1 // SPDX-License-Identifier: GPL-2.0+
3 * Simple network protocol
4 * PXE base code protocol
6 * Copyright (c) 2016 Alexander Graf
8 * The simple network protocol has the following statuses and services
9 * to move between them:
11 * Start(): EfiSimpleNetworkStopped -> EfiSimpleNetworkStarted
12 * Initialize(): EfiSimpleNetworkStarted -> EfiSimpleNetworkInitialized
13 * Shutdown(): EfiSimpleNetworkInitialized -> EfiSimpleNetworkStarted
14 * Stop(): EfiSimpleNetworkStarted -> EfiSimpleNetworkStopped
15 * Reset(): EfiSimpleNetworkInitialized -> EfiSimpleNetworkInitialized
19 #include <efi_loader.h>
23 static const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
24 static const efi_guid_t efi_pxe_base_code_protocol_guid =
25 EFI_PXE_BASE_CODE_PROTOCOL_GUID;
26 static struct efi_pxe_packet *dhcp_ack;
27 static bool new_rx_packet;
28 static void *new_tx_packet;
29 static void *transmit_buffer;
32 * The notification function of this event is called in every timer cycle
33 * to check if a new network packet has been received.
35 static struct efi_event *network_timer_event;
37 * This event is signaled when a packet has been received.
39 static struct efi_event *wait_for_packet;
42 * struct efi_net_obj - EFI object representing a network interface
44 * @header: EFI object header
45 * @net: simple network protocol interface
46 * @net_mode: status of the network interface
47 * @pxe: PXE base code protocol interface
48 * @pxe_mode: status of the PXE base code protocol
51 struct efi_object header;
52 struct efi_simple_network net;
53 struct efi_simple_network_mode net_mode;
54 struct efi_pxe_base_code_protocol pxe;
55 struct efi_pxe_mode pxe_mode;
59 * efi_net_start() - start the network interface
61 * This function implements the Start service of the
62 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
63 * (UEFI) specification for details.
65 * @this: pointer to the protocol instance
68 static efi_status_t EFIAPI efi_net_start(struct efi_simple_network *this)
70 efi_status_t ret = EFI_SUCCESS;
72 EFI_ENTRY("%p", this);
74 /* Check parameters */
76 ret = EFI_INVALID_PARAMETER;
80 if (this->mode->state != EFI_NETWORK_STOPPED) {
81 ret = EFI_ALREADY_STARTED;
84 wait_for_packet->is_signaled = false;
85 this->mode->state = EFI_NETWORK_STARTED;
92 * efi_net_stop() - stop the network interface
94 * This function implements the Stop service of the
95 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
96 * (UEFI) specification for details.
98 * @this: pointer to the protocol instance
101 static efi_status_t EFIAPI efi_net_stop(struct efi_simple_network *this)
103 efi_status_t ret = EFI_SUCCESS;
105 EFI_ENTRY("%p", this);
107 /* Check parameters */
109 ret = EFI_INVALID_PARAMETER;
113 if (this->mode->state == EFI_NETWORK_STOPPED) {
114 ret = EFI_NOT_STARTED;
116 /* Disable hardware and put it into the reset state */
118 this->mode->state = EFI_NETWORK_STOPPED;
121 return EFI_EXIT(ret);
125 * efi_net_initialize() - initialize the network interface
127 * This function implements the Initialize service of the
128 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
129 * (UEFI) specification for details.
131 * @this: pointer to the protocol instance
132 * @extra_rx: extra receive buffer to be allocated
133 * @extra_tx: extra transmit buffer to be allocated
134 * Return: status code
136 static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this,
137 ulong extra_rx, ulong extra_tx)
140 efi_status_t r = EFI_SUCCESS;
142 EFI_ENTRY("%p, %lx, %lx", this, extra_rx, extra_tx);
144 /* Check parameters */
146 r = EFI_INVALID_PARAMETER;
150 switch (this->mode->state) {
151 case EFI_NETWORK_INITIALIZED:
152 case EFI_NETWORK_STARTED:
159 /* Setup packet buffers */
161 /* Disable hardware and put it into the reset state */
163 /* Set current device according to environment variables */
165 /* Get hardware ready for send and receive operations */
169 this->mode->state = EFI_NETWORK_STOPPED;
170 r = EFI_DEVICE_ERROR;
173 this->int_status = 0;
174 wait_for_packet->is_signaled = false;
175 this->mode->state = EFI_NETWORK_INITIALIZED;
182 * efi_net_reset() - reinitialize the network interface
184 * This function implements the Reset service of the
185 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
186 * (UEFI) specification for details.
188 * @this: pointer to the protocol instance
189 * @extended_verification: execute exhaustive verification
190 * Return: status code
192 static efi_status_t EFIAPI efi_net_reset(struct efi_simple_network *this,
193 int extended_verification)
197 EFI_ENTRY("%p, %x", this, extended_verification);
199 /* Check parameters */
201 ret = EFI_INVALID_PARAMETER;
205 switch (this->mode->state) {
206 case EFI_NETWORK_INITIALIZED:
208 case EFI_NETWORK_STOPPED:
209 ret = EFI_NOT_STARTED;
212 ret = EFI_DEVICE_ERROR;
216 this->mode->state = EFI_NETWORK_STARTED;
217 ret = EFI_CALL(efi_net_initialize(this, 0, 0));
219 return EFI_EXIT(ret);
223 * efi_net_shutdown() - shut down the network interface
225 * This function implements the Shutdown service of the
226 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
227 * (UEFI) specification for details.
229 * @this: pointer to the protocol instance
230 * Return: status code
232 static efi_status_t EFIAPI efi_net_shutdown(struct efi_simple_network *this)
234 efi_status_t ret = EFI_SUCCESS;
236 EFI_ENTRY("%p", this);
238 /* Check parameters */
240 ret = EFI_INVALID_PARAMETER;
244 switch (this->mode->state) {
245 case EFI_NETWORK_INITIALIZED:
247 case EFI_NETWORK_STOPPED:
248 ret = EFI_NOT_STARTED;
251 ret = EFI_DEVICE_ERROR;
256 this->int_status = 0;
257 wait_for_packet->is_signaled = false;
258 this->mode->state = EFI_NETWORK_STARTED;
261 return EFI_EXIT(ret);
265 * efi_net_receive_filters() - mange multicast receive filters
267 * This function implements the ReceiveFilters service of the
268 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
269 * (UEFI) specification for details.
271 * @this: pointer to the protocol instance
272 * @enable: bit mask of receive filters to enable
273 * @disable: bit mask of receive filters to disable
274 * @reset_mcast_filter: true resets contents of the filters
275 * @mcast_filter_count: number of hardware MAC addresses in the new filters list
276 * @mcast_filter: list of new filters
277 * Return: status code
279 static efi_status_t EFIAPI efi_net_receive_filters
280 (struct efi_simple_network *this, u32 enable, u32 disable,
281 int reset_mcast_filter, ulong mcast_filter_count,
282 struct efi_mac_address *mcast_filter)
284 EFI_ENTRY("%p, %x, %x, %x, %lx, %p", this, enable, disable,
285 reset_mcast_filter, mcast_filter_count, mcast_filter);
287 return EFI_EXIT(EFI_UNSUPPORTED);
291 * efi_net_station_address() - set the hardware MAC address
293 * This function implements the StationAddress service of the
294 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
295 * (UEFI) specification for details.
297 * @this: pointer to the protocol instance
298 * @reset: if true reset the address to default
299 * @new_mac: new MAC address
300 * Return: status code
302 static efi_status_t EFIAPI efi_net_station_address
303 (struct efi_simple_network *this, int reset,
304 struct efi_mac_address *new_mac)
306 EFI_ENTRY("%p, %x, %p", this, reset, new_mac);
308 return EFI_EXIT(EFI_UNSUPPORTED);
312 * efi_net_statistics() - reset or collect statistics of the network interface
314 * This function implements the Statistics service of the
315 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
316 * (UEFI) specification for details.
318 * @this: pointer to the protocol instance
319 * @reset: if true, the statistics are reset
320 * @stat_size: size of the statistics table
321 * @stat_table: table to receive the statistics
322 * Return: status code
324 static efi_status_t EFIAPI efi_net_statistics(struct efi_simple_network *this,
325 int reset, ulong *stat_size,
328 EFI_ENTRY("%p, %x, %p, %p", this, reset, stat_size, stat_table);
330 return EFI_EXIT(EFI_UNSUPPORTED);
334 * efi_net_mcastiptomac() - translate multicast IP address to MAC address
336 * This function implements the MCastIPtoMAC service of the
337 * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface
338 * (UEFI) specification for details.
340 * @this: pointer to the protocol instance
341 * @ipv6: true if the IP address is an IPv6 address
344 * Return: status code
346 static efi_status_t EFIAPI efi_net_mcastiptomac(struct efi_simple_network *this,
348 struct efi_ip_address *ip,
349 struct efi_mac_address *mac)
351 efi_status_t ret = EFI_SUCCESS;
353 EFI_ENTRY("%p, %x, %p, %p", this, ipv6, ip, mac);
355 if (!this || !ip || !mac) {
356 ret = EFI_INVALID_PARAMETER;
361 ret = EFI_UNSUPPORTED;
365 /* Multi-cast addresses are in the range 224.0.0.0 - 239.255.255.255 */
366 if ((ip->ip_addr[0] & 0xf0) != 0xe0) {
367 ret = EFI_INVALID_PARAMETER;
371 switch (this->mode->state) {
372 case EFI_NETWORK_INITIALIZED:
373 case EFI_NETWORK_STARTED:
376 ret = EFI_NOT_STARTED;
380 memset(mac, 0, sizeof(struct efi_mac_address));
383 * Copy lower 23 bits of IPv4 multi-cast address
384 * RFC 1112, RFC 7042 2.1.1.
386 mac->mac_addr[0] = 0x01;
387 mac->mac_addr[1] = 0x00;
388 mac->mac_addr[2] = 0x5E;
389 mac->mac_addr[3] = ip->ip_addr[1] & 0x7F;
390 mac->mac_addr[4] = ip->ip_addr[2];
391 mac->mac_addr[5] = ip->ip_addr[3];
393 return EFI_EXIT(ret);
397 * efi_net_nvdata() - read or write NVRAM
399 * This function implements the GetStatus service of the Simple Network
400 * Protocol. See the UEFI spec for details.
402 * @this: the instance of the Simple Network Protocol
403 * @read_write: true for read, false for write
404 * @offset: offset in NVRAM
405 * @buffer_size: size of buffer
407 * Return: status code
409 static efi_status_t EFIAPI efi_net_nvdata(struct efi_simple_network *this,
410 int read_write, ulong offset,
411 ulong buffer_size, char *buffer)
413 EFI_ENTRY("%p, %x, %lx, %lx, %p", this, read_write, offset, buffer_size,
416 return EFI_EXIT(EFI_UNSUPPORTED);
420 * efi_net_get_status() - get interrupt status
422 * This function implements the GetStatus service of the Simple Network
423 * Protocol. See the UEFI spec for details.
425 * @this: the instance of the Simple Network Protocol
426 * @int_status: interface status
427 * @txbuf: transmission buffer
429 static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this,
430 u32 *int_status, void **txbuf)
432 efi_status_t ret = EFI_SUCCESS;
434 EFI_ENTRY("%p, %p, %p", this, int_status, txbuf);
438 /* Check parameters */
440 ret = EFI_INVALID_PARAMETER;
444 switch (this->mode->state) {
445 case EFI_NETWORK_STOPPED:
446 ret = EFI_NOT_STARTED;
448 case EFI_NETWORK_STARTED:
449 ret = EFI_DEVICE_ERROR;
456 *int_status = this->int_status;
457 this->int_status = 0;
460 *txbuf = new_tx_packet;
462 new_tx_packet = NULL;
464 return EFI_EXIT(ret);
468 * efi_net_transmit() - transmit a packet
470 * This function implements the Transmit service of the Simple Network Protocol.
471 * See the UEFI spec for details.
473 * @this: the instance of the Simple Network Protocol
474 * @header_size: size of the media header
475 * @buffer_size: size of the buffer to receive the packet
476 * @buffer: buffer to receive the packet
477 * @src_addr: source hardware MAC address
478 * @dest_addr: destination hardware MAC address
479 * @protocol: type of header to build
480 * Return: status code
482 static efi_status_t EFIAPI efi_net_transmit
483 (struct efi_simple_network *this, size_t header_size,
484 size_t buffer_size, void *buffer,
485 struct efi_mac_address *src_addr,
486 struct efi_mac_address *dest_addr, u16 *protocol)
488 efi_status_t ret = EFI_SUCCESS;
490 EFI_ENTRY("%p, %lu, %lu, %p, %p, %p, %p", this,
491 (unsigned long)header_size, (unsigned long)buffer_size,
492 buffer, src_addr, dest_addr, protocol);
496 /* Check parameters */
497 if (!this || !buffer) {
498 ret = EFI_INVALID_PARAMETER;
502 /* We do not support jumbo packets */
503 if (buffer_size > PKTSIZE_ALIGN) {
504 ret = EFI_INVALID_PARAMETER;
508 /* At least the IP header has to fit into the buffer */
509 if (buffer_size < this->mode->media_header_size) {
510 ret = EFI_BUFFER_TOO_SMALL;
516 * Support VLANs. Use net_set_ether() for copying the header. Use a
517 * U_BOOT_ENV_CALLBACK to update the media header size.
520 struct ethernet_hdr *header = buffer;
522 if (!dest_addr || !protocol ||
523 header_size != this->mode->media_header_size) {
524 ret = EFI_INVALID_PARAMETER;
528 src_addr = &this->mode->current_address;
530 memcpy(header->et_dest, dest_addr, ARP_HLEN);
531 memcpy(header->et_src, src_addr, ARP_HLEN);
532 header->et_protlen = htons(*protocol);
535 switch (this->mode->state) {
536 case EFI_NETWORK_STOPPED:
537 ret = EFI_NOT_STARTED;
539 case EFI_NETWORK_STARTED:
540 ret = EFI_DEVICE_ERROR;
546 /* Ethernet packets always fit, just bounce */
547 memcpy(transmit_buffer, buffer, buffer_size);
548 net_send_packet(transmit_buffer, buffer_size);
550 new_tx_packet = buffer;
551 this->int_status |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
553 return EFI_EXIT(ret);
557 * efi_net_receive() - receive a packet from a network interface
559 * This function implements the Receive service of the Simple Network Protocol.
560 * See the UEFI spec for details.
562 * @this: the instance of the Simple Network Protocol
563 * @header_size: size of the media header
564 * @buffer_size: size of the buffer to receive the packet
565 * @buffer: buffer to receive the packet
566 * @src_addr: source MAC address
567 * @dest_addr: destination MAC address
568 * @protocol: protocol
569 * Return: status code
571 static efi_status_t EFIAPI efi_net_receive
572 (struct efi_simple_network *this, size_t *header_size,
573 size_t *buffer_size, void *buffer,
574 struct efi_mac_address *src_addr,
575 struct efi_mac_address *dest_addr, u16 *protocol)
577 efi_status_t ret = EFI_SUCCESS;
578 struct ethernet_hdr *eth_hdr;
579 size_t hdr_size = sizeof(struct ethernet_hdr);
582 EFI_ENTRY("%p, %p, %p, %p, %p, %p, %p", this, header_size,
583 buffer_size, buffer, src_addr, dest_addr, protocol);
588 /* Check parameters */
589 if (!this || !buffer || !buffer_size) {
590 ret = EFI_INVALID_PARAMETER;
594 switch (this->mode->state) {
595 case EFI_NETWORK_STOPPED:
596 ret = EFI_NOT_STARTED;
598 case EFI_NETWORK_STARTED:
599 ret = EFI_DEVICE_ERROR;
605 if (!new_rx_packet) {
609 /* Fill export parameters */
610 eth_hdr = (struct ethernet_hdr *)net_rx_packet;
611 protlen = ntohs(eth_hdr->et_protlen);
612 if (protlen == 0x8100) {
614 protlen = ntohs(*(u16 *)&net_rx_packet[hdr_size - 2]);
617 *header_size = hdr_size;
619 memcpy(dest_addr, eth_hdr->et_dest, ARP_HLEN);
621 memcpy(src_addr, eth_hdr->et_src, ARP_HLEN);
624 if (*buffer_size < net_rx_packet_len) {
625 /* Packet doesn't fit, try again with bigger buffer */
626 *buffer_size = net_rx_packet_len;
627 ret = EFI_BUFFER_TOO_SMALL;
631 memcpy(buffer, net_rx_packet, net_rx_packet_len);
632 *buffer_size = net_rx_packet_len;
634 this->int_status &= ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
636 return EFI_EXIT(ret);
640 * efi_net_set_dhcp_ack() - take note of a selected DHCP IP address
642 * This function is called by dhcp_handler().
644 * @pkt: packet received by dhcp_handler()
645 * @len: length of the packet received
647 void efi_net_set_dhcp_ack(void *pkt, int len)
649 int maxsize = sizeof(*dhcp_ack);
652 dhcp_ack = malloc(maxsize);
654 memcpy(dhcp_ack, pkt, min(len, maxsize));
658 * efi_net_push() - callback for received network packet
660 * This function is called when a network packet is received by eth_rx().
662 * @pkt: network packet
665 static void efi_net_push(void *pkt, int len)
667 new_rx_packet = true;
671 * efi_network_timer_notify() - check if a new network packet has been received
673 * This notification function is called in every timer cycle.
675 * @event: the event for which this notification function is registered
676 * @context: event context - not used in this function
678 static void EFIAPI efi_network_timer_notify(struct efi_event *event,
681 struct efi_simple_network *this = (struct efi_simple_network *)context;
683 EFI_ENTRY("%p, %p", event, context);
686 * Some network drivers do not support calling eth_rx() before
689 if (!this || this->mode->state != EFI_NETWORK_INITIALIZED)
692 if (!new_rx_packet) {
693 push_packet = efi_net_push;
697 /* Check that we at least received an Ethernet header */
698 if (net_rx_packet_len >=
699 sizeof(struct ethernet_hdr)) {
701 EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
702 wait_for_packet->is_signaled = true;
709 EFI_EXIT(EFI_SUCCESS);
712 static efi_status_t EFIAPI efi_pxe_base_code_start(
713 struct efi_pxe_base_code_protocol *this,
716 return EFI_UNSUPPORTED;
719 static efi_status_t EFIAPI efi_pxe_base_code_stop(
720 struct efi_pxe_base_code_protocol *this)
722 return EFI_UNSUPPORTED;
725 static efi_status_t EFIAPI efi_pxe_base_code_dhcp(
726 struct efi_pxe_base_code_protocol *this,
729 return EFI_UNSUPPORTED;
732 static efi_status_t EFIAPI efi_pxe_base_code_discover(
733 struct efi_pxe_base_code_protocol *this,
734 u16 type, u16 *layer, u8 bis,
735 struct efi_pxe_base_code_discover_info *info)
737 return EFI_UNSUPPORTED;
740 static efi_status_t EFIAPI efi_pxe_base_code_mtftp(
741 struct efi_pxe_base_code_protocol *this,
742 u32 operation, void *buffer_ptr,
743 u8 overwrite, efi_uintn_t *buffer_size,
744 struct efi_ip_address server_ip, char *filename,
745 struct efi_pxe_base_code_mtftp_info *info,
748 return EFI_UNSUPPORTED;
751 static efi_status_t EFIAPI efi_pxe_base_code_udp_write(
752 struct efi_pxe_base_code_protocol *this,
753 u16 op_flags, struct efi_ip_address *dest_ip,
755 struct efi_ip_address *gateway_ip,
756 struct efi_ip_address *src_ip, u16 *src_port,
757 efi_uintn_t *header_size, void *header_ptr,
758 efi_uintn_t *buffer_size, void *buffer_ptr)
760 return EFI_UNSUPPORTED;
763 static efi_status_t EFIAPI efi_pxe_base_code_udp_read(
764 struct efi_pxe_base_code_protocol *this,
765 u16 op_flags, struct efi_ip_address *dest_ip,
766 u16 *dest_port, struct efi_ip_address *src_ip,
767 u16 *src_port, efi_uintn_t *header_size,
768 void *header_ptr, efi_uintn_t *buffer_size,
771 return EFI_UNSUPPORTED;
774 static efi_status_t EFIAPI efi_pxe_base_code_set_ip_filter(
775 struct efi_pxe_base_code_protocol *this,
776 struct efi_pxe_base_code_filter *new_filter)
778 return EFI_UNSUPPORTED;
781 static efi_status_t EFIAPI efi_pxe_base_code_arp(
782 struct efi_pxe_base_code_protocol *this,
783 struct efi_ip_address *ip_addr,
784 struct efi_mac_address *mac_addr)
786 return EFI_UNSUPPORTED;
789 static efi_status_t EFIAPI efi_pxe_base_code_set_parameters(
790 struct efi_pxe_base_code_protocol *this,
791 u8 *new_auto_arp, u8 *new_send_guid,
792 u8 *new_ttl, u8 *new_tos,
793 u8 *new_make_callback)
795 return EFI_UNSUPPORTED;
798 static efi_status_t EFIAPI efi_pxe_base_code_set_station_ip(
799 struct efi_pxe_base_code_protocol *this,
800 struct efi_ip_address *new_station_ip,
801 struct efi_ip_address *new_subnet_mask)
803 return EFI_UNSUPPORTED;
806 static efi_status_t EFIAPI efi_pxe_base_code_set_packets(
807 struct efi_pxe_base_code_protocol *this,
808 u8 *new_dhcp_discover_valid,
809 u8 *new_dhcp_ack_received,
810 u8 *new_proxy_offer_received,
811 u8 *new_pxe_discover_valid,
812 u8 *new_pxe_reply_received,
813 u8 *new_pxe_bis_reply_received,
814 EFI_PXE_BASE_CODE_PACKET *new_dchp_discover,
815 EFI_PXE_BASE_CODE_PACKET *new_dhcp_acc,
816 EFI_PXE_BASE_CODE_PACKET *new_proxy_offer,
817 EFI_PXE_BASE_CODE_PACKET *new_pxe_discover,
818 EFI_PXE_BASE_CODE_PACKET *new_pxe_reply,
819 EFI_PXE_BASE_CODE_PACKET *new_pxe_bis_reply)
821 return EFI_UNSUPPORTED;
825 * efi_net_register() - register the simple network protocol
827 * This gets called from do_bootefi_exec().
829 efi_status_t efi_net_register(void)
831 struct efi_net_obj *netobj = NULL;
834 if (!eth_get_dev()) {
835 /* No network device active, don't expose any */
839 /* We only expose the "active" network device, so one is enough */
840 netobj = calloc(1, sizeof(*netobj));
842 goto out_of_resources;
844 /* Allocate an aligned transmit buffer */
845 transmit_buffer = calloc(1, PKTSIZE_ALIGN + PKTALIGN);
846 if (!transmit_buffer)
847 goto out_of_resources;
848 transmit_buffer = (void *)ALIGN((uintptr_t)transmit_buffer, PKTALIGN);
850 /* Hook net up to the device list */
851 efi_add_handle(&netobj->header);
853 /* Fill in object data */
854 r = efi_add_protocol(&netobj->header, &efi_net_guid,
856 if (r != EFI_SUCCESS)
857 goto failure_to_add_protocol;
858 r = efi_add_protocol(&netobj->header, &efi_guid_device_path,
860 if (r != EFI_SUCCESS)
861 goto failure_to_add_protocol;
862 r = efi_add_protocol(&netobj->header, &efi_pxe_base_code_protocol_guid,
864 if (r != EFI_SUCCESS)
865 goto failure_to_add_protocol;
866 netobj->net.revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;
867 netobj->net.start = efi_net_start;
868 netobj->net.stop = efi_net_stop;
869 netobj->net.initialize = efi_net_initialize;
870 netobj->net.reset = efi_net_reset;
871 netobj->net.shutdown = efi_net_shutdown;
872 netobj->net.receive_filters = efi_net_receive_filters;
873 netobj->net.station_address = efi_net_station_address;
874 netobj->net.statistics = efi_net_statistics;
875 netobj->net.mcastiptomac = efi_net_mcastiptomac;
876 netobj->net.nvdata = efi_net_nvdata;
877 netobj->net.get_status = efi_net_get_status;
878 netobj->net.transmit = efi_net_transmit;
879 netobj->net.receive = efi_net_receive;
880 netobj->net.mode = &netobj->net_mode;
881 netobj->net_mode.state = EFI_NETWORK_STOPPED;
882 memcpy(netobj->net_mode.current_address.mac_addr, eth_get_ethaddr(), 6);
883 netobj->net_mode.hwaddr_size = ARP_HLEN;
884 netobj->net_mode.media_header_size = ETHER_HDR_SIZE;
885 netobj->net_mode.max_packet_size = PKTSIZE;
886 netobj->net_mode.if_type = ARP_ETHER;
888 netobj->pxe.revision = EFI_PXE_BASE_CODE_PROTOCOL_REVISION;
889 netobj->pxe.start = efi_pxe_base_code_start;
890 netobj->pxe.stop = efi_pxe_base_code_stop;
891 netobj->pxe.dhcp = efi_pxe_base_code_dhcp;
892 netobj->pxe.discover = efi_pxe_base_code_discover;
893 netobj->pxe.mtftp = efi_pxe_base_code_mtftp;
894 netobj->pxe.udp_write = efi_pxe_base_code_udp_write;
895 netobj->pxe.udp_read = efi_pxe_base_code_udp_read;
896 netobj->pxe.set_ip_filter = efi_pxe_base_code_set_ip_filter;
897 netobj->pxe.arp = efi_pxe_base_code_arp;
898 netobj->pxe.set_parameters = efi_pxe_base_code_set_parameters;
899 netobj->pxe.set_station_ip = efi_pxe_base_code_set_station_ip;
900 netobj->pxe.set_packets = efi_pxe_base_code_set_packets;
901 netobj->pxe.mode = &netobj->pxe_mode;
903 netobj->pxe_mode.dhcp_ack = *dhcp_ack;
906 * Create WaitForPacket event.
908 r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK,
909 efi_network_timer_notify, NULL, NULL,
911 if (r != EFI_SUCCESS) {
912 printf("ERROR: Failed to register network event\n");
915 netobj->net.wait_for_packet = wait_for_packet;
917 * Create a timer event.
919 * The notification function is used to check if a new network packet
922 * iPXE is running at TPL_CALLBACK most of the time. Use a higher TPL.
924 r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
925 efi_network_timer_notify, &netobj->net, NULL,
926 &network_timer_event);
927 if (r != EFI_SUCCESS) {
928 printf("ERROR: Failed to register network event\n");
931 /* Network is time critical, create event in every timer cycle */
932 r = efi_set_timer(network_timer_event, EFI_TIMER_PERIODIC, 0);
933 if (r != EFI_SUCCESS) {
934 printf("ERROR: Failed to set network timer\n");
939 failure_to_add_protocol:
940 printf("ERROR: Failure to add protocol\n");
944 /* free(transmit_buffer) not needed yet */
945 printf("ERROR: Out of memory\n");
946 return EFI_OUT_OF_RESOURCES;