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 | /* |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 3 | * Simple network protocol |
| 4 | * PXE base code protocol |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 5 | * |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 6 | * Copyright (c) 2016 Alexander Graf |
| 7 | * |
| 8 | * The simple network protocol has the following statuses and services |
| 9 | * to move between them: |
| 10 | * |
| 11 | * Start(): EfiSimpleNetworkStopped -> EfiSimpleNetworkStarted |
| 12 | * Initialize(): EfiSimpleNetworkStarted -> EfiSimpleNetworkInitialized |
| 13 | * Shutdown(): EfiSimpleNetworkInitialized -> EfiSimpleNetworkStarted |
| 14 | * Stop(): EfiSimpleNetworkStarted -> EfiSimpleNetworkStopped |
| 15 | * Reset(): EfiSimpleNetworkInitialized -> EfiSimpleNetworkInitialized |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 16 | */ |
| 17 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 18 | #include <efi_loader.h> |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 19 | #include <malloc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <net.h> |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 21 | |
Heinrich Schuchardt | 788ad41 | 2019-04-20 07:39:11 +0200 | [diff] [blame] | 22 | static const efi_guid_t efi_net_guid = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; |
Heinrich Schuchardt | 3127e7e | 2019-08-06 08:13:33 +0200 | [diff] [blame] | 23 | static const efi_guid_t efi_pxe_base_code_protocol_guid = |
| 24 | EFI_PXE_BASE_CODE_PROTOCOL_GUID; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 25 | static struct efi_pxe_packet *dhcp_ack; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 26 | static void *new_tx_packet; |
Heinrich Schuchardt | eb07c28 | 2018-12-01 00:16:32 +0100 | [diff] [blame] | 27 | static void *transmit_buffer; |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 28 | static uchar **receive_buffer; |
| 29 | static size_t *receive_lengths; |
| 30 | static int rx_packet_idx; |
| 31 | static int rx_packet_num; |
Heinrich Schuchardt | 2f1a93f | 2022-11-26 16:44:38 +0100 | [diff] [blame] | 32 | static struct efi_net_obj *netobj; |
Heinrich Schuchardt | eb07c28 | 2018-12-01 00:16:32 +0100 | [diff] [blame] | 33 | |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 34 | /* |
| 35 | * The notification function of this event is called in every timer cycle |
| 36 | * to check if a new network packet has been received. |
| 37 | */ |
| 38 | static struct efi_event *network_timer_event; |
Heinrich Schuchardt | 0c153c2 | 2017-10-05 16:36:01 +0200 | [diff] [blame] | 39 | /* |
| 40 | * This event is signaled when a packet has been received. |
| 41 | */ |
| 42 | static struct efi_event *wait_for_packet; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 43 | |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 44 | /** |
| 45 | * struct efi_net_obj - EFI object representing a network interface |
| 46 | * |
| 47 | * @header: EFI object header |
| 48 | * @net: simple network protocol interface |
| 49 | * @net_mode: status of the network interface |
| 50 | * @pxe: PXE base code protocol interface |
| 51 | * @pxe_mode: status of the PXE base code protocol |
| 52 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 53 | struct efi_net_obj { |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 54 | struct efi_object header; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 55 | struct efi_simple_network net; |
| 56 | struct efi_simple_network_mode net_mode; |
Heinrich Schuchardt | 3127e7e | 2019-08-06 08:13:33 +0200 | [diff] [blame] | 57 | struct efi_pxe_base_code_protocol pxe; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 58 | struct efi_pxe_mode pxe_mode; |
| 59 | }; |
| 60 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 61 | /* |
| 62 | * efi_net_start() - start the network interface |
| 63 | * |
| 64 | * This function implements the Start service of the |
| 65 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 66 | * (UEFI) specification for details. |
| 67 | * |
| 68 | * @this: pointer to the protocol instance |
| 69 | * Return: status code |
| 70 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 71 | static efi_status_t EFIAPI efi_net_start(struct efi_simple_network *this) |
| 72 | { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 73 | efi_status_t ret = EFI_SUCCESS; |
| 74 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 75 | EFI_ENTRY("%p", this); |
| 76 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 77 | /* Check parameters */ |
| 78 | if (!this) { |
| 79 | ret = EFI_INVALID_PARAMETER; |
| 80 | goto out; |
| 81 | } |
| 82 | |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 83 | if (this->mode->state != EFI_NETWORK_STOPPED) { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 84 | ret = EFI_ALREADY_STARTED; |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 85 | } else { |
| 86 | this->int_status = 0; |
| 87 | wait_for_packet->is_signaled = false; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 88 | this->mode->state = EFI_NETWORK_STARTED; |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 89 | } |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 90 | out: |
| 91 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 94 | /* |
| 95 | * efi_net_stop() - stop the network interface |
| 96 | * |
| 97 | * This function implements the Stop service of the |
| 98 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 99 | * (UEFI) specification for details. |
| 100 | * |
| 101 | * @this: pointer to the protocol instance |
| 102 | * Return: status code |
| 103 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 104 | static efi_status_t EFIAPI efi_net_stop(struct efi_simple_network *this) |
| 105 | { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 106 | efi_status_t ret = EFI_SUCCESS; |
| 107 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 108 | EFI_ENTRY("%p", this); |
| 109 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 110 | /* Check parameters */ |
| 111 | if (!this) { |
| 112 | ret = EFI_INVALID_PARAMETER; |
| 113 | goto out; |
| 114 | } |
| 115 | |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 116 | if (this->mode->state == EFI_NETWORK_STOPPED) { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 117 | ret = EFI_NOT_STARTED; |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 118 | } else { |
| 119 | /* Disable hardware and put it into the reset state */ |
| 120 | eth_halt(); |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 121 | /* Clear cache of packets */ |
| 122 | rx_packet_num = 0; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 123 | this->mode->state = EFI_NETWORK_STOPPED; |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 124 | } |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 125 | out: |
| 126 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 129 | /* |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 130 | * efi_net_initialize() - initialize the network interface |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 131 | * |
| 132 | * This function implements the Initialize service of the |
| 133 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 134 | * (UEFI) specification for details. |
| 135 | * |
| 136 | * @this: pointer to the protocol instance |
| 137 | * @extra_rx: extra receive buffer to be allocated |
| 138 | * @extra_tx: extra transmit buffer to be allocated |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 139 | * Return: status code |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 140 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 141 | static efi_status_t EFIAPI efi_net_initialize(struct efi_simple_network *this, |
| 142 | ulong extra_rx, ulong extra_tx) |
| 143 | { |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 144 | int ret; |
| 145 | efi_status_t r = EFI_SUCCESS; |
| 146 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 147 | EFI_ENTRY("%p, %lx, %lx", this, extra_rx, extra_tx); |
| 148 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 149 | /* Check parameters */ |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 150 | if (!this) { |
| 151 | r = EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 152 | goto out; |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 155 | switch (this->mode->state) { |
| 156 | case EFI_NETWORK_INITIALIZED: |
| 157 | case EFI_NETWORK_STARTED: |
| 158 | break; |
| 159 | default: |
| 160 | r = EFI_NOT_STARTED; |
| 161 | goto out; |
| 162 | } |
| 163 | |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 164 | /* Setup packet buffers */ |
| 165 | net_init(); |
| 166 | /* Disable hardware and put it into the reset state */ |
| 167 | eth_halt(); |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 168 | /* Clear cache of packets */ |
| 169 | rx_packet_num = 0; |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 170 | /* Set current device according to environment variables */ |
| 171 | eth_set_current(); |
| 172 | /* Get hardware ready for send and receive operations */ |
| 173 | ret = eth_init(); |
| 174 | if (ret < 0) { |
| 175 | eth_halt(); |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 176 | this->mode->state = EFI_NETWORK_STOPPED; |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 177 | r = EFI_DEVICE_ERROR; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 178 | goto out; |
| 179 | } else { |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 180 | this->int_status = 0; |
| 181 | wait_for_packet->is_signaled = false; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 182 | this->mode->state = EFI_NETWORK_INITIALIZED; |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 183 | } |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 184 | out: |
Heinrich Schuchardt | ad4d67c | 2018-04-03 22:06:52 +0200 | [diff] [blame] | 185 | return EFI_EXIT(r); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 188 | /* |
| 189 | * efi_net_reset() - reinitialize the network interface |
| 190 | * |
| 191 | * This function implements the Reset service of the |
| 192 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 193 | * (UEFI) specification for details. |
| 194 | * |
| 195 | * @this: pointer to the protocol instance |
| 196 | * @extended_verification: execute exhaustive verification |
| 197 | * Return: status code |
| 198 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 199 | static efi_status_t EFIAPI efi_net_reset(struct efi_simple_network *this, |
| 200 | int extended_verification) |
| 201 | { |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 202 | efi_status_t ret; |
| 203 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 204 | EFI_ENTRY("%p, %x", this, extended_verification); |
| 205 | |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 206 | /* Check parameters */ |
| 207 | if (!this) { |
| 208 | ret = EFI_INVALID_PARAMETER; |
| 209 | goto out; |
| 210 | } |
| 211 | |
| 212 | switch (this->mode->state) { |
| 213 | case EFI_NETWORK_INITIALIZED: |
| 214 | break; |
| 215 | case EFI_NETWORK_STOPPED: |
| 216 | ret = EFI_NOT_STARTED; |
| 217 | goto out; |
| 218 | default: |
| 219 | ret = EFI_DEVICE_ERROR; |
| 220 | goto out; |
| 221 | } |
| 222 | |
| 223 | this->mode->state = EFI_NETWORK_STARTED; |
| 224 | ret = EFI_CALL(efi_net_initialize(this, 0, 0)); |
| 225 | out: |
| 226 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 229 | /* |
| 230 | * efi_net_shutdown() - shut down the network interface |
| 231 | * |
| 232 | * This function implements the Shutdown service of the |
| 233 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 234 | * (UEFI) specification for details. |
| 235 | * |
| 236 | * @this: pointer to the protocol instance |
| 237 | * Return: status code |
| 238 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 239 | static efi_status_t EFIAPI efi_net_shutdown(struct efi_simple_network *this) |
| 240 | { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 241 | efi_status_t ret = EFI_SUCCESS; |
| 242 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 243 | EFI_ENTRY("%p", this); |
| 244 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 245 | /* Check parameters */ |
| 246 | if (!this) { |
| 247 | ret = EFI_INVALID_PARAMETER; |
| 248 | goto out; |
| 249 | } |
| 250 | |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 251 | switch (this->mode->state) { |
| 252 | case EFI_NETWORK_INITIALIZED: |
| 253 | break; |
| 254 | case EFI_NETWORK_STOPPED: |
| 255 | ret = EFI_NOT_STARTED; |
| 256 | goto out; |
| 257 | default: |
| 258 | ret = EFI_DEVICE_ERROR; |
| 259 | goto out; |
| 260 | } |
| 261 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 262 | eth_halt(); |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 263 | this->int_status = 0; |
| 264 | wait_for_packet->is_signaled = false; |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 265 | this->mode->state = EFI_NETWORK_STARTED; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 266 | |
| 267 | out: |
| 268 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 271 | /* |
| 272 | * efi_net_receive_filters() - mange multicast receive filters |
| 273 | * |
| 274 | * This function implements the ReceiveFilters service of the |
| 275 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 276 | * (UEFI) specification for details. |
| 277 | * |
| 278 | * @this: pointer to the protocol instance |
| 279 | * @enable: bit mask of receive filters to enable |
| 280 | * @disable: bit mask of receive filters to disable |
| 281 | * @reset_mcast_filter: true resets contents of the filters |
| 282 | * @mcast_filter_count: number of hardware MAC addresses in the new filters list |
| 283 | * @mcast_filter: list of new filters |
| 284 | * Return: status code |
| 285 | */ |
| 286 | static efi_status_t EFIAPI efi_net_receive_filters |
| 287 | (struct efi_simple_network *this, u32 enable, u32 disable, |
| 288 | int reset_mcast_filter, ulong mcast_filter_count, |
| 289 | struct efi_mac_address *mcast_filter) |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 290 | { |
| 291 | EFI_ENTRY("%p, %x, %x, %x, %lx, %p", this, enable, disable, |
| 292 | reset_mcast_filter, mcast_filter_count, mcast_filter); |
| 293 | |
Heinrich Schuchardt | a50b5c6 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 294 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 297 | /* |
| 298 | * efi_net_station_address() - set the hardware MAC address |
| 299 | * |
| 300 | * This function implements the StationAddress service of the |
| 301 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 302 | * (UEFI) specification for details. |
| 303 | * |
| 304 | * @this: pointer to the protocol instance |
| 305 | * @reset: if true reset the address to default |
| 306 | * @new_mac: new MAC address |
| 307 | * Return: status code |
| 308 | */ |
| 309 | static efi_status_t EFIAPI efi_net_station_address |
| 310 | (struct efi_simple_network *this, int reset, |
| 311 | struct efi_mac_address *new_mac) |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 312 | { |
| 313 | EFI_ENTRY("%p, %x, %p", this, reset, new_mac); |
| 314 | |
Heinrich Schuchardt | a50b5c6 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 315 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 316 | } |
| 317 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 318 | /* |
| 319 | * efi_net_statistics() - reset or collect statistics of the network interface |
| 320 | * |
| 321 | * This function implements the Statistics service of the |
| 322 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 323 | * (UEFI) specification for details. |
| 324 | * |
| 325 | * @this: pointer to the protocol instance |
| 326 | * @reset: if true, the statistics are reset |
| 327 | * @stat_size: size of the statistics table |
| 328 | * @stat_table: table to receive the statistics |
| 329 | * Return: status code |
| 330 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 331 | static efi_status_t EFIAPI efi_net_statistics(struct efi_simple_network *this, |
| 332 | int reset, ulong *stat_size, |
| 333 | void *stat_table) |
| 334 | { |
| 335 | EFI_ENTRY("%p, %x, %p, %p", this, reset, stat_size, stat_table); |
| 336 | |
Heinrich Schuchardt | a50b5c6 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 337 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 340 | /* |
| 341 | * efi_net_mcastiptomac() - translate multicast IP address to MAC address |
| 342 | * |
Heinrich Schuchardt | 33b318d | 2019-09-01 17:17:53 +0200 | [diff] [blame] | 343 | * This function implements the MCastIPtoMAC service of the |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 344 | * EFI_SIMPLE_NETWORK_PROTOCOL. See the Unified Extensible Firmware Interface |
| 345 | * (UEFI) specification for details. |
| 346 | * |
| 347 | * @this: pointer to the protocol instance |
| 348 | * @ipv6: true if the IP address is an IPv6 address |
| 349 | * @ip: IP address |
| 350 | * @mac: MAC address |
| 351 | * Return: status code |
| 352 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 353 | static efi_status_t EFIAPI efi_net_mcastiptomac(struct efi_simple_network *this, |
| 354 | int ipv6, |
| 355 | struct efi_ip_address *ip, |
| 356 | struct efi_mac_address *mac) |
| 357 | { |
Heinrich Schuchardt | 33b318d | 2019-09-01 17:17:53 +0200 | [diff] [blame] | 358 | efi_status_t ret = EFI_SUCCESS; |
| 359 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 360 | EFI_ENTRY("%p, %x, %p, %p", this, ipv6, ip, mac); |
| 361 | |
Heinrich Schuchardt | 33b318d | 2019-09-01 17:17:53 +0200 | [diff] [blame] | 362 | if (!this || !ip || !mac) { |
| 363 | ret = EFI_INVALID_PARAMETER; |
| 364 | goto out; |
| 365 | } |
| 366 | |
| 367 | if (ipv6) { |
| 368 | ret = EFI_UNSUPPORTED; |
| 369 | goto out; |
| 370 | } |
| 371 | |
| 372 | /* Multi-cast addresses are in the range 224.0.0.0 - 239.255.255.255 */ |
| 373 | if ((ip->ip_addr[0] & 0xf0) != 0xe0) { |
| 374 | ret = EFI_INVALID_PARAMETER; |
| 375 | goto out; |
| 376 | }; |
| 377 | |
| 378 | switch (this->mode->state) { |
| 379 | case EFI_NETWORK_INITIALIZED: |
| 380 | case EFI_NETWORK_STARTED: |
| 381 | break; |
| 382 | default: |
| 383 | ret = EFI_NOT_STARTED; |
| 384 | goto out; |
| 385 | } |
| 386 | |
| 387 | memset(mac, 0, sizeof(struct efi_mac_address)); |
| 388 | |
| 389 | /* |
| 390 | * Copy lower 23 bits of IPv4 multi-cast address |
| 391 | * RFC 1112, RFC 7042 2.1.1. |
| 392 | */ |
| 393 | mac->mac_addr[0] = 0x01; |
| 394 | mac->mac_addr[1] = 0x00; |
| 395 | mac->mac_addr[2] = 0x5E; |
| 396 | mac->mac_addr[3] = ip->ip_addr[1] & 0x7F; |
| 397 | mac->mac_addr[4] = ip->ip_addr[2]; |
| 398 | mac->mac_addr[5] = ip->ip_addr[3]; |
| 399 | out: |
| 400 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 403 | /** |
| 404 | * efi_net_nvdata() - read or write NVRAM |
| 405 | * |
| 406 | * This function implements the GetStatus service of the Simple Network |
| 407 | * Protocol. See the UEFI spec for details. |
| 408 | * |
| 409 | * @this: the instance of the Simple Network Protocol |
Heinrich Schuchardt | dc305ad | 2019-09-05 20:37:13 +0200 | [diff] [blame] | 410 | * @read_write: true for read, false for write |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 411 | * @offset: offset in NVRAM |
| 412 | * @buffer_size: size of buffer |
| 413 | * @buffer: buffer |
| 414 | * Return: status code |
| 415 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 416 | static efi_status_t EFIAPI efi_net_nvdata(struct efi_simple_network *this, |
| 417 | int read_write, ulong offset, |
| 418 | ulong buffer_size, char *buffer) |
| 419 | { |
| 420 | EFI_ENTRY("%p, %x, %lx, %lx, %p", this, read_write, offset, buffer_size, |
| 421 | buffer); |
| 422 | |
Heinrich Schuchardt | a50b5c6 | 2017-10-05 16:35:59 +0200 | [diff] [blame] | 423 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 424 | } |
| 425 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 426 | /** |
| 427 | * efi_net_get_status() - get interrupt status |
| 428 | * |
| 429 | * This function implements the GetStatus service of the Simple Network |
| 430 | * Protocol. See the UEFI spec for details. |
| 431 | * |
| 432 | * @this: the instance of the Simple Network Protocol |
| 433 | * @int_status: interface status |
| 434 | * @txbuf: transmission buffer |
| 435 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 436 | static efi_status_t EFIAPI efi_net_get_status(struct efi_simple_network *this, |
| 437 | u32 *int_status, void **txbuf) |
| 438 | { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 439 | efi_status_t ret = EFI_SUCCESS; |
| 440 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 441 | EFI_ENTRY("%p, %p, %p", this, int_status, txbuf); |
| 442 | |
Heinrich Schuchardt | e371c5f | 2017-10-05 16:36:02 +0200 | [diff] [blame] | 443 | efi_timer_check(); |
| 444 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 445 | /* Check parameters */ |
| 446 | if (!this) { |
| 447 | ret = EFI_INVALID_PARAMETER; |
| 448 | goto out; |
| 449 | } |
| 450 | |
| 451 | switch (this->mode->state) { |
| 452 | case EFI_NETWORK_STOPPED: |
| 453 | ret = EFI_NOT_STARTED; |
| 454 | goto out; |
| 455 | case EFI_NETWORK_STARTED: |
| 456 | ret = EFI_DEVICE_ERROR; |
| 457 | goto out; |
| 458 | default: |
| 459 | break; |
| 460 | } |
| 461 | |
Heinrich Schuchardt | e371c5f | 2017-10-05 16:36:02 +0200 | [diff] [blame] | 462 | if (int_status) { |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 463 | *int_status = this->int_status; |
| 464 | this->int_status = 0; |
Heinrich Schuchardt | e371c5f | 2017-10-05 16:36:02 +0200 | [diff] [blame] | 465 | } |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 466 | if (txbuf) |
| 467 | *txbuf = new_tx_packet; |
| 468 | |
| 469 | new_tx_packet = NULL; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 470 | out: |
| 471 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 472 | } |
| 473 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 474 | /** |
| 475 | * efi_net_transmit() - transmit a packet |
| 476 | * |
| 477 | * This function implements the Transmit service of the Simple Network Protocol. |
| 478 | * See the UEFI spec for details. |
| 479 | * |
| 480 | * @this: the instance of the Simple Network Protocol |
| 481 | * @header_size: size of the media header |
| 482 | * @buffer_size: size of the buffer to receive the packet |
| 483 | * @buffer: buffer to receive the packet |
| 484 | * @src_addr: source hardware MAC address |
| 485 | * @dest_addr: destination hardware MAC address |
| 486 | * @protocol: type of header to build |
| 487 | * Return: status code |
| 488 | */ |
| 489 | static efi_status_t EFIAPI efi_net_transmit |
| 490 | (struct efi_simple_network *this, size_t header_size, |
| 491 | size_t buffer_size, void *buffer, |
| 492 | struct efi_mac_address *src_addr, |
| 493 | struct efi_mac_address *dest_addr, u16 *protocol) |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 494 | { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 495 | efi_status_t ret = EFI_SUCCESS; |
| 496 | |
Heinrich Schuchardt | f66b2e3 | 2017-10-05 16:36:03 +0200 | [diff] [blame] | 497 | EFI_ENTRY("%p, %lu, %lu, %p, %p, %p, %p", this, |
| 498 | (unsigned long)header_size, (unsigned long)buffer_size, |
| 499 | buffer, src_addr, dest_addr, protocol); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 500 | |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 501 | efi_timer_check(); |
| 502 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 503 | /* Check parameters */ |
Heinrich Schuchardt | f286c2c | 2019-05-15 23:27:43 +0200 | [diff] [blame] | 504 | if (!this || !buffer) { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 505 | ret = EFI_INVALID_PARAMETER; |
| 506 | goto out; |
| 507 | } |
| 508 | |
| 509 | /* We do not support jumbo packets */ |
| 510 | if (buffer_size > PKTSIZE_ALIGN) { |
| 511 | ret = EFI_INVALID_PARAMETER; |
| 512 | goto out; |
| 513 | } |
| 514 | |
Heinrich Schuchardt | 0218a8f | 2019-08-31 10:55:29 +0200 | [diff] [blame] | 515 | /* At least the IP header has to fit into the buffer */ |
| 516 | if (buffer_size < this->mode->media_header_size) { |
| 517 | ret = EFI_BUFFER_TOO_SMALL; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 518 | goto out; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Heinrich Schuchardt | 0218a8f | 2019-08-31 10:55:29 +0200 | [diff] [blame] | 521 | /* |
| 522 | * TODO: |
| 523 | * Support VLANs. Use net_set_ether() for copying the header. Use a |
| 524 | * U_BOOT_ENV_CALLBACK to update the media header size. |
| 525 | */ |
| 526 | if (header_size) { |
| 527 | struct ethernet_hdr *header = buffer; |
| 528 | |
| 529 | if (!dest_addr || !protocol || |
| 530 | header_size != this->mode->media_header_size) { |
| 531 | ret = EFI_INVALID_PARAMETER; |
| 532 | goto out; |
| 533 | } |
| 534 | if (!src_addr) |
| 535 | src_addr = &this->mode->current_address; |
| 536 | |
| 537 | memcpy(header->et_dest, dest_addr, ARP_HLEN); |
| 538 | memcpy(header->et_src, src_addr, ARP_HLEN); |
| 539 | header->et_protlen = htons(*protocol); |
| 540 | } |
| 541 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 542 | switch (this->mode->state) { |
| 543 | case EFI_NETWORK_STOPPED: |
| 544 | ret = EFI_NOT_STARTED; |
| 545 | goto out; |
| 546 | case EFI_NETWORK_STARTED: |
| 547 | ret = EFI_DEVICE_ERROR; |
| 548 | goto out; |
| 549 | default: |
| 550 | break; |
| 551 | } |
| 552 | |
| 553 | /* Ethernet packets always fit, just bounce */ |
Heinrich Schuchardt | eb07c28 | 2018-12-01 00:16:32 +0100 | [diff] [blame] | 554 | memcpy(transmit_buffer, buffer, buffer_size); |
| 555 | net_send_packet(transmit_buffer, buffer_size); |
Alexander Graf | 0b12b86 | 2016-09-06 14:26:27 +0200 | [diff] [blame] | 556 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 557 | new_tx_packet = buffer; |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 558 | this->int_status |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 559 | out: |
| 560 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 563 | /** |
| 564 | * efi_net_receive() - receive a packet from a network interface |
Heinrich Schuchardt | f66b2e3 | 2017-10-05 16:36:03 +0200 | [diff] [blame] | 565 | * |
| 566 | * This function implements the Receive service of the Simple Network Protocol. |
| 567 | * See the UEFI spec for details. |
| 568 | * |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 569 | * @this: the instance of the Simple Network Protocol |
| 570 | * @header_size: size of the media header |
| 571 | * @buffer_size: size of the buffer to receive the packet |
| 572 | * @buffer: buffer to receive the packet |
| 573 | * @src_addr: source MAC address |
| 574 | * @dest_addr: destination MAC address |
| 575 | * @protocol: protocol |
| 576 | * Return: status code |
Heinrich Schuchardt | f66b2e3 | 2017-10-05 16:36:03 +0200 | [diff] [blame] | 577 | */ |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 578 | static efi_status_t EFIAPI efi_net_receive |
| 579 | (struct efi_simple_network *this, size_t *header_size, |
| 580 | size_t *buffer_size, void *buffer, |
| 581 | struct efi_mac_address *src_addr, |
| 582 | struct efi_mac_address *dest_addr, u16 *protocol) |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 583 | { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 584 | efi_status_t ret = EFI_SUCCESS; |
Heinrich Schuchardt | aa0d197 | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 585 | struct ethernet_hdr *eth_hdr; |
| 586 | size_t hdr_size = sizeof(struct ethernet_hdr); |
| 587 | u16 protlen; |
| 588 | |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 589 | EFI_ENTRY("%p, %p, %p, %p, %p, %p, %p", this, header_size, |
| 590 | buffer_size, buffer, src_addr, dest_addr, protocol); |
| 591 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 592 | /* Execute events */ |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 593 | efi_timer_check(); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 594 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 595 | /* Check parameters */ |
Heinrich Schuchardt | f286c2c | 2019-05-15 23:27:43 +0200 | [diff] [blame] | 596 | if (!this || !buffer || !buffer_size) { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 597 | ret = EFI_INVALID_PARAMETER; |
| 598 | goto out; |
| 599 | } |
| 600 | |
| 601 | switch (this->mode->state) { |
| 602 | case EFI_NETWORK_STOPPED: |
| 603 | ret = EFI_NOT_STARTED; |
| 604 | goto out; |
| 605 | case EFI_NETWORK_STARTED: |
| 606 | ret = EFI_DEVICE_ERROR; |
| 607 | goto out; |
| 608 | default: |
| 609 | break; |
| 610 | } |
| 611 | |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 612 | if (!rx_packet_num) { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 613 | ret = EFI_NOT_READY; |
| 614 | goto out; |
| 615 | } |
Heinrich Schuchardt | aa0d197 | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 616 | /* Fill export parameters */ |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 617 | eth_hdr = (struct ethernet_hdr *)receive_buffer[rx_packet_idx]; |
Heinrich Schuchardt | aa0d197 | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 618 | protlen = ntohs(eth_hdr->et_protlen); |
| 619 | if (protlen == 0x8100) { |
| 620 | hdr_size += 4; |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 621 | protlen = ntohs(*(u16 *)&receive_buffer[rx_packet_idx][hdr_size - 2]); |
Heinrich Schuchardt | aa0d197 | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 622 | } |
| 623 | if (header_size) |
| 624 | *header_size = hdr_size; |
| 625 | if (dest_addr) |
| 626 | memcpy(dest_addr, eth_hdr->et_dest, ARP_HLEN); |
| 627 | if (src_addr) |
| 628 | memcpy(src_addr, eth_hdr->et_src, ARP_HLEN); |
| 629 | if (protocol) |
| 630 | *protocol = protlen; |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 631 | if (*buffer_size < receive_lengths[rx_packet_idx]) { |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 632 | /* Packet doesn't fit, try again with bigger buffer */ |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 633 | *buffer_size = receive_lengths[rx_packet_idx]; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 634 | ret = EFI_BUFFER_TOO_SMALL; |
| 635 | goto out; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 636 | } |
Heinrich Schuchardt | aa0d197 | 2017-10-05 16:36:04 +0200 | [diff] [blame] | 637 | /* Copy packet */ |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 638 | memcpy(buffer, receive_buffer[rx_packet_idx], |
| 639 | receive_lengths[rx_packet_idx]); |
| 640 | *buffer_size = receive_lengths[rx_packet_idx]; |
| 641 | rx_packet_idx = (rx_packet_idx + 1) % ETH_PACKETS_BATCH_RECV; |
| 642 | rx_packet_num--; |
| 643 | if (rx_packet_num) |
| 644 | wait_for_packet->is_signaled = true; |
| 645 | else |
| 646 | this->int_status &= ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 647 | out: |
| 648 | return EFI_EXIT(ret); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 649 | } |
| 650 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 651 | /** |
| 652 | * efi_net_set_dhcp_ack() - take note of a selected DHCP IP address |
| 653 | * |
| 654 | * This function is called by dhcp_handler(). |
Heinrich Schuchardt | dc305ad | 2019-09-05 20:37:13 +0200 | [diff] [blame] | 655 | * |
| 656 | * @pkt: packet received by dhcp_handler() |
| 657 | * @len: length of the packet received |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 658 | */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 659 | void efi_net_set_dhcp_ack(void *pkt, int len) |
| 660 | { |
| 661 | int maxsize = sizeof(*dhcp_ack); |
| 662 | |
Heinrich Schuchardt | 2f1a93f | 2022-11-26 16:44:38 +0100 | [diff] [blame] | 663 | if (!dhcp_ack) { |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 664 | dhcp_ack = malloc(maxsize); |
Heinrich Schuchardt | 2f1a93f | 2022-11-26 16:44:38 +0100 | [diff] [blame] | 665 | if (!dhcp_ack) |
| 666 | return; |
| 667 | } |
| 668 | memset(dhcp_ack, 0, maxsize); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 669 | memcpy(dhcp_ack, pkt, min(len, maxsize)); |
Heinrich Schuchardt | 2f1a93f | 2022-11-26 16:44:38 +0100 | [diff] [blame] | 670 | |
| 671 | if (netobj) |
| 672 | netobj->pxe_mode.dhcp_ack = *dhcp_ack; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 673 | } |
| 674 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 675 | /** |
| 676 | * efi_net_push() - callback for received network packet |
| 677 | * |
| 678 | * This function is called when a network packet is received by eth_rx(). |
| 679 | * |
| 680 | * @pkt: network packet |
| 681 | * @len: length |
| 682 | */ |
| 683 | static void efi_net_push(void *pkt, int len) |
| 684 | { |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 685 | int rx_packet_next; |
| 686 | |
| 687 | /* Check that we at least received an Ethernet header */ |
| 688 | if (len < sizeof(struct ethernet_hdr)) |
| 689 | return; |
| 690 | |
| 691 | /* Check that the buffer won't overflow */ |
| 692 | if (len > PKTSIZE_ALIGN) |
| 693 | return; |
| 694 | |
| 695 | /* Can't store more than pre-alloced buffer */ |
| 696 | if (rx_packet_num >= ETH_PACKETS_BATCH_RECV) |
| 697 | return; |
| 698 | |
| 699 | rx_packet_next = (rx_packet_idx + rx_packet_num) % |
| 700 | ETH_PACKETS_BATCH_RECV; |
| 701 | memcpy(receive_buffer[rx_packet_next], pkt, len); |
| 702 | receive_lengths[rx_packet_next] = len; |
| 703 | |
| 704 | rx_packet_num++; |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | /** |
| 708 | * efi_network_timer_notify() - check if a new network packet has been received |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 709 | * |
| 710 | * This notification function is called in every timer cycle. |
| 711 | * |
Heinrich Schuchardt | dc305ad | 2019-09-05 20:37:13 +0200 | [diff] [blame] | 712 | * @event: the event for which this notification function is registered |
| 713 | * @context: event context - not used in this function |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 714 | */ |
| 715 | static void EFIAPI efi_network_timer_notify(struct efi_event *event, |
| 716 | void *context) |
| 717 | { |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 718 | struct efi_simple_network *this = (struct efi_simple_network *)context; |
| 719 | |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 720 | EFI_ENTRY("%p, %p", event, context); |
| 721 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 722 | /* |
| 723 | * Some network drivers do not support calling eth_rx() before |
| 724 | * initialization. |
| 725 | */ |
| 726 | if (!this || this->mode->state != EFI_NETWORK_INITIALIZED) |
| 727 | goto out; |
| 728 | |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 729 | if (!rx_packet_num) { |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 730 | push_packet = efi_net_push; |
| 731 | eth_rx(); |
| 732 | push_packet = NULL; |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 733 | if (rx_packet_num) { |
| 734 | this->int_status |= |
| 735 | EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; |
| 736 | wait_for_packet->is_signaled = true; |
Heinrich Schuchardt | d3f1ff2 | 2019-08-31 09:56:30 +0200 | [diff] [blame] | 737 | } |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 738 | } |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 739 | out: |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 740 | EFI_EXIT(EFI_SUCCESS); |
| 741 | } |
| 742 | |
Heinrich Schuchardt | 3127e7e | 2019-08-06 08:13:33 +0200 | [diff] [blame] | 743 | static efi_status_t EFIAPI efi_pxe_base_code_start( |
| 744 | struct efi_pxe_base_code_protocol *this, |
| 745 | u8 use_ipv6) |
| 746 | { |
| 747 | return EFI_UNSUPPORTED; |
| 748 | } |
| 749 | |
| 750 | static efi_status_t EFIAPI efi_pxe_base_code_stop( |
| 751 | struct efi_pxe_base_code_protocol *this) |
| 752 | { |
| 753 | return EFI_UNSUPPORTED; |
| 754 | } |
| 755 | |
| 756 | static efi_status_t EFIAPI efi_pxe_base_code_dhcp( |
| 757 | struct efi_pxe_base_code_protocol *this, |
| 758 | u8 sort_offers) |
| 759 | { |
| 760 | return EFI_UNSUPPORTED; |
| 761 | } |
| 762 | |
| 763 | static efi_status_t EFIAPI efi_pxe_base_code_discover( |
| 764 | struct efi_pxe_base_code_protocol *this, |
| 765 | u16 type, u16 *layer, u8 bis, |
| 766 | struct efi_pxe_base_code_discover_info *info) |
| 767 | { |
| 768 | return EFI_UNSUPPORTED; |
| 769 | } |
| 770 | |
| 771 | static efi_status_t EFIAPI efi_pxe_base_code_mtftp( |
| 772 | struct efi_pxe_base_code_protocol *this, |
| 773 | u32 operation, void *buffer_ptr, |
| 774 | u8 overwrite, efi_uintn_t *buffer_size, |
| 775 | struct efi_ip_address server_ip, char *filename, |
| 776 | struct efi_pxe_base_code_mtftp_info *info, |
| 777 | u8 dont_use_buffer) |
| 778 | { |
| 779 | return EFI_UNSUPPORTED; |
| 780 | } |
| 781 | |
| 782 | static efi_status_t EFIAPI efi_pxe_base_code_udp_write( |
| 783 | struct efi_pxe_base_code_protocol *this, |
| 784 | u16 op_flags, struct efi_ip_address *dest_ip, |
| 785 | u16 *dest_port, |
| 786 | struct efi_ip_address *gateway_ip, |
| 787 | struct efi_ip_address *src_ip, u16 *src_port, |
| 788 | efi_uintn_t *header_size, void *header_ptr, |
| 789 | efi_uintn_t *buffer_size, void *buffer_ptr) |
| 790 | { |
| 791 | return EFI_UNSUPPORTED; |
| 792 | } |
| 793 | |
| 794 | static efi_status_t EFIAPI efi_pxe_base_code_udp_read( |
| 795 | struct efi_pxe_base_code_protocol *this, |
| 796 | u16 op_flags, struct efi_ip_address *dest_ip, |
| 797 | u16 *dest_port, struct efi_ip_address *src_ip, |
| 798 | u16 *src_port, efi_uintn_t *header_size, |
| 799 | void *header_ptr, efi_uintn_t *buffer_size, |
| 800 | void *buffer_ptr) |
| 801 | { |
| 802 | return EFI_UNSUPPORTED; |
| 803 | } |
| 804 | |
| 805 | static efi_status_t EFIAPI efi_pxe_base_code_set_ip_filter( |
| 806 | struct efi_pxe_base_code_protocol *this, |
| 807 | struct efi_pxe_base_code_filter *new_filter) |
| 808 | { |
| 809 | return EFI_UNSUPPORTED; |
| 810 | } |
| 811 | |
| 812 | static efi_status_t EFIAPI efi_pxe_base_code_arp( |
| 813 | struct efi_pxe_base_code_protocol *this, |
| 814 | struct efi_ip_address *ip_addr, |
| 815 | struct efi_mac_address *mac_addr) |
| 816 | { |
| 817 | return EFI_UNSUPPORTED; |
| 818 | } |
| 819 | |
| 820 | static efi_status_t EFIAPI efi_pxe_base_code_set_parameters( |
| 821 | struct efi_pxe_base_code_protocol *this, |
| 822 | u8 *new_auto_arp, u8 *new_send_guid, |
| 823 | u8 *new_ttl, u8 *new_tos, |
| 824 | u8 *new_make_callback) |
| 825 | { |
| 826 | return EFI_UNSUPPORTED; |
| 827 | } |
| 828 | |
| 829 | static efi_status_t EFIAPI efi_pxe_base_code_set_station_ip( |
| 830 | struct efi_pxe_base_code_protocol *this, |
| 831 | struct efi_ip_address *new_station_ip, |
| 832 | struct efi_ip_address *new_subnet_mask) |
| 833 | { |
| 834 | return EFI_UNSUPPORTED; |
| 835 | } |
| 836 | |
| 837 | static efi_status_t EFIAPI efi_pxe_base_code_set_packets( |
| 838 | struct efi_pxe_base_code_protocol *this, |
| 839 | u8 *new_dhcp_discover_valid, |
| 840 | u8 *new_dhcp_ack_received, |
| 841 | u8 *new_proxy_offer_received, |
| 842 | u8 *new_pxe_discover_valid, |
| 843 | u8 *new_pxe_reply_received, |
| 844 | u8 *new_pxe_bis_reply_received, |
| 845 | EFI_PXE_BASE_CODE_PACKET *new_dchp_discover, |
| 846 | EFI_PXE_BASE_CODE_PACKET *new_dhcp_acc, |
| 847 | EFI_PXE_BASE_CODE_PACKET *new_proxy_offer, |
| 848 | EFI_PXE_BASE_CODE_PACKET *new_pxe_discover, |
| 849 | EFI_PXE_BASE_CODE_PACKET *new_pxe_reply, |
| 850 | EFI_PXE_BASE_CODE_PACKET *new_pxe_bis_reply) |
| 851 | { |
| 852 | return EFI_UNSUPPORTED; |
| 853 | } |
| 854 | |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 855 | /** |
| 856 | * efi_net_register() - register the simple network protocol |
| 857 | * |
| 858 | * This gets called from do_bootefi_exec(). |
| 859 | */ |
Heinrich Schuchardt | 6f5c73f | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 860 | efi_status_t efi_net_register(void) |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 861 | { |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 862 | efi_status_t r; |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 863 | int i; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 864 | |
| 865 | if (!eth_get_dev()) { |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 866 | /* No network device active, don't expose any */ |
Heinrich Schuchardt | 6f5c73f | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 867 | return EFI_SUCCESS; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 868 | } |
| 869 | |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 870 | /* We only expose the "active" network device, so one is enough */ |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 871 | netobj = calloc(1, sizeof(*netobj)); |
Heinrich Schuchardt | eb07c28 | 2018-12-01 00:16:32 +0100 | [diff] [blame] | 872 | if (!netobj) |
| 873 | goto out_of_resources; |
| 874 | |
| 875 | /* Allocate an aligned transmit buffer */ |
| 876 | transmit_buffer = calloc(1, PKTSIZE_ALIGN + PKTALIGN); |
| 877 | if (!transmit_buffer) |
| 878 | goto out_of_resources; |
| 879 | transmit_buffer = (void *)ALIGN((uintptr_t)transmit_buffer, PKTALIGN); |
Heinrich Schuchardt | 23b45b6 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 880 | |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 881 | /* Allocate a number of receive buffers */ |
| 882 | receive_buffer = calloc(ETH_PACKETS_BATCH_RECV, |
| 883 | sizeof(*receive_buffer)); |
| 884 | if (!receive_buffer) |
| 885 | goto out_of_resources; |
| 886 | for (i = 0; i < ETH_PACKETS_BATCH_RECV; i++) { |
| 887 | receive_buffer[i] = malloc(PKTSIZE_ALIGN); |
| 888 | if (!receive_buffer[i]) |
| 889 | goto out_of_resources; |
| 890 | } |
| 891 | receive_lengths = calloc(ETH_PACKETS_BATCH_RECV, |
| 892 | sizeof(*receive_lengths)); |
| 893 | if (!receive_lengths) |
| 894 | goto out_of_resources; |
| 895 | |
Heinrich Schuchardt | 23b45b6 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 896 | /* Hook net up to the device list */ |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 897 | efi_add_handle(&netobj->header); |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 898 | |
| 899 | /* Fill in object data */ |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 900 | r = efi_add_protocol(&netobj->header, &efi_net_guid, |
Heinrich Schuchardt | 23b45b6 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 901 | &netobj->net); |
| 902 | if (r != EFI_SUCCESS) |
Heinrich Schuchardt | 6f5c73f | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 903 | goto failure_to_add_protocol; |
Heinrich Schuchardt | 7292872 | 2018-09-26 05:27:56 +0200 | [diff] [blame] | 904 | r = efi_add_protocol(&netobj->header, &efi_guid_device_path, |
Heinrich Schuchardt | 23b45b6 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 905 | efi_dp_from_eth()); |
| 906 | if (r != EFI_SUCCESS) |
Heinrich Schuchardt | 6f5c73f | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 907 | goto failure_to_add_protocol; |
Heinrich Schuchardt | 3127e7e | 2019-08-06 08:13:33 +0200 | [diff] [blame] | 908 | r = efi_add_protocol(&netobj->header, &efi_pxe_base_code_protocol_guid, |
Heinrich Schuchardt | 23b45b6 | 2017-11-26 14:05:13 +0100 | [diff] [blame] | 909 | &netobj->pxe); |
| 910 | if (r != EFI_SUCCESS) |
Heinrich Schuchardt | 6f5c73f | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 911 | goto failure_to_add_protocol; |
Heinrich Schuchardt | d54396a | 2017-10-05 16:35:57 +0200 | [diff] [blame] | 912 | netobj->net.revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 913 | netobj->net.start = efi_net_start; |
| 914 | netobj->net.stop = efi_net_stop; |
| 915 | netobj->net.initialize = efi_net_initialize; |
| 916 | netobj->net.reset = efi_net_reset; |
| 917 | netobj->net.shutdown = efi_net_shutdown; |
| 918 | netobj->net.receive_filters = efi_net_receive_filters; |
| 919 | netobj->net.station_address = efi_net_station_address; |
| 920 | netobj->net.statistics = efi_net_statistics; |
| 921 | netobj->net.mcastiptomac = efi_net_mcastiptomac; |
| 922 | netobj->net.nvdata = efi_net_nvdata; |
| 923 | netobj->net.get_status = efi_net_get_status; |
| 924 | netobj->net.transmit = efi_net_transmit; |
| 925 | netobj->net.receive = efi_net_receive; |
| 926 | netobj->net.mode = &netobj->net_mode; |
Heinrich Schuchardt | 6a6e7d8 | 2019-09-01 15:24:47 +0200 | [diff] [blame] | 927 | netobj->net_mode.state = EFI_NETWORK_STOPPED; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 928 | memcpy(netobj->net_mode.current_address.mac_addr, eth_get_ethaddr(), 6); |
Heinrich Schuchardt | d1cc6cb | 2017-10-05 16:35:58 +0200 | [diff] [blame] | 929 | netobj->net_mode.hwaddr_size = ARP_HLEN; |
Heinrich Schuchardt | 0218a8f | 2019-08-31 10:55:29 +0200 | [diff] [blame] | 930 | netobj->net_mode.media_header_size = ETHER_HDR_SIZE; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 931 | netobj->net_mode.max_packet_size = PKTSIZE; |
Andrew Thomas | 27df0a7 | 2018-06-21 16:21:01 -0700 | [diff] [blame] | 932 | netobj->net_mode.if_type = ARP_ETHER; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 933 | |
Heinrich Schuchardt | 3127e7e | 2019-08-06 08:13:33 +0200 | [diff] [blame] | 934 | netobj->pxe.revision = EFI_PXE_BASE_CODE_PROTOCOL_REVISION; |
| 935 | netobj->pxe.start = efi_pxe_base_code_start; |
| 936 | netobj->pxe.stop = efi_pxe_base_code_stop; |
| 937 | netobj->pxe.dhcp = efi_pxe_base_code_dhcp; |
| 938 | netobj->pxe.discover = efi_pxe_base_code_discover; |
| 939 | netobj->pxe.mtftp = efi_pxe_base_code_mtftp; |
| 940 | netobj->pxe.udp_write = efi_pxe_base_code_udp_write; |
| 941 | netobj->pxe.udp_read = efi_pxe_base_code_udp_read; |
| 942 | netobj->pxe.set_ip_filter = efi_pxe_base_code_set_ip_filter; |
| 943 | netobj->pxe.arp = efi_pxe_base_code_arp; |
| 944 | netobj->pxe.set_parameters = efi_pxe_base_code_set_parameters; |
| 945 | netobj->pxe.set_station_ip = efi_pxe_base_code_set_station_ip; |
| 946 | netobj->pxe.set_packets = efi_pxe_base_code_set_packets; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 947 | netobj->pxe.mode = &netobj->pxe_mode; |
| 948 | if (dhcp_ack) |
| 949 | netobj->pxe_mode.dhcp_ack = *dhcp_ack; |
| 950 | |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 951 | /* |
Heinrich Schuchardt | 0c153c2 | 2017-10-05 16:36:01 +0200 | [diff] [blame] | 952 | * Create WaitForPacket event. |
| 953 | */ |
| 954 | r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK, |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 955 | efi_network_timer_notify, NULL, NULL, |
Heinrich Schuchardt | 0c153c2 | 2017-10-05 16:36:01 +0200 | [diff] [blame] | 956 | &wait_for_packet); |
| 957 | if (r != EFI_SUCCESS) { |
| 958 | printf("ERROR: Failed to register network event\n"); |
| 959 | return r; |
| 960 | } |
| 961 | netobj->net.wait_for_packet = wait_for_packet; |
| 962 | /* |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 963 | * Create a timer event. |
| 964 | * |
| 965 | * The notification function is used to check if a new network packet |
| 966 | * has been received. |
Heinrich Schuchardt | 86df48c | 2018-03-24 18:40:22 +0100 | [diff] [blame] | 967 | * |
| 968 | * 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] | 969 | */ |
Heinrich Schuchardt | 86df48c | 2018-03-24 18:40:22 +0100 | [diff] [blame] | 970 | r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_NOTIFY, |
Heinrich Schuchardt | b6f2036 | 2018-12-01 00:16:33 +0100 | [diff] [blame] | 971 | efi_network_timer_notify, &netobj->net, NULL, |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 972 | &network_timer_event); |
| 973 | if (r != EFI_SUCCESS) { |
| 974 | printf("ERROR: Failed to register network event\n"); |
| 975 | return r; |
| 976 | } |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 977 | /* Network is time critical, create event in every timer cycle */ |
Heinrich Schuchardt | 3d7fc69 | 2017-10-05 16:36:00 +0200 | [diff] [blame] | 978 | r = efi_set_timer(network_timer_event, EFI_TIMER_PERIODIC, 0); |
| 979 | if (r != EFI_SUCCESS) { |
| 980 | printf("ERROR: Failed to set network timer\n"); |
| 981 | return r; |
| 982 | } |
| 983 | |
Heinrich Schuchardt | 6f5c73f | 2018-03-03 15:28:56 +0100 | [diff] [blame] | 984 | return EFI_SUCCESS; |
| 985 | failure_to_add_protocol: |
| 986 | printf("ERROR: Failure to add protocol\n"); |
| 987 | return r; |
Heinrich Schuchardt | eb07c28 | 2018-12-01 00:16:32 +0100 | [diff] [blame] | 988 | out_of_resources: |
| 989 | free(netobj); |
Heinrich Schuchardt | 2f1a93f | 2022-11-26 16:44:38 +0100 | [diff] [blame] | 990 | netobj = NULL; |
Patrick Wildt | fab8910 | 2020-10-07 11:04:33 +0200 | [diff] [blame] | 991 | free(transmit_buffer); |
| 992 | if (receive_buffer) |
| 993 | for (i = 0; i < ETH_PACKETS_BATCH_RECV; i++) |
| 994 | free(receive_buffer[i]); |
| 995 | free(receive_buffer); |
| 996 | free(receive_lengths); |
Heinrich Schuchardt | eb07c28 | 2018-12-01 00:16:32 +0100 | [diff] [blame] | 997 | printf("ERROR: Out of memory\n"); |
| 998 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | 94c4b99 | 2016-05-06 21:01:01 +0200 | [diff] [blame] | 999 | } |