Tom Rini | f739fcd | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 2 | /* |
| 3 | * EFI application network access support |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <efi_loader.h> |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 10 | #include <malloc.h> |
| 11 | |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 12 | static const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_GUID; |
| 13 | static const efi_guid_t efi_pxe_guid = EFI_PXE_GUID; |
| 14 | static struct efi_pxe_packet *dhcp_ack; |
| 15 | static bool new_rx_packet; |
| 16 | static void *new_tx_packet; |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 17 | /* |
| 18 | * The notification function of this event is called in every timer cycle |
| 19 | * to check if a new network packet has been received. |
| 20 | */ |
| 21 | static struct efi_event *network_timer_event; |
Heinrich Schuchardt | e5c2160 | 2017-10-05 16:36:01 +0200 | [diff] [blame] | 22 | /* |
| 23 | * This event is signaled when a packet has been received. |
| 24 | */ |
| 25 | static struct efi_event *wait_for_packet; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 26 | |
| 27 | struct efi_net_obj { |
| 28 | /* Generic EFI object parent class data */ |
| 29 | struct efi_object parent; |
| 30 | /* EFI Interface callback struct for network */ |
| 31 | struct efi_simple_network net; |
| 32 | struct efi_simple_network_mode net_mode; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 33 | /* PXE struct to transmit dhcp data */ |
| 34 | struct efi_pxe pxe; |
| 35 | struct efi_pxe_mode pxe_mode; |
| 36 | }; |
| 37 | |
| 38 | static efi_status_t EFIAPI efi_net_start(struct efi_simple_network *this) |
| 39 | { |
| 40 | EFI_ENTRY("%p", this); |
| 41 | |
| 42 | return EFI_EXIT(EFI_SUCCESS); |
| 43 | } |
| 44 | |
| 45 | static efi_status_t EFIAPI efi_net_stop(struct efi_simple_network *this) |
| 46 | { |
| 47 | EFI_ENTRY("%p", this); |
| 48 | |
| 49 | return EFI_EXIT(EFI_SUCCESS); |
| 50 | } |
| 51 | |
Heinrich Schuchardt | 0c5d2a3 | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 52 | /* |
| 53 | * Initialize network adapter and allocate transmit and receive buffers. |
| 54 | * |
| 55 | * This function implements the Initialize service of the |
| 56 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 57 | * (UEFI) specification for details. |
| 58 | * |
| 59 | * @this: pointer to the protocol instance |
| 60 | * @extra_rx: extra receive buffer to be allocated |
| 61 | * @extra_tx: extra transmit buffer to be allocated |
| 62 | * @return: status code |
| 63 | */ |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 64 | static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this, |
| 65 | ulong extra_rx, ulong extra_tx) |
| 66 | { |
Heinrich Schuchardt | 0c5d2a3 | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 67 | int ret; |
| 68 | efi_status_t r = EFI_SUCCESS; |
| 69 | |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 70 | EFI_ENTRY("%p, %lx, %lx", this, extra_rx, extra_tx); |
| 71 | |
Heinrich Schuchardt | 0c5d2a3 | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 72 | if (!this) { |
| 73 | r = EFI_INVALID_PARAMETER; |
| 74 | goto error; |
| 75 | } |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 76 | |
Heinrich Schuchardt | 0c5d2a3 | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 77 | /* Setup packet buffers */ |
| 78 | net_init(); |
| 79 | /* Disable hardware and put it into the reset state */ |
| 80 | eth_halt(); |
| 81 | /* Set current device according to environment variables */ |
| 82 | eth_set_current(); |
| 83 | /* Get hardware ready for send and receive operations */ |
| 84 | ret = eth_init(); |
| 85 | if (ret < 0) { |
| 86 | eth_halt(); |
| 87 | r = EFI_DEVICE_ERROR; |
| 88 | } |
| 89 | |
| 90 | error: |
| 91 | return EFI_EXIT(r); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static efi_status_t EFIAPI efi_net_reset(struct efi_simple_network *this, |
| 95 | int extended_verification) |
| 96 | { |
| 97 | EFI_ENTRY("%p, %x", this, extended_verification); |
| 98 | |
| 99 | return EFI_EXIT(EFI_SUCCESS); |
| 100 | } |
| 101 | |
| 102 | static efi_status_t EFIAPI efi_net_shutdown(struct efi_simple_network *this) |
| 103 | { |
| 104 | EFI_ENTRY("%p", this); |
| 105 | |
| 106 | return EFI_EXIT(EFI_SUCCESS); |
| 107 | } |
| 108 | |
| 109 | static efi_status_t EFIAPI efi_net_receive_filters( |
| 110 | struct efi_simple_network *this, u32 enable, u32 disable, |
| 111 | int reset_mcast_filter, ulong mcast_filter_count, |
| 112 | struct efi_mac_address *mcast_filter) |
| 113 | { |
| 114 | EFI_ENTRY("%p, %x, %x, %x, %lx, %p", this, enable, disable, |
| 115 | reset_mcast_filter, mcast_filter_count, mcast_filter); |
| 116 | |
Heinrich Schuchardt | 61da678 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 117 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static efi_status_t EFIAPI efi_net_station_address( |
| 121 | struct efi_simple_network *this, int reset, |
| 122 | struct efi_mac_address *new_mac) |
| 123 | { |
| 124 | EFI_ENTRY("%p, %x, %p", this, reset, new_mac); |
| 125 | |
Heinrich Schuchardt | 61da678 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 126 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static efi_status_t EFIAPI efi_net_statistics(struct efi_simple_network *this, |
| 130 | int reset, ulong *stat_size, |
| 131 | void *stat_table) |
| 132 | { |
| 133 | EFI_ENTRY("%p, %x, %p, %p", this, reset, stat_size, stat_table); |
| 134 | |
Heinrich Schuchardt | 61da678 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 135 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static efi_status_t EFIAPI efi_net_mcastiptomac(struct efi_simple_network *this, |
| 139 | int ipv6, |
| 140 | struct efi_ip_address *ip, |
| 141 | struct efi_mac_address *mac) |
| 142 | { |
| 143 | EFI_ENTRY("%p, %x, %p, %p", this, ipv6, ip, mac); |
| 144 | |
| 145 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 146 | } |
| 147 | |
| 148 | static efi_status_t EFIAPI efi_net_nvdata(struct efi_simple_network *this, |
| 149 | int read_write, ulong offset, |
| 150 | ulong buffer_size, char *buffer) |
| 151 | { |
| 152 | EFI_ENTRY("%p, %x, %lx, %lx, %p", this, read_write, offset, buffer_size, |
| 153 | buffer); |
| 154 | |
Heinrich Schuchardt | 61da678 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 155 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this, |
| 159 | u32 *int_status, void **txbuf) |
| 160 | { |
| 161 | EFI_ENTRY("%p, %p, %p", this, int_status, txbuf); |
| 162 | |
Heinrich Schuchardt | 891b3d9 | 2017-10-05 16:36:02 +0200 | [diff] [blame] | 163 | efi_timer_check(); |
| 164 | |
| 165 | if (int_status) { |
| 166 | /* We send packets synchronously, so nothing is outstanding */ |
| 167 | *int_status = EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; |
| 168 | if (new_rx_packet) |
| 169 | *int_status |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; |
| 170 | } |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 171 | if (txbuf) |
| 172 | *txbuf = new_tx_packet; |
| 173 | |
| 174 | new_tx_packet = NULL; |
| 175 | |
| 176 | return EFI_EXIT(EFI_SUCCESS); |
| 177 | } |
| 178 | |
| 179 | static efi_status_t EFIAPI efi_net_transmit(struct efi_simple_network *this, |
Heinrich Schuchardt | 8db174d | 2017-10-05 16:36:03 +0200 | [diff] [blame] | 180 | size_t header_size, size_t buffer_size, void *buffer, |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 181 | struct efi_mac_address *src_addr, |
| 182 | struct efi_mac_address *dest_addr, u16 *protocol) |
| 183 | { |
Heinrich Schuchardt | 8db174d | 2017-10-05 16:36:03 +0200 | [diff] [blame] | 184 | EFI_ENTRY("%p, %lu, %lu, %p, %p, %p, %p", this, |
| 185 | (unsigned long)header_size, (unsigned long)buffer_size, |
| 186 | buffer, src_addr, dest_addr, protocol); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 187 | |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 188 | efi_timer_check(); |
| 189 | |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 190 | if (header_size) { |
| 191 | /* We would need to create the header if header_size != 0 */ |
| 192 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 193 | } |
| 194 | |
Alexander Graf | 712cd29 | 2016-09-06 14:26:27 +0200 | [diff] [blame] | 195 | #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER |
| 196 | /* Ethernet packets always fit, just bounce */ |
| 197 | memcpy(efi_bounce_buffer, buffer, buffer_size); |
| 198 | net_send_packet(efi_bounce_buffer, buffer_size); |
| 199 | #else |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 200 | net_send_packet(buffer, buffer_size); |
Alexander Graf | 712cd29 | 2016-09-06 14:26:27 +0200 | [diff] [blame] | 201 | #endif |
| 202 | |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 203 | new_tx_packet = buffer; |
| 204 | |
| 205 | return EFI_EXIT(EFI_SUCCESS); |
| 206 | } |
| 207 | |
| 208 | static void efi_net_push(void *pkt, int len) |
| 209 | { |
| 210 | new_rx_packet = true; |
Heinrich Schuchardt | e5c2160 | 2017-10-05 16:36:01 +0200 | [diff] [blame] | 211 | wait_for_packet->is_signaled = true; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Heinrich Schuchardt | 8db174d | 2017-10-05 16:36:03 +0200 | [diff] [blame] | 214 | /* |
| 215 | * Receive a packet from a network interface. |
| 216 | * |
| 217 | * This function implements the Receive service of the Simple Network Protocol. |
| 218 | * See the UEFI spec for details. |
| 219 | * |
| 220 | * @this the instance of the Simple Network Protocol |
| 221 | * @header_size size of the media header |
| 222 | * @buffer_size size of the buffer to receive the packet |
| 223 | * @buffer buffer to receive the packet |
| 224 | * @src_addr source MAC address |
| 225 | * @dest_addr destination MAC address |
| 226 | * @protocol protocol |
| 227 | * @return status code |
| 228 | */ |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 229 | static efi_status_t EFIAPI efi_net_receive(struct efi_simple_network *this, |
Heinrich Schuchardt | 8db174d | 2017-10-05 16:36:03 +0200 | [diff] [blame] | 230 | size_t *header_size, size_t *buffer_size, void *buffer, |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 231 | struct efi_mac_address *src_addr, |
| 232 | struct efi_mac_address *dest_addr, u16 *protocol) |
| 233 | { |
Heinrich Schuchardt | 336d9df | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 234 | struct ethernet_hdr *eth_hdr; |
| 235 | size_t hdr_size = sizeof(struct ethernet_hdr); |
| 236 | u16 protlen; |
| 237 | |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 238 | EFI_ENTRY("%p, %p, %p, %p, %p, %p, %p", this, header_size, |
| 239 | buffer_size, buffer, src_addr, dest_addr, protocol); |
| 240 | |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 241 | efi_timer_check(); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 242 | |
| 243 | if (!new_rx_packet) |
| 244 | return EFI_EXIT(EFI_NOT_READY); |
Heinrich Schuchardt | 336d9df | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 245 | /* Check that we at least received an Ethernet header */ |
| 246 | if (net_rx_packet_len < sizeof(struct ethernet_hdr)) { |
| 247 | new_rx_packet = false; |
| 248 | return EFI_EXIT(EFI_NOT_READY); |
| 249 | } |
| 250 | /* Fill export parameters */ |
| 251 | eth_hdr = (struct ethernet_hdr *)net_rx_packet; |
| 252 | protlen = ntohs(eth_hdr->et_protlen); |
| 253 | if (protlen == 0x8100) { |
| 254 | hdr_size += 4; |
| 255 | protlen = ntohs(*(u16 *)&net_rx_packet[hdr_size - 2]); |
| 256 | } |
| 257 | if (header_size) |
| 258 | *header_size = hdr_size; |
| 259 | if (dest_addr) |
| 260 | memcpy(dest_addr, eth_hdr->et_dest, ARP_HLEN); |
| 261 | if (src_addr) |
| 262 | memcpy(src_addr, eth_hdr->et_src, ARP_HLEN); |
| 263 | if (protocol) |
| 264 | *protocol = protlen; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 265 | if (*buffer_size < net_rx_packet_len) { |
| 266 | /* Packet doesn't fit, try again with bigger buf */ |
| 267 | *buffer_size = net_rx_packet_len; |
| 268 | return EFI_EXIT(EFI_BUFFER_TOO_SMALL); |
| 269 | } |
Heinrich Schuchardt | 336d9df | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 270 | /* Copy packet */ |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 271 | memcpy(buffer, net_rx_packet, net_rx_packet_len); |
| 272 | *buffer_size = net_rx_packet_len; |
| 273 | new_rx_packet = false; |
| 274 | |
| 275 | return EFI_EXIT(EFI_SUCCESS); |
| 276 | } |
| 277 | |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 278 | void efi_net_set_dhcp_ack(void *pkt, int len) |
| 279 | { |
| 280 | int maxsize = sizeof(*dhcp_ack); |
| 281 | |
| 282 | if (!dhcp_ack) |
| 283 | dhcp_ack = malloc(maxsize); |
| 284 | |
| 285 | memcpy(dhcp_ack, pkt, min(len, maxsize)); |
| 286 | } |
| 287 | |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 288 | /* |
| 289 | * Check if a new network packet has been received. |
| 290 | * |
| 291 | * This notification function is called in every timer cycle. |
| 292 | * |
| 293 | * @event the event for which this notification function is registered |
| 294 | * @context event context - not used in this function |
| 295 | */ |
| 296 | static void EFIAPI efi_network_timer_notify(struct efi_event *event, |
| 297 | void *context) |
| 298 | { |
| 299 | EFI_ENTRY("%p, %p", event, context); |
| 300 | |
| 301 | if (!new_rx_packet) { |
| 302 | push_packet = efi_net_push; |
| 303 | eth_rx(); |
| 304 | push_packet = NULL; |
| 305 | } |
| 306 | EFI_EXIT(EFI_SUCCESS); |
| 307 | } |
| 308 | |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 309 | /* This gets called from do_bootefi_exec(). */ |
Heinrich Schuchardt | 075d425 | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 310 | efi_status_t efi_net_register(void) |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 311 | { |
| 312 | struct efi_net_obj *netobj; |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 313 | efi_status_t r; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 314 | |
| 315 | if (!eth_get_dev()) { |
| 316 | /* No eth device active, don't expose any */ |
Heinrich Schuchardt | 075d425 | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 317 | return EFI_SUCCESS; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /* We only expose the "active" eth device, so one is enough */ |
| 321 | netobj = calloc(1, sizeof(*netobj)); |
Heinrich Schuchardt | 075d425 | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 322 | if (!netobj) { |
| 323 | printf("ERROR: Out of memory\n"); |
| 324 | return EFI_OUT_OF_RESOURCES; |
| 325 | } |
Heinrich Schuchardt | 84d1456 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 326 | |
| 327 | /* Hook net up to the device list */ |
Heinrich Schuchardt | 44549d6 | 2017-11-26 14:05:23 +0100 | [diff] [blame] | 328 | efi_add_handle(&netobj->parent); |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 329 | |
| 330 | /* Fill in object data */ |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame^] | 331 | r = efi_add_protocol(&netobj->parent, &efi_net_guid, |
Heinrich Schuchardt | 84d1456 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 332 | &netobj->net); |
| 333 | if (r != EFI_SUCCESS) |
Heinrich Schuchardt | 075d425 | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 334 | goto failure_to_add_protocol; |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame^] | 335 | r = efi_add_protocol(&netobj->parent, &efi_guid_device_path, |
Heinrich Schuchardt | 84d1456 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 336 | efi_dp_from_eth()); |
| 337 | if (r != EFI_SUCCESS) |
Heinrich Schuchardt | 075d425 | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 338 | goto failure_to_add_protocol; |
Heinrich Schuchardt | fae0118 | 2018-09-26 05:27:55 +0200 | [diff] [blame^] | 339 | r = efi_add_protocol(&netobj->parent, &efi_pxe_guid, |
Heinrich Schuchardt | 84d1456 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 340 | &netobj->pxe); |
| 341 | if (r != EFI_SUCCESS) |
Heinrich Schuchardt | 075d425 | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 342 | goto failure_to_add_protocol; |
Heinrich Schuchardt | bdecf97 | 2017-10-05 16:35:57 +0200 | [diff] [blame] | 343 | netobj->net.revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 344 | netobj->net.start = efi_net_start; |
| 345 | netobj->net.stop = efi_net_stop; |
| 346 | netobj->net.initialize = efi_net_initialize; |
| 347 | netobj->net.reset = efi_net_reset; |
| 348 | netobj->net.shutdown = efi_net_shutdown; |
| 349 | netobj->net.receive_filters = efi_net_receive_filters; |
| 350 | netobj->net.station_address = efi_net_station_address; |
| 351 | netobj->net.statistics = efi_net_statistics; |
| 352 | netobj->net.mcastiptomac = efi_net_mcastiptomac; |
| 353 | netobj->net.nvdata = efi_net_nvdata; |
| 354 | netobj->net.get_status = efi_net_get_status; |
| 355 | netobj->net.transmit = efi_net_transmit; |
| 356 | netobj->net.receive = efi_net_receive; |
| 357 | netobj->net.mode = &netobj->net_mode; |
| 358 | netobj->net_mode.state = EFI_NETWORK_STARTED; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 359 | memcpy(netobj->net_mode.current_address.mac_addr, eth_get_ethaddr(), 6); |
Heinrich Schuchardt | 5d4a5ea | 2017-10-05 16:35:58 +0200 | [diff] [blame] | 360 | netobj->net_mode.hwaddr_size = ARP_HLEN; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 361 | netobj->net_mode.max_packet_size = PKTSIZE; |
Andrew Thomas | f25ddca | 2018-06-21 16:21:01 -0700 | [diff] [blame] | 362 | netobj->net_mode.if_type = ARP_ETHER; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 363 | |
| 364 | netobj->pxe.mode = &netobj->pxe_mode; |
| 365 | if (dhcp_ack) |
| 366 | netobj->pxe_mode.dhcp_ack = *dhcp_ack; |
| 367 | |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 368 | /* |
Heinrich Schuchardt | e5c2160 | 2017-10-05 16:36:01 +0200 | [diff] [blame] | 369 | * Create WaitForPacket event. |
| 370 | */ |
| 371 | r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK, |
Heinrich Schuchardt | b095f3c | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 372 | efi_network_timer_notify, NULL, NULL, |
Heinrich Schuchardt | e5c2160 | 2017-10-05 16:36:01 +0200 | [diff] [blame] | 373 | &wait_for_packet); |
| 374 | if (r != EFI_SUCCESS) { |
| 375 | printf("ERROR: Failed to register network event\n"); |
| 376 | return r; |
| 377 | } |
| 378 | netobj->net.wait_for_packet = wait_for_packet; |
| 379 | /* |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 380 | * Create a timer event. |
| 381 | * |
| 382 | * The notification function is used to check if a new network packet |
| 383 | * has been received. |
Heinrich Schuchardt | ee3db4f | 2018-03-24 18:40:22 +0100 | [diff] [blame] | 384 | * |
| 385 | * iPXE is running at TPL_CALLBACK most of the time. Use a higher TPL. |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 386 | */ |
Heinrich Schuchardt | ee3db4f | 2018-03-24 18:40:22 +0100 | [diff] [blame] | 387 | r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY, |
Heinrich Schuchardt | b095f3c | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 388 | efi_network_timer_notify, NULL, NULL, |
Heinrich Schuchardt | a0549ef | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 389 | &network_timer_event); |
| 390 | if (r != EFI_SUCCESS) { |
| 391 | printf("ERROR: Failed to register network event\n"); |
| 392 | return r; |
| 393 | } |
| 394 | /* Network is time critical, create event in every timer cyle */ |
| 395 | r = efi_set_timer(network_timer_event, EFI_TIMER_PERIODIC, 0); |
| 396 | if (r != EFI_SUCCESS) { |
| 397 | printf("ERROR: Failed to set network timer\n"); |
| 398 | return r; |
| 399 | } |
| 400 | |
Heinrich Schuchardt | 075d425 | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 401 | return EFI_SUCCESS; |
| 402 | failure_to_add_protocol: |
| 403 | printf("ERROR: Failure to add protocol\n"); |
| 404 | return r; |
Alexander Graf | 0efe1bc | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 405 | } |