3 Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #include <Protocol/SimpleNetwork.h>
27 #include <Protocol/DevicePath.h>
28 #include <Protocol/EmuIoThunk.h>
29 #include <Protocol/EmuSnp.h>
32 #include <Library/BaseLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/DevicePathLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/NetLib.h>
41 #define NET_ETHER_HEADER_SIZE 14
44 // Private data for driver.
46 #define EMU_SNP_PRIVATE_DATA_SIGNATURE SIGNATURE_32( 'U', 'S', 'N', 'P' )
50 EMU_IO_THUNK_PROTOCOL
*IoThunk
;
52 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
55 EFI_HANDLE DeviceHandle
;
57 EFI_SIMPLE_NETWORK_PROTOCOL Snp
;
58 EFI_SIMPLE_NETWORK_MODE Mode
;
60 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
62 } EMU_SNP_PRIVATE_DATA
;
64 #define EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS(a) \
65 CR( a, EMU_SNP_PRIVATE_DATA, Snp, EMU_SNP_PRIVATE_DATA_SIGNATURE )
67 extern EFI_DRIVER_BINDING_PROTOCOL gEmuSnpDriverBinding
;
68 extern EFI_COMPONENT_NAME_PROTOCOL gEmuSnpDriverComponentName
;
69 extern EFI_COMPONENT_NAME2_PROTOCOL gEmuSnpDriverComponentName2
;
72 Test to see if this driver supports ControllerHandle. This service
73 is called by the EFI boot service ConnectController(). In
74 order to make drivers as small as possible, there are a few calling
75 restrictions for this service. ConnectController() must
76 follow these calling restrictions. If any other agent wishes to call
77 Supported() it must also follow these calling restrictions.
79 @param This Protocol instance pointer.
80 @param ControllerHandle Handle of device to test
81 @param RemainingDevicePath Optional parameter use to pick a specific child
84 @retval EFI_SUCCESS This driver supports this device
85 @retval EFI_UNSUPPORTED This driver does not support this device
90 EmuSnpDriverBindingSupported (
91 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
92 IN EFI_HANDLE ControllerHandle
,
93 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
97 Start this driver on ControllerHandle. This service is called by the
98 EFI boot service ConnectController(). In order to make
99 drivers as small as possible, there are a few calling restrictions for
100 this service. ConnectController() must follow these
101 calling restrictions. If any other agent wishes to call Start() it
102 must also follow these calling restrictions.
104 @param This Protocol instance pointer.
105 @param ControllerHandle Handle of device to bind driver to
106 @param RemainingDevicePath Optional parameter use to pick a specific child
109 @retval EFI_SUCCESS Always succeeds.
114 EmuSnpDriverBindingStart (
115 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
116 IN EFI_HANDLE ControllerHandle
,
117 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
121 Stop this driver on ControllerHandle. This service is called by the
122 EFI boot service DisconnectController(). In order to
123 make drivers as small as possible, there are a few calling
124 restrictions for this service. DisconnectController()
125 must follow these calling restrictions. If any other agent wishes
126 to call Stop() it must also follow these calling restrictions.
128 @param This Protocol instance pointer.
129 @param ControllerHandle Handle of device to stop driver on
130 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
131 children is zero stop the entire bus driver.
132 @param ChildHandleBuffer List of Child Handles to Stop.
134 @retval EFI_SUCCESS Always succeeds.
139 EmuSnpDriverBindingStop (
140 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
141 IN EFI_HANDLE ControllerHandle
,
142 IN UINTN NumberOfChildren
,
143 IN EFI_HANDLE
*ChildHandleBuffer
147 Changes the state of a network interface from "stopped" to "started".
149 @param This Protocol instance pointer.
151 @retval EFI_SUCCESS Always succeeds.
157 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
161 Changes the state of a network interface from "started" to "stopped".
163 @param This Protocol instance pointer.
165 @retval EFI_SUCCESS Always succeeds.
171 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
175 Resets a network adapter and allocates the transmit and receive buffers
176 required by the network interface; optionally, also requests allocation
177 of additional transmit and receive buffers.
179 @param This Protocol instance pointer.
180 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
181 that the driver should allocate for the network interface.
182 Some network interfaces will not be able to use the extra
183 buffer, and the caller will not know if it is actually
185 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
186 that the driver should allocate for the network interface.
187 Some network interfaces will not be able to use the extra
188 buffer, and the caller will not know if it is actually
191 @retval EFI_SUCCESS Always succeeds.
197 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
198 IN UINTN ExtraRxBufferSize OPTIONAL
,
199 IN UINTN ExtraTxBufferSize OPTIONAL
203 Resets a network adapter and re-initializes it with the parameters that were
204 provided in the previous call to Initialize().
206 @param This Protocol instance pointer.
207 @param ExtendedVerification Indicates that the driver may perform a more
208 exhaustive verification operation of the device
211 @retval EFI_SUCCESS Always succeeds.
217 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
218 IN BOOLEAN ExtendedVerification
222 Resets a network adapter and leaves it in a state that is safe for
223 another driver to initialize.
225 @param This Protocol instance pointer.
227 @retval EFI_SUCCESS Always succeeds.
233 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
237 Manages the multicast receive filters of a network interface.
239 @param This Protocol instance pointer.
240 @param EnableBits A bit mask of receive filters to enable on the network interface.
241 @param DisableBits A bit mask of receive filters to disable on the network interface.
242 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
243 filters on the network interface to their default values.
244 @param McastFilterCount Number of multicast HW MAC addresses in the new
245 MCastFilter list. This value must be less than or equal to
246 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
247 field is optional if ResetMCastFilter is TRUE.
248 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
249 addresses. This list will replace any existing multicast
250 HW MAC address list. This field is optional if
251 ResetMCastFilter is TRUE.
253 @retval EFI_SUCCESS The multicast receive filter list was updated.
254 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
259 EmuSnpReceiveFilters(
260 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
261 IN UINT32 EnableBits
,
262 IN UINT32 DisableBits
,
263 IN BOOLEAN ResetMcastFilter
,
264 IN UINTN McastFilterCount OPTIONAL
,
265 IN EFI_MAC_ADDRESS
* McastFilter OPTIONAL
269 Modifies or resets the current station address, if supported.
271 @param This Protocol instance pointer.
272 @param Reset Flag used to reset the station address to the network interfaces
274 @param NewMacAddr New station address to be used for the network interface.
276 @retval EFI_UNSUPPORTED Not supported yet.
281 EmuSnpStationAddress(
282 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
284 IN EFI_MAC_ADDRESS
* NewMacAddr OPTIONAL
288 Resets or collects the statistics on a network interface.
290 @param This Protocol instance pointer.
291 @param Reset Set to TRUE to reset the statistics for the network interface.
292 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
293 output the size, in bytes, of the resulting table of
295 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
296 contains the statistics.
298 @retval EFI_SUCCESS The statistics were collected from the network interface.
299 @retval EFI_NOT_STARTED The network interface has not been started.
300 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
301 size needed to hold the statistics is returned in
303 @retval EFI_UNSUPPORTED Not supported yet.
309 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
311 IN OUT UINTN
* StatisticsSize OPTIONAL
,
312 OUT EFI_NETWORK_STATISTICS
* StatisticsTable OPTIONAL
316 Converts a multicast IP address to a multicast HW MAC address.
318 @param This Protocol instance pointer.
319 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
320 to FALSE if the multicast IP address is IPv4 [RFC 791].
321 @param Ip The multicast IP address that is to be converted to a multicast
323 @param Mac The multicast HW MAC address that is to be generated from IP.
325 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
327 @retval EFI_NOT_STARTED The network interface has not been started.
328 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
329 size needed to hold the statistics is returned in
331 @retval EFI_UNSUPPORTED Not supported yet.
337 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
339 IN EFI_IP_ADDRESS
* Ip
,
340 OUT EFI_MAC_ADDRESS
* Mac
344 Performs read and write operations on the NVRAM device attached to a
347 @param This Protocol instance pointer.
348 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
349 @param Offset Byte offset in the NVRAM device at which to start the read or
350 write operation. This must be a multiple of NvRamAccessSize and
352 @param BufferSize The number of bytes to read or write from the NVRAM device.
353 This must also be a multiple of NvramAccessSize.
354 @param Buffer A pointer to the data buffer.
356 @retval EFI_UNSUPPORTED Not supported yet.
362 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
363 IN BOOLEAN ReadOrWrite
,
370 Reads the current interrupt status and recycled transmit buffer status from
373 @param This Protocol instance pointer.
374 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
375 If this is NULL, the interrupt status will not be read from
376 the device. If this is not NULL, the interrupt status will
377 be read from the device. When the interrupt status is read,
378 it will also be cleared. Clearing the transmit interrupt
379 does not empty the recycled transmit buffer array.
380 @param TxBuffer Recycled transmit buffer address. The network interface will
381 not transmit if its internal recycled transmit buffer array
382 is full. Reading the transmit buffer does not clear the
383 transmit interrupt. If this is NULL, then the transmit buffer
384 status will not be read. If there are no transmit buffers to
385 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
387 @retval EFI_SUCCESS Always succeeds.
393 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
394 OUT UINT32
* InterruptStatus
,
399 Places a packet in the transmit queue of a network interface.
401 @param This Protocol instance pointer.
402 @param HeaderSize The size, in bytes, of the media header to be filled in by
403 the Transmit() function. If HeaderSize is non-zero, then it
404 must be equal to This->Mode->MediaHeaderSize and the DestAddr
405 and Protocol parameters must not be NULL.
406 @param BufferSize The size, in bytes, of the entire packet (media header and
407 data) to be transmitted through the network interface.
408 @param Buffer A pointer to the packet (media header followed by data) to be
409 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
410 then the media header in Buffer must already be filled in by the
411 caller. If HeaderSize is non-zero, then the media header will be
412 filled in by the Transmit() function.
413 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
414 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
415 This->Mode->CurrentAddress is used for the source HW MAC address.
416 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
417 parameter is ignored.
418 @param Protocol The type of header to build. If HeaderSize is zero, then this
419 parameter is ignored. See RFC 1700, section "Ether Types", for
422 @retval EFI_SUCCESS The packet was placed on the transmit queue.
423 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
424 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
430 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
434 IN EFI_MAC_ADDRESS
* SrcAddr OPTIONAL
,
435 IN EFI_MAC_ADDRESS
* DestAddr OPTIONAL
,
436 IN UINT16
* Protocol OPTIONAL
440 Receives a packet from a network interface.
442 @param This Protocol instance pointer.
443 @param HeaderSize The size, in bytes, of the media header received on the network
444 interface. If this parameter is NULL, then the media header size
445 will not be returned.
446 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
447 bytes, of the packet that was received on the network interface.
448 @param Buffer A pointer to the data buffer to receive both the media header and
450 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
451 HW MAC source address will not be extracted from the media
453 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
454 the HW MAC destination address will not be extracted from the
456 @param Protocol The media header type. If this parameter is NULL, then the
457 protocol will not be extracted from the media header. See
458 RFC 1700 section "Ether Types" for examples.
460 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
461 been updated to the number of bytes received.
462 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
464 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
465 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
466 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
472 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
473 OUT UINTN
* HeaderSize OPTIONAL
,
474 IN OUT UINTN
* BuffSize
,
476 OUT EFI_MAC_ADDRESS
* SourceAddr OPTIONAL
,
477 OUT EFI_MAC_ADDRESS
* DestinationAddr OPTIONAL
,
478 OUT UINT16
* Protocol OPTIONAL
483 EmuSnpWaitForPacketNotify(
488 #endif // _EMU_SNP_H_