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