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.
21 #include <Library/PrintLib.h>
25 EFI_DRIVER_BINDING_PROTOCOL gUnixSnpDriverBinding
=
27 UnixSnpDriverBindingSupported
,
28 UnixSnpDriverBindingStart
,
29 UnixSnpDriverBindingStop
,
36 Changes the state of a network interface from "stopped" to "started".
38 @param This Protocol instance pointer.
40 @retval EFI_SUCCESS Always succeeds.
46 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
50 Changes the state of a network interface from "started" to "stopped".
52 @param This Protocol instance pointer.
54 @retval EFI_SUCCESS Always succeeds.
60 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
64 Resets a network adapter and allocates the transmit and receive buffers
65 required by the network interface; optionally, also requests allocation
66 of additional transmit and receive buffers.
68 @param This Protocol instance pointer.
69 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
70 that the driver should allocate for the network interface.
71 Some network interfaces will not be able to use the extra
72 buffer, and the caller will not know if it is actually
74 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
75 that the driver should allocate for the network interface.
76 Some network interfaces will not be able to use the extra
77 buffer, and the caller will not know if it is actually
80 @retval EFI_SUCCESS Always succeeds.
86 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
87 IN UINTN ExtraRxBufferSize OPTIONAL
,
88 IN UINTN ExtraTxBufferSize OPTIONAL
92 Resets a network adapter and re-initializes it with the parameters that were
93 provided in the previous call to Initialize().
95 @param This Protocol instance pointer.
96 @param ExtendedVerification Indicates that the driver may perform a more
97 exhaustive verification operation of the device
100 @retval EFI_SUCCESS Always succeeds.
106 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
107 IN BOOLEAN ExtendedVerification
111 Resets a network adapter and leaves it in a state that is safe for
112 another driver to initialize.
114 @param This Protocol instance pointer.
116 @retval EFI_SUCCESS Always succeeds.
122 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
126 Manages the multicast receive filters of a network interface.
128 @param This Protocol instance pointer.
129 @param EnableBits A bit mask of receive filters to enable on the network interface.
130 @param DisableBits A bit mask of receive filters to disable on the network interface.
131 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
132 filters on the network interface to their default values.
133 @param McastFilterCount Number of multicast HW MAC addresses in the new
134 MCastFilter list. This value must be less than or equal to
135 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
136 field is optional if ResetMCastFilter is TRUE.
137 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
138 addresses. This list will replace any existing multicast
139 HW MAC address list. This field is optional if
140 ResetMCastFilter is TRUE.
142 @retval EFI_SUCCESS The multicast receive filter list was updated.
143 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
148 UnixSnpReceiveFilters(
149 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
150 IN UINT32 EnableBits
,
151 IN UINT32 DisableBits
,
152 IN BOOLEAN ResetMcastFilter
,
153 IN UINTN McastFilterCount OPTIONAL
,
154 IN EFI_MAC_ADDRESS
* McastFilter OPTIONAL
158 Modifies or resets the current station address, if supported.
160 @param This Protocol instance pointer.
161 @param Reset Flag used to reset the station address to the network interfaces
163 @param NewMacAddr New station address to be used for the network interface.
165 @retval EFI_UNSUPPORTED Not supported yet.
170 UnixSnpStationAddress(
171 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
173 IN EFI_MAC_ADDRESS
* NewMacAddr OPTIONAL
177 Resets or collects the statistics on a network interface.
179 @param This Protocol instance pointer.
180 @param Reset Set to TRUE to reset the statistics for the network interface.
181 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
182 output the size, in bytes, of the resulting table of
184 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
185 contains the statistics.
187 @retval EFI_SUCCESS The statistics were collected from the network interface.
188 @retval EFI_NOT_STARTED The network interface has not been started.
189 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
190 size needed to hold the statistics is returned in
192 @retval EFI_UNSUPPORTED Not supported yet.
198 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
200 IN OUT UINTN
* StatisticsSize OPTIONAL
,
201 OUT EFI_NETWORK_STATISTICS
* StatisticsTable OPTIONAL
205 Converts a multicast IP address to a multicast HW MAC address.
207 @param This Protocol instance pointer.
208 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
209 to FALSE if the multicast IP address is IPv4 [RFC 791].
210 @param Ip The multicast IP address that is to be converted to a multicast
212 @param Mac The multicast HW MAC address that is to be generated from IP.
214 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
216 @retval EFI_NOT_STARTED The network interface has not been started.
217 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
218 size needed to hold the statistics is returned in
220 @retval EFI_UNSUPPORTED Not supported yet.
226 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
228 IN EFI_IP_ADDRESS
* Ip
,
229 OUT EFI_MAC_ADDRESS
* Mac
233 Performs read and write operations on the NVRAM device attached to a
236 @param This Protocol instance pointer.
237 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
238 @param Offset Byte offset in the NVRAM device at which to start the read or
239 write operation. This must be a multiple of NvRamAccessSize and
241 @param BufferSize The number of bytes to read or write from the NVRAM device.
242 This must also be a multiple of NvramAccessSize.
243 @param Buffer A pointer to the data buffer.
245 @retval EFI_UNSUPPORTED Not supported yet.
251 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
252 IN BOOLEAN ReadOrWrite
,
259 Reads the current interrupt status and recycled transmit buffer status from
262 @param This Protocol instance pointer.
263 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
264 If this is NULL, the interrupt status will not be read from
265 the device. If this is not NULL, the interrupt status will
266 be read from the device. When the interrupt status is read,
267 it will also be cleared. Clearing the transmit interrupt
268 does not empty the recycled transmit buffer array.
269 @param TxBuffer Recycled transmit buffer address. The network interface will
270 not transmit if its internal recycled transmit buffer array
271 is full. Reading the transmit buffer does not clear the
272 transmit interrupt. If this is NULL, then the transmit buffer
273 status will not be read. If there are no transmit buffers to
274 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
276 @retval EFI_SUCCESS Always succeeds.
282 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
283 OUT UINT32
* InterruptStatus
,
288 Places a packet in the transmit queue of a network interface.
290 @param This Protocol instance pointer.
291 @param HeaderSize The size, in bytes, of the media header to be filled in by
292 the Transmit() function. If HeaderSize is non-zero, then it
293 must be equal to This->Mode->MediaHeaderSize and the DestAddr
294 and Protocol parameters must not be NULL.
295 @param BufferSize The size, in bytes, of the entire packet (media header and
296 data) to be transmitted through the network interface.
297 @param Buffer A pointer to the packet (media header followed by data) to be
298 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
299 then the media header in Buffer must already be filled in by the
300 caller. If HeaderSize is non-zero, then the media header will be
301 filled in by the Transmit() function.
302 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
303 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
304 This->Mode->CurrentAddress is used for the source HW MAC address.
305 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
306 parameter is ignored.
307 @param Protocol The type of header to build. If HeaderSize is zero, then this
308 parameter is ignored. See RFC 1700, section "Ether Types", for
311 @retval EFI_SUCCESS The packet was placed on the transmit queue.
312 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
313 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
319 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
323 IN EFI_MAC_ADDRESS
* SrcAddr OPTIONAL
,
324 IN EFI_MAC_ADDRESS
* DestAddr OPTIONAL
,
325 IN UINT16
* Protocol OPTIONAL
329 Receives a packet from a network interface.
331 @param This Protocol instance pointer.
332 @param HeaderSize The size, in bytes, of the media header received on the network
333 interface. If this parameter is NULL, then the media header size
334 will not be returned.
335 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
336 bytes, of the packet that was received on the network interface.
337 @param Buffer A pointer to the data buffer to receive both the media header and
339 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
340 HW MAC source address will not be extracted from the media
342 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
343 the HW MAC destination address will not be extracted from the
345 @param Protocol The media header type. If this parameter is NULL, then the
346 protocol will not be extracted from the media header. See
347 RFC 1700 section "Ether Types" for examples.
349 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
350 been updated to the number of bytes received.
351 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
353 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
354 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
355 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
361 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
362 OUT UINTN
* HeaderSize OPTIONAL
,
363 IN OUT UINTN
* BuffSize
,
365 OUT EFI_MAC_ADDRESS
* SourceAddr OPTIONAL
,
366 OUT EFI_MAC_ADDRESS
* DestinationAddr OPTIONAL
,
367 OUT UINT16
* Protocol OPTIONAL
372 UnixSnpWaitForPacketNotify(
378 // Strange, but there doesn't appear to be any structure for the Ethernet header in edk2...
383 UINT8 DstAddr
[ NET_ETHER_ADDR_LEN
];
384 UINT8 SrcAddr
[ NET_ETHER_ADDR_LEN
];
388 UNIX_SNP_PRIVATE_DATA gUnixSnpPrivateTemplate
=
390 UNIX_SNP_PRIVATE_DATA_SIGNATURE
, // Signature
392 NULL
, // DeviceHandle
395 NULL
, // InterfaceName
398 NULL
, // CurrentReadPointer
399 NULL
, // EndReadPointer
402 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
, // Revision
403 UnixSnpStart
, // Start
405 UnixSnpInitialize
, // Initialize
406 UnixSnpReset
, // Reset
407 UnixSnpShutdown
, // Shutdown
408 UnixSnpReceiveFilters
, // ReceiveFilters
409 UnixSnpStationAddress
, // StationAddress
410 UnixSnpStatistics
, // Statistics
411 UnixSnpMcastIptoMac
, // MCastIpToMac
412 UnixSnpNvdata
, // NvData
413 UnixSnpGetStatus
, // GetStatus
414 UnixSnpTransmit
, // Transmit
415 UnixSnpReceive
, // Receive
416 NULL
, // WaitForPacket
420 EfiSimpleNetworkStopped
, // State
421 NET_ETHER_ADDR_LEN
, // HwAddressSize
422 NET_ETHER_HEADER_SIZE
, // MediaHeaderSize
423 1500, // MaxPacketSize
425 0, // NvRamAccessSize
426 0, // ReceiveFilterMask
427 0, // ReceiveFilterSetting
428 MAX_MCAST_FILTER_CNT
, // MaxMCastFilterCount
429 0, // MCastFilterCount
438 }, // BroadcastAddress
441 }, // PermanentAddress
442 NET_IFTYPE_ETHERNET
, // IfType
443 FALSE
, // MacAddressChangeable
444 FALSE
, // MultipleTxSupported
445 FALSE
, // MediaPresentSupported
452 IN UNIX_SNP_PRIVATE_DATA
* Private
,
453 IN EFI_UNIX_IO_PROTOCOL
* UnixIo
456 struct ifaddrs
* IfAddrs
;
458 struct sockaddr_dl
* IfSdl
;
462 Result
= UnixIo
->UnixThunk
->GetIfAddrs( &IfAddrs
);
465 return( EFI_UNSUPPORTED
);
469 // Convert the interface name to ASCII so we can find it.
471 Private
->InterfaceName
= AllocateZeroPool( StrLen( UnixIo
->EnvString
) );
473 if ( !Private
->InterfaceName
)
475 Status
= EFI_OUT_OF_RESOURCES
;
479 UnicodeStrToAsciiStr( UnixIo
->EnvString
, Private
->InterfaceName
);
485 IfSdl
= ( struct sockaddr_dl
* ) If
->ifa_addr
;
487 if ( IfSdl
->sdl_family
== AF_LINK
)
489 if ( !AsciiStrCmp( Private
->InterfaceName
, If
->ifa_name
) )
491 CopyMem( &Private
->MacAddress
, LLADDR( IfSdl
), NET_ETHER_ADDR_LEN
);
493 Status
= EFI_SUCCESS
;
502 ( VOID
) UnixIo
->UnixThunk
->FreeIfAddrs( IfAddrs
);
509 OpenBpfFileDescriptor(
510 IN UNIX_SNP_PRIVATE_DATA
* Private
,
514 CHAR8 BfpDeviceName
[ 256 ];
516 EFI_STATUS Status
= EFI_OUT_OF_RESOURCES
;
520 // Open a Berkeley Packet Filter device. This must be done as root, so this is probably
521 // the place which is most likely to fail...
523 for ( Index
= 0; TRUE
; Index
++ )
525 AsciiSPrint( BfpDeviceName
, sizeof( BfpDeviceName
), "/dev/bpf%d", Index
);
527 *Fd
= Private
->UnixThunk
->Open( BfpDeviceName
, O_RDWR
, 0 );
531 Status
= EFI_SUCCESS
;
535 Result
= Private
->UnixThunk
->GetErrno();
536 if ( Result
== EACCES
)
538 DEBUG( ( EFI_D_ERROR
, "Permissions on '%a' are incorrect. Fix with 'sudo chmod 666 %a'.\n",
539 BfpDeviceName
, BfpDeviceName
) );
541 if ( Result
!= EBUSY
)
552 Test to see if this driver supports ControllerHandle. This service
553 is called by the EFI boot service ConnectController(). In
554 order to make drivers as small as possible, there are a few calling
555 restrictions for this service. ConnectController() must
556 follow these calling restrictions. If any other agent wishes to call
557 Supported() it must also follow these calling restrictions.
559 @param This Protocol instance pointer.
560 @param ControllerHandle Handle of device to test
561 @param RemainingDevicePath Optional parameter use to pick a specific child
564 @retval EFI_SUCCESS This driver supports this device
565 @retval EFI_UNSUPPORTED This driver does not support this device
570 UnixSnpDriverBindingSupported(
571 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
572 IN EFI_HANDLE ControllerHandle
,
573 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
577 EFI_UNIX_IO_PROTOCOL
* UnixIo
;
580 // Open the I/O abstraction needed to perform the supported test.
582 Status
= gBS
->OpenProtocol(
584 &gEfiUnixIoProtocolGuid
,
586 This
->DriverBindingHandle
,
588 EFI_OPEN_PROTOCOL_BY_DRIVER
591 if ( EFI_ERROR( Status
) )
599 Status
= EFI_UNSUPPORTED
;
600 if ( CompareGuid( UnixIo
->TypeGuid
, &gEfiUnixNetworkGuid
) )
602 Status
= EFI_SUCCESS
;
606 // Close the I/O abstraction used to perform the supported test.
610 &gEfiUnixIoProtocolGuid
,
611 This
->DriverBindingHandle
,
620 Start this driver on ControllerHandle. This service is called by the
621 EFI boot service ConnectController(). In order to make
622 drivers as small as possible, there are a few calling restrictions for
623 this service. ConnectController() must follow these
624 calling restrictions. If any other agent wishes to call Start() it
625 must also follow these calling restrictions.
627 @param This Protocol instance pointer.
628 @param ControllerHandle Handle of device to bind driver to
629 @param RemainingDevicePath Optional parameter use to pick a specific child
632 @retval EFI_SUCCESS Always succeeds.
637 UnixSnpDriverBindingStart(
638 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
639 IN EFI_HANDLE ControllerHandle
,
640 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
643 MAC_ADDR_DEVICE_PATH Node
;
644 EFI_DEVICE_PATH_PROTOCOL
* ParentDevicePath
= NULL
;
645 EFI_UNIX_IO_PROTOCOL
* UnixIo
;
646 UNIX_SNP_PRIVATE_DATA
* Private
= NULL
;
648 BOOLEAN CreateDevice
;
651 // Grab the protocols we need.
653 Status
= gBS
->OpenProtocol(
655 &gEfiDevicePathProtocolGuid
,
656 ( VOID
** ) &ParentDevicePath
,
657 This
->DriverBindingHandle
,
659 EFI_OPEN_PROTOCOL_BY_DRIVER
661 if ( EFI_ERROR( Status
) )
667 // Open the I/O abstraction needed to perform the supported test.
669 Status
= gBS
->OpenProtocol(
671 &gEfiUnixIoProtocolGuid
,
673 This
->DriverBindingHandle
,
675 EFI_OPEN_PROTOCOL_BY_DRIVER
677 if ( EFI_ERROR( Status
) )
685 if ( !CompareGuid( UnixIo
->TypeGuid
, &gEfiUnixNetworkGuid
) )
687 Status
= EFI_UNSUPPORTED
;
692 if ( ( RemainingDevicePath
!= NULL
) && IsDevicePathEnd( RemainingDevicePath
) )
694 CreateDevice
= FALSE
;
700 // Allocate the private data.
702 Private
= AllocateCopyPool( sizeof( UNIX_SNP_PRIVATE_DATA
), &gUnixSnpPrivateTemplate
);
703 if ( Private
== NULL
)
705 Status
= EFI_OUT_OF_RESOURCES
;
709 Status
= GetInterfaceMacAddr( Private
, UnixIo
);
710 if ( EFI_ERROR( Status
) )
715 Private
->UnixThunk
= UnixIo
->UnixThunk
;
717 Private
->Snp
.Mode
= &Private
->Mode
;
720 // Set the broadcast address.
722 SetMem( &Private
->Mode
.BroadcastAddress
, sizeof( EFI_MAC_ADDRESS
), 0xFF );
724 CopyMem( &Private
->Mode
.CurrentAddress
, &Private
->MacAddress
, sizeof( EFI_MAC_ADDRESS
) );
725 CopyMem( &Private
->Mode
.PermanentAddress
, &Private
->MacAddress
, sizeof( EFI_MAC_ADDRESS
) );
728 // Since the fake SNP is based on a real NIC, to avoid conflict with the host NIC
729 // network stack, we use a different MAC address.
730 // So just change the last byte of the MAC address for the real NIC.
732 Private
->Mode
.CurrentAddress
.Addr
[ NET_ETHER_ADDR_LEN
- 1 ]++;
735 // Build the device path by appending the MAC node to the ParentDevicePath
736 // from the UnixIo handle.
738 ZeroMem( &Node
, sizeof( MAC_ADDR_DEVICE_PATH
) );
740 Node
.Header
.Type
= MESSAGING_DEVICE_PATH
;
741 Node
.Header
.SubType
= MSG_MAC_ADDR_DP
;
742 Node
.IfType
= Private
->Mode
.IfType
;
744 SetDevicePathNodeLength( ( EFI_DEVICE_PATH_PROTOCOL
* ) &Node
, sizeof( MAC_ADDR_DEVICE_PATH
) );
746 CopyMem( &Node
.MacAddress
, &Private
->Mode
.CurrentAddress
, sizeof( EFI_MAC_ADDRESS
) );
749 // Build the device path by appending the MAC node to the ParentDevicePath from the UnixIo handle.
751 Private
->DevicePath
= AppendDevicePathNode( ParentDevicePath
, ( EFI_DEVICE_PATH_PROTOCOL
* ) &Node
);
752 if ( Private
->DevicePath
== NULL
)
754 Status
= EFI_OUT_OF_RESOURCES
;
758 Status
= gBS
->InstallMultipleProtocolInterfaces(
759 &Private
->DeviceHandle
,
760 &gEfiSimpleNetworkProtocolGuid
,
762 &gEfiDevicePathProtocolGuid
,
766 if ( EFI_ERROR( Status
) )
771 Status
= gBS
->OpenProtocol(
773 &gEfiUnixIoProtocolGuid
,
775 This
->DriverBindingHandle
,
776 Private
->DeviceHandle
,
777 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
779 if ( EFI_ERROR( Status
) )
787 if ( Private
->InterfaceName
!= NULL
)
789 FreePool( Private
->InterfaceName
);
790 Private
->InterfaceName
= NULL
;
792 if ( Private
!= NULL
)
796 if ( ParentDevicePath
!= NULL
)
800 &gEfiDevicePathProtocolGuid
,
801 This
->DriverBindingHandle
,
810 Stop this driver on ControllerHandle. This service is called by the
811 EFI boot service DisconnectController(). In order to
812 make drivers as small as possible, there are a few calling
813 restrictions for this service. DisconnectController()
814 must follow these calling restrictions. If any other agent wishes
815 to call Stop() it must also follow these calling restrictions.
817 @param This Protocol instance pointer.
818 @param ControllerHandle Handle of device to stop driver on
819 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
820 children is zero stop the entire bus driver.
821 @param ChildHandleBuffer List of Child Handles to Stop.
823 @retval EFI_SUCCESS Always succeeds.
828 UnixSnpDriverBindingStop(
829 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
830 IN EFI_HANDLE ControllerHandle
,
831 IN UINTN NumberOfChildren
,
832 IN EFI_HANDLE
* ChildHandleBuffer
835 UNIX_SNP_PRIVATE_DATA
* Private
= NULL
;
836 EFI_SIMPLE_NETWORK_PROTOCOL
* Snp
;
840 // Get our context back.
842 Status
= gBS
->OpenProtocol(
844 &gEfiSimpleNetworkProtocolGuid
,
846 This
->DriverBindingHandle
,
848 EFI_OPEN_PROTOCOL_GET_PROTOCOL
850 if ( EFI_ERROR( Status
) )
852 return( EFI_UNSUPPORTED
);
855 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( Snp
);
857 Status
= gBS
->CloseProtocol(
859 &gEfiUnixIoProtocolGuid
,
860 This
->DriverBindingHandle
,
861 Private
->DeviceHandle
864 Status
= gBS
->UninstallMultipleProtocolInterfaces(
865 Private
->DeviceHandle
,
866 &gEfiSimpleNetworkProtocolGuid
,
868 &gEfiDevicePathProtocolGuid
,
873 FreePool( Private
->InterfaceName
);
874 FreePool( Private
->DevicePath
);
877 return( EFI_SUCCESS
);
882 Changes the state of a network interface from "stopped" to "started".
884 @param This Protocol instance pointer.
886 @retval EFI_SUCCESS Always succeeds.
892 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
895 STATIC
struct bpf_insn FilterInstructionTemplate
[] =
897 // Load 4 bytes from the destination MAC address.
898 BPF_STMT( BPF_LD
+ BPF_W
+ BPF_ABS
, OFFSET_OF( EthernetHeader
, DstAddr
[ 0 ] ) ),
900 // Compare to first 4 bytes of fake MAC address.
901 BPF_JUMP( BPF_JMP
+ BPF_JEQ
+ BPF_K
, 0x12345678, 0, 3 ),
903 // Load remaining 2 bytes from the destination MAC address.
904 BPF_STMT( BPF_LD
+ BPF_H
+ BPF_ABS
, OFFSET_OF( EthernetHeader
, DstAddr
[ 4 ] ) ),
906 // Compare to remaining 2 bytes of fake MAC address.
907 BPF_JUMP( BPF_JMP
+ BPF_JEQ
+ BPF_K
, 0x9ABC, 5, 0 ),
909 // Load 4 bytes from the destination MAC address.
910 BPF_STMT( BPF_LD
+ BPF_W
+ BPF_ABS
, OFFSET_OF( EthernetHeader
, DstAddr
[ 0 ] ) ),
912 // Compare to first 4 bytes of broadcast MAC address.
913 BPF_JUMP( BPF_JMP
+ BPF_JEQ
+ BPF_K
, 0xFFFFFFFF, 0, 2 ),
915 // Load remaining 2 bytes from the destination MAC address.
916 BPF_STMT( BPF_LD
+ BPF_H
+ BPF_ABS
, OFFSET_OF( EthernetHeader
, DstAddr
[ 4 ] ) ),
918 // Compare to remaining 2 bytes of broadcast MAC address.
919 BPF_JUMP( BPF_JMP
+ BPF_JEQ
+ BPF_K
, 0xFFFF, 1, 0 ),
922 BPF_STMT( BPF_RET
+ BPF_K
, 0 ),
924 // Receive entire packet.
925 BPF_STMT( BPF_RET
+ BPF_K
, -1 )
927 struct ifreq BoundIf
;
928 struct bpf_program BpfProgram
;
929 struct bpf_insn
* FilterProgram
;
930 UNIX_SNP_PRIVATE_DATA
* Private
;
938 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
940 switch ( Private
->Snp
.Mode
->State
)
942 case EfiSimpleNetworkStopped
:
945 case EfiSimpleNetworkStarted
:
946 case EfiSimpleNetworkInitialized
:
947 return( EFI_ALREADY_STARTED
);
951 return( EFI_DEVICE_ERROR
);
955 if ( Private
->BpfFd
== 0 )
957 Status
= OpenBpfFileDescriptor( Private
, &Fd
);
959 if ( EFI_ERROR( Status
) )
967 // Associate our interface with this BPF file descriptor.
969 AsciiStrCpy( BoundIf
.ifr_name
, Private
->InterfaceName
);
970 Result
= Private
->UnixThunk
->IoCtl( Private
->BpfFd
, BIOCSETIF
, &BoundIf
);
974 goto DeviceErrorExit
;
978 // Enable immediate mode and find out the buffer size.
981 Result
= Private
->UnixThunk
->IoCtl( Private
->BpfFd
, BIOCIMMEDIATE
, &Value
);
985 goto DeviceErrorExit
;
989 // Enable non-blocking I/O.
992 Value
= Private
->UnixThunk
->Fcntl( Private
->BpfFd
, F_GETFL
, 0 );
996 goto DeviceErrorExit
;
1001 Result
= Private
->UnixThunk
->Fcntl( Private
->BpfFd
, F_SETFL
, (void *) Value
);
1005 goto DeviceErrorExit
;
1009 // Disable "header complete" flag. This means the supplied source MAC address is
1010 // what goes on the wire.
1013 Result
= Private
->UnixThunk
->IoCtl( Private
->BpfFd
, BIOCSHDRCMPLT
, &Value
);
1017 goto DeviceErrorExit
;
1020 Result
= Private
->UnixThunk
->IoCtl( Private
->BpfFd
, BIOCGBLEN
, &Value
);
1024 goto DeviceErrorExit
;
1028 // Allocate read buffer.
1030 Private
->ReadBufferSize
= Value
;
1031 Private
->ReadBuffer
= AllocateZeroPool( Private
->ReadBufferSize
);
1032 if ( Private
->ReadBuffer
== NULL
)
1034 Status
= EFI_OUT_OF_RESOURCES
;
1038 Private
->CurrentReadPointer
= Private
->EndReadPointer
= Private
->ReadBuffer
;
1041 // Install our packet filter: successful reads should only produce broadcast or unitcast
1042 // packets directed to our fake MAC address.
1044 FilterProgram
= AllocateCopyPool( sizeof( FilterInstructionTemplate
), &FilterInstructionTemplate
);
1045 if ( FilterProgram
== NULL
)
1051 // Insert out fake MAC address into the filter. The data has to be host endian.
1053 CopyMem( &Temp32
, &Private
->Mode
.CurrentAddress
.Addr
[ 0 ], sizeof( UINT32
) );
1054 FilterProgram
[ 1 ].k
= NTOHL( Temp32
);
1055 CopyMem( &Temp16
, &Private
->Mode
.CurrentAddress
.Addr
[ 4 ], sizeof( UINT16
) );
1056 FilterProgram
[ 3 ].k
= NTOHS( Temp16
);
1058 BpfProgram
.bf_len
= sizeof( FilterInstructionTemplate
) / sizeof( struct bpf_insn
);
1059 BpfProgram
.bf_insns
= FilterProgram
;
1061 Result
= Private
->UnixThunk
->IoCtl( Private
->BpfFd
, BIOCSETF
, &BpfProgram
);
1065 goto DeviceErrorExit
;
1068 FreePool( FilterProgram
);
1071 // Enable promiscuous mode.
1074 Result
= Private
->UnixThunk
->IoCtl( Private
->BpfFd
, BIOCPROMISC
, 0 );
1078 goto DeviceErrorExit
;
1082 Private
->Snp
.Mode
->State
= EfiSimpleNetworkStarted
;
1088 Status
= EFI_DEVICE_ERROR
;
1090 if ( Private
->ReadBuffer
!= NULL
)
1092 FreePool( Private
->ReadBuffer
);
1093 Private
->ReadBuffer
= NULL
;
1100 Changes the state of a network interface from "started" to "stopped".
1102 @param This Protocol instance pointer.
1104 @retval EFI_SUCCESS Always succeeds.
1110 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
1113 UNIX_SNP_PRIVATE_DATA
* Private
= EFI_SUCCESS
;
1116 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
1118 switch ( Private
->Snp
.Mode
->State
)
1120 case EfiSimpleNetworkStarted
:
1123 case EfiSimpleNetworkStopped
:
1124 return( EFI_NOT_STARTED
);
1128 return( EFI_DEVICE_ERROR
);
1132 if ( Private
->BpfFd
!= 0 )
1134 Private
->UnixThunk
->Close( Private
->BpfFd
);
1138 if ( Private
->ReadBuffer
!= NULL
)
1140 FreePool( Private
->ReadBuffer
);
1141 Private
->CurrentReadPointer
= Private
->EndReadPointer
= Private
->ReadBuffer
= NULL
;
1144 Private
->Snp
.Mode
->State
= EfiSimpleNetworkStopped
;
1151 Resets a network adapter and allocates the transmit and receive buffers
1152 required by the network interface; optionally, also requests allocation
1153 of additional transmit and receive buffers.
1155 @param This Protocol instance pointer.
1156 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
1157 that the driver should allocate for the network interface.
1158 Some network interfaces will not be able to use the extra
1159 buffer, and the caller will not know if it is actually
1161 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
1162 that the driver should allocate for the network interface.
1163 Some network interfaces will not be able to use the extra
1164 buffer, and the caller will not know if it is actually
1167 @retval EFI_SUCCESS Always succeeds.
1173 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1174 IN UINTN ExtraRxBufferSize OPTIONAL
,
1175 IN UINTN ExtraTxBufferSize OPTIONAL
1178 UNIX_SNP_PRIVATE_DATA
* Private
= EFI_SUCCESS
;
1181 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
1183 switch ( Private
->Snp
.Mode
->State
)
1185 case EfiSimpleNetworkStarted
:
1188 case EfiSimpleNetworkStopped
:
1189 return( EFI_NOT_STARTED
);
1193 return( EFI_DEVICE_ERROR
);
1198 Status
= gBS
->CreateEvent(
1201 UnixSnpWaitForPacketNotify
,
1203 &Private
->Snp
.WaitForPacket
1207 if ( !EFI_ERROR( Status
) )
1209 Private
->Mode
.MCastFilterCount
= 0;
1210 Private
->Mode
.ReceiveFilterSetting
= 0;
1211 ZeroMem( Private
->Mode
.MCastFilter
, sizeof( Private
->Mode
.MCastFilter
) );
1213 Private
->Snp
.Mode
->State
= EfiSimpleNetworkInitialized
;
1220 Resets a network adapter and re-initializes it with the parameters that were
1221 provided in the previous call to Initialize().
1223 @param This Protocol instance pointer.
1224 @param ExtendedVerification Indicates that the driver may perform a more
1225 exhaustive verification operation of the device
1228 @retval EFI_SUCCESS Always succeeds.
1234 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1235 IN BOOLEAN ExtendedVerification
1238 UNIX_SNP_PRIVATE_DATA
* Private
;
1239 EFI_STATUS Success
= EFI_SUCCESS
;
1241 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
1243 switch ( Private
->Snp
.Mode
->State
)
1245 case EfiSimpleNetworkInitialized
:
1248 case EfiSimpleNetworkStopped
:
1249 return( EFI_NOT_STARTED
);
1253 return( EFI_DEVICE_ERROR
);
1261 Resets a network adapter and leaves it in a state that is safe for
1262 another driver to initialize.
1264 @param This Protocol instance pointer.
1266 @retval EFI_SUCCESS Always succeeds.
1272 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
1275 UNIX_SNP_PRIVATE_DATA
* Private
;
1276 EFI_STATUS Success
= EFI_SUCCESS
;
1278 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
1280 switch ( Private
->Snp
.Mode
->State
)
1282 case EfiSimpleNetworkInitialized
:
1285 case EfiSimpleNetworkStopped
:
1286 return( EFI_NOT_STARTED
);
1290 return( EFI_DEVICE_ERROR
);
1294 Private
->Snp
.Mode
->State
= EfiSimpleNetworkStarted
;
1296 Private
->Mode
.ReceiveFilterSetting
= 0;
1297 Private
->Mode
.MCastFilterCount
= 0;
1298 ZeroMem( Private
->Mode
.MCastFilter
, sizeof( Private
->Mode
.MCastFilter
) );
1300 if ( Private
->Snp
.WaitForPacket
!= NULL
)
1302 gBS
->CloseEvent( Private
->Snp
.WaitForPacket
);
1303 Private
->Snp
.WaitForPacket
= NULL
;
1306 if ( Private
->BpfFd
!= 0 )
1308 Private
->UnixThunk
->Close( Private
->BpfFd
);
1312 if ( Private
->ReadBuffer
!= NULL
)
1314 FreePool( Private
->ReadBuffer
);
1315 Private
->CurrentReadPointer
= Private
->EndReadPointer
= Private
->ReadBuffer
= NULL
;
1322 Manages the multicast receive filters of a network interface.
1324 @param This Protocol instance pointer.
1325 @param EnableBits A bit mask of receive filters to enable on the network interface.
1326 @param DisableBits A bit mask of receive filters to disable on the network interface.
1327 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
1328 filters on the network interface to their default values.
1329 @param McastFilterCount Number of multicast HW MAC addresses in the new
1330 MCastFilter list. This value must be less than or equal to
1331 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
1332 field is optional if ResetMCastFilter is TRUE.
1333 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
1334 addresses. This list will replace any existing multicast
1335 HW MAC address list. This field is optional if
1336 ResetMCastFilter is TRUE.
1338 @retval EFI_SUCCESS The multicast receive filter list was updated.
1339 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1344 UnixSnpReceiveFilters(
1345 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1346 IN UINT32 EnableBits
,
1347 IN UINT32 DisableBits
,
1348 IN BOOLEAN ResetMcastFilter
,
1349 IN UINTN McastFilterCount OPTIONAL
,
1350 IN EFI_MAC_ADDRESS
* McastFilter OPTIONAL
1353 UNIX_SNP_PRIVATE_DATA
* Private
;
1355 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
1357 // ReturnValue = GlobalData->NtNetUtilityTable.SetReceiveFilter (
1358 // Instance->InterfaceInfo.InterfaceIndex,
1360 // McastFilterCount,
1364 // For now, just succeed...
1365 return( EFI_SUCCESS
);
1369 Modifies or resets the current station address, if supported.
1371 @param This Protocol instance pointer.
1372 @param Reset Flag used to reset the station address to the network interfaces
1374 @param NewMacAddr New station address to be used for the network interface.
1376 @retval EFI_UNSUPPORTED Not supported yet.
1381 UnixSnpStationAddress(
1382 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1384 IN EFI_MAC_ADDRESS
* NewMacAddr OPTIONAL
1387 return( EFI_UNSUPPORTED
);
1391 Resets or collects the statistics on a network interface.
1393 @param This Protocol instance pointer.
1394 @param Reset Set to TRUE to reset the statistics for the network interface.
1395 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
1396 output the size, in bytes, of the resulting table of
1398 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
1399 contains the statistics.
1401 @retval EFI_SUCCESS The statistics were collected from the network interface.
1402 @retval EFI_NOT_STARTED The network interface has not been started.
1403 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
1404 size needed to hold the statistics is returned in
1406 @retval EFI_UNSUPPORTED Not supported yet.
1412 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1414 IN OUT UINTN
* StatisticsSize OPTIONAL
,
1415 OUT EFI_NETWORK_STATISTICS
* StatisticsTable OPTIONAL
1418 return( EFI_UNSUPPORTED
);
1422 Converts a multicast IP address to a multicast HW MAC address.
1424 @param This Protocol instance pointer.
1425 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
1426 to FALSE if the multicast IP address is IPv4 [RFC 791].
1427 @param Ip The multicast IP address that is to be converted to a multicast
1429 @param Mac The multicast HW MAC address that is to be generated from IP.
1431 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
1433 @retval EFI_NOT_STARTED The network interface has not been started.
1434 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
1435 size needed to hold the statistics is returned in
1437 @retval EFI_UNSUPPORTED Not supported yet.
1442 UnixSnpMcastIptoMac(
1443 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1445 IN EFI_IP_ADDRESS
* Ip
,
1446 OUT EFI_MAC_ADDRESS
* Mac
1449 return( EFI_UNSUPPORTED
);
1454 Performs read and write operations on the NVRAM device attached to a
1457 @param This Protocol instance pointer.
1458 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
1459 @param Offset Byte offset in the NVRAM device at which to start the read or
1460 write operation. This must be a multiple of NvRamAccessSize and
1461 less than NvRamSize.
1462 @param BufferSize The number of bytes to read or write from the NVRAM device.
1463 This must also be a multiple of NvramAccessSize.
1464 @param Buffer A pointer to the data buffer.
1466 @retval EFI_UNSUPPORTED Not supported yet.
1472 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1473 IN BOOLEAN ReadOrWrite
,
1475 IN UINTN BufferSize
,
1479 return( EFI_UNSUPPORTED
);
1484 Reads the current interrupt status and recycled transmit buffer status from
1485 a network interface.
1487 @param This Protocol instance pointer.
1488 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
1489 If this is NULL, the interrupt status will not be read from
1490 the device. If this is not NULL, the interrupt status will
1491 be read from the device. When the interrupt status is read,
1492 it will also be cleared. Clearing the transmit interrupt
1493 does not empty the recycled transmit buffer array.
1494 @param TxBuffer Recycled transmit buffer address. The network interface will
1495 not transmit if its internal recycled transmit buffer array
1496 is full. Reading the transmit buffer does not clear the
1497 transmit interrupt. If this is NULL, then the transmit buffer
1498 status will not be read. If there are no transmit buffers to
1499 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
1501 @retval EFI_SUCCESS Always succeeds.
1507 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1508 OUT UINT32
* InterruptStatus
,
1512 if ( TxBuffer
!= NULL
)
1514 *( ( UINT8
** ) TxBuffer
) = ( UINT8
* ) 1;
1517 if ( InterruptStatus
!= NULL
)
1519 *InterruptStatus
= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
1522 return( EFI_SUCCESS
);
1527 Places a packet in the transmit queue of a network interface.
1529 @param This Protocol instance pointer.
1530 @param HeaderSize The size, in bytes, of the media header to be filled in by
1531 the Transmit() function. If HeaderSize is non-zero, then it
1532 must be equal to This->Mode->MediaHeaderSize and the DestAddr
1533 and Protocol parameters must not be NULL.
1534 @param BufferSize The size, in bytes, of the entire packet (media header and
1535 data) to be transmitted through the network interface.
1536 @param Buffer A pointer to the packet (media header followed by data) to be
1537 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
1538 then the media header in Buffer must already be filled in by the
1539 caller. If HeaderSize is non-zero, then the media header will be
1540 filled in by the Transmit() function.
1541 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
1542 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
1543 This->Mode->CurrentAddress is used for the source HW MAC address.
1544 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
1545 parameter is ignored.
1546 @param Protocol The type of header to build. If HeaderSize is zero, then this
1547 parameter is ignored. See RFC 1700, section "Ether Types", for
1550 @retval EFI_SUCCESS The packet was placed on the transmit queue.
1551 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1552 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
1553 @retval EFI_NOT_STARTED The network interface has not been started.
1559 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1560 IN UINTN HeaderSize
,
1561 IN UINTN BufferSize
,
1563 IN EFI_MAC_ADDRESS
* SrcAddr OPTIONAL
,
1564 IN EFI_MAC_ADDRESS
* DestAddr OPTIONAL
,
1565 IN UINT16
* Protocol OPTIONAL
1568 UNIX_SNP_PRIVATE_DATA
* Private
;
1569 EthernetHeader
* EnetHeader
;
1572 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
1574 if ( This
->Mode
->State
< EfiSimpleNetworkStarted
)
1576 return( EFI_NOT_STARTED
);
1579 if ( HeaderSize
!= 0 )
1581 if ( ( DestAddr
== NULL
) || ( Protocol
== NULL
) || ( HeaderSize
!= This
->Mode
->MediaHeaderSize
) )
1583 return( EFI_INVALID_PARAMETER
);
1586 if ( SrcAddr
== NULL
)
1588 SrcAddr
= &This
->Mode
->CurrentAddress
;
1591 EnetHeader
= ( EthernetHeader
* ) Buffer
;
1593 CopyMem( EnetHeader
->DstAddr
, DestAddr
, NET_ETHER_ADDR_LEN
);
1594 CopyMem( EnetHeader
->SrcAddr
, SrcAddr
, NET_ETHER_ADDR_LEN
);
1596 EnetHeader
->Type
= HTONS( *Protocol
);
1599 Result
= Private
->UnixThunk
->Write( Private
->BpfFd
, Buffer
, BufferSize
);
1603 return( EFI_DEVICE_ERROR
);
1607 return( EFI_SUCCESS
);
1612 Receives a packet from a network interface.
1614 @param This Protocol instance pointer.
1615 @param HeaderSize The size, in bytes, of the media header received on the network
1616 interface. If this parameter is NULL, then the media header size
1617 will not be returned.
1618 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
1619 bytes, of the packet that was received on the network interface.
1620 @param Buffer A pointer to the data buffer to receive both the media header and
1622 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
1623 HW MAC source address will not be extracted from the media
1625 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
1626 the HW MAC destination address will not be extracted from the
1628 @param Protocol The media header type. If this parameter is NULL, then the
1629 protocol will not be extracted from the media header. See
1630 RFC 1700 section "Ether Types" for examples.
1632 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
1633 been updated to the number of bytes received.
1634 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
1636 @retval EFI_NOT_STARTED The network interface has not been started.
1637 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
1638 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1644 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1645 OUT UINTN
* HeaderSize OPTIONAL
,
1646 IN OUT UINTN
* BuffSize
,
1648 OUT EFI_MAC_ADDRESS
* SourceAddr OPTIONAL
,
1649 OUT EFI_MAC_ADDRESS
* DestinationAddr OPTIONAL
,
1650 OUT UINT16
* Protocol OPTIONAL
1653 UNIX_SNP_PRIVATE_DATA
* Private
;
1654 struct bpf_hdr
* BpfHeader
;
1655 EthernetHeader
* EnetHeader
;
1656 EFI_STATUS Status
= EFI_SUCCESS
;
1659 if ( This
->Mode
->State
< EfiSimpleNetworkStarted
)
1661 return( EFI_NOT_STARTED
);
1664 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( This
);
1667 // Do we have any remaining packets from the previous read?
1669 if ( Private
->CurrentReadPointer
>= Private
->EndReadPointer
)
1671 Result
= Private
->UnixThunk
->Read( Private
->BpfFd
, Private
->ReadBuffer
, Private
->ReadBufferSize
);
1675 Result
= Private
->UnixThunk
->GetErrno();
1678 // EAGAIN means that there's no I/O outstanding against this file descriptor.
1680 if ( Result
== EAGAIN
)
1682 return( EFI_NOT_READY
);
1686 return( EFI_DEVICE_ERROR
);
1692 return( EFI_NOT_READY
);
1695 Private
->CurrentReadPointer
= Private
->ReadBuffer
;
1696 Private
->EndReadPointer
= Private
->CurrentReadPointer
+ Result
;
1699 BpfHeader
= Private
->CurrentReadPointer
;
1700 EnetHeader
= Private
->CurrentReadPointer
+ BpfHeader
->bh_hdrlen
;
1702 if ( BpfHeader
->bh_caplen
> *BuffSize
)
1704 *BuffSize
= BpfHeader
->bh_caplen
;
1705 return( EFI_BUFFER_TOO_SMALL
);
1708 CopyMem( Buffer
, EnetHeader
, BpfHeader
->bh_caplen
);
1709 *BuffSize
= BpfHeader
->bh_caplen
;
1711 if ( HeaderSize
!= NULL
)
1713 *HeaderSize
= sizeof( EthernetHeader
);
1716 if ( DestinationAddr
!= NULL
)
1718 ZeroMem( DestinationAddr
, sizeof( EFI_MAC_ADDRESS
) );
1719 CopyMem( DestinationAddr
, EnetHeader
->DstAddr
, NET_ETHER_ADDR_LEN
);
1722 if ( SourceAddr
!= NULL
)
1724 ZeroMem( SourceAddr
, sizeof( EFI_MAC_ADDRESS
) );
1725 CopyMem( SourceAddr
, EnetHeader
->SrcAddr
, NET_ETHER_ADDR_LEN
);
1728 if ( Protocol
!= NULL
)
1730 *Protocol
= NTOHS( EnetHeader
->Type
);
1733 Private
->CurrentReadPointer
+= BPF_WORDALIGN( BpfHeader
->bh_hdrlen
+ BpfHeader
->bh_caplen
);
1741 UnixSnpWaitForPacketNotify(
1746 UNIX_SNP_PRIVATE_DATA
* Private
;
1748 Private
= UNIX_SNP_PRIVATE_DATA_FROM_SNP_THIS( Context
);
1750 if ( Private
->Snp
.Mode
->State
< EfiSimpleNetworkStarted
)
1758 This is the declaration of an EFI image entry point. This entry point is
1759 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1760 both device drivers and bus drivers.
1762 @param ImageHandle The firmware allocated handle for the UEFI image.
1763 @param SystemTable A pointer to the EFI System Table.
1765 @retval EFI_SUCCESS The operation completed successfully.
1766 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1770 InitializeUnixSnpDriver(
1771 IN EFI_HANDLE ImageHandle
,
1772 IN EFI_SYSTEM_TABLE
* SystemTable
1778 // Install the Driver Protocols
1781 Status
= EfiLibInstallDriverBindingComponentName2(
1784 &gUnixSnpDriverBinding
,
1786 &gUnixSnpDriverComponentName
,
1787 &gUnixSnpDriverComponentName2