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