3 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
16 EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding
= {
17 SnpNt32DriverBindingSupported
,
18 SnpNt32DriverBindingStart
,
19 SnpNt32DriverBindingStop
,
25 SNPNT32_GLOBAL_DATA gSnpNt32GlobalData
= {
26 SNP_NT32_DRIVER_SIGNATURE
, // Signature
32 NULL
, // NetworkLibraryHandle
35 }, // NtNetUtilityTable
44 SnpNt32InitializeGlobalData
, // InitializeGlobalData
45 SnpNt32InitializeInstanceData
, // InitializeInstanceData
46 SnpNt32CloseInstance
// CloseInstance
50 Changes the state of a network interface from "stopped" to "started".
52 @param This Protocol instance pointer.
54 @retval EFI_SUCCESS Always succeeds.
60 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
64 Changes the state of a network interface from "started" to "stopped".
66 @param This Protocol instance pointer.
68 @retval EFI_SUCCESS Always succeeds.
74 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
78 Resets a network adapter and allocates the transmit and receive buffers
79 required by the network interface; optionally, also requests allocation
80 of additional transmit and receive buffers.
82 @param This Protocol instance pointer.
83 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
84 that the driver should allocate for the network interface.
85 Some network interfaces will not be able to use the extra
86 buffer, and the caller will not know if it is actually
88 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
89 that the driver should allocate for the network interface.
90 Some network interfaces will not be able to use the extra
91 buffer, and the caller will not know if it is actually
94 @retval EFI_SUCCESS Always succeeds.
100 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
101 IN UINTN ExtraRxBufferSize OPTIONAL
,
102 IN UINTN ExtraTxBufferSize OPTIONAL
106 Resets a network adapter and re-initializes it with the parameters that were
107 provided in the previous call to Initialize().
109 @param This Protocol instance pointer.
110 @param ExtendedVerification Indicates that the driver may perform a more
111 exhaustive verification operation of the device
114 @retval EFI_SUCCESS Always succeeds.
120 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
121 IN BOOLEAN ExtendedVerification
125 Resets a network adapter and leaves it in a state that is safe for
126 another driver to initialize.
128 @param This Protocol instance pointer.
130 @retval EFI_SUCCESS Always succeeds.
136 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
140 Manages the multicast receive filters of a network interface.
142 @param This Protocol instance pointer.
143 @param EnableBits A bit mask of receive filters to enable on the network interface.
144 @param DisableBits A bit mask of receive filters to disable on the network interface.
145 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
146 filters on the network interface to their default values.
147 @param McastFilterCount Number of multicast HW MAC addresses in the new
148 MCastFilter list. This value must be less than or equal to
149 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
150 field is optional if ResetMCastFilter is TRUE.
151 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
152 addresses. This list will replace any existing multicast
153 HW MAC address list. This field is optional if
154 ResetMCastFilter is TRUE.
156 @retval EFI_SUCCESS The multicast receive filter list was updated.
157 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
162 SnpNt32ReceiveFilters (
163 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
164 IN UINT32 EnableBits
,
165 IN UINT32 DisableBits
,
166 IN BOOLEAN ResetMcastFilter
,
167 IN UINTN McastFilterCount OPTIONAL
,
168 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
172 Modifies or resets the current station address, if supported.
174 @param This Protocol instance pointer.
175 @param Reset Flag used to reset the station address to the network interfaces
177 @param NewMacAddr New station address to be used for the network interface.
179 @retval EFI_UNSUPPORTED Not supported yet.
184 SnpNt32StationAddress (
185 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
187 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
191 Resets or collects the statistics on a network interface.
193 @param This Protocol instance pointer.
194 @param Reset Set to TRUE to reset the statistics for the network interface.
195 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
196 output the size, in bytes, of the resulting table of
198 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
199 contains the statistics.
201 @retval EFI_SUCCESS The statistics were collected from the network interface.
202 @retval EFI_NOT_STARTED The network interface has not been started.
203 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
204 size needed to hold the statistics is returned in
206 @retval EFI_UNSUPPORTED Not supported yet.
212 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
214 IN OUT UINTN
*StatisticsSize OPTIONAL
,
215 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
219 Converts a multicast IP address to a multicast HW MAC address.
221 @param This Protocol instance pointer.
222 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
223 to FALSE if the multicast IP address is IPv4 [RFC 791].
224 @param Ip The multicast IP address that is to be converted to a multicast
226 @param Mac The multicast HW MAC address that is to be generated from IP.
228 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
230 @retval EFI_NOT_STARTED The network interface has not been started.
231 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
232 size needed to hold the statistics is returned in
234 @retval EFI_UNSUPPORTED Not supported yet.
239 SnpNt32McastIptoMac (
240 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
242 IN EFI_IP_ADDRESS
*Ip
,
243 OUT EFI_MAC_ADDRESS
*Mac
247 Performs read and write operations on the NVRAM device attached to a
250 @param This Protocol instance pointer.
251 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
252 @param Offset Byte offset in the NVRAM device at which to start the read or
253 write operation. This must be a multiple of NvRamAccessSize and
255 @param BufferSize The number of bytes to read or write from the NVRAM device.
256 This must also be a multiple of NvramAccessSize.
257 @param Buffer A pointer to the data buffer.
259 @retval EFI_UNSUPPORTED Not supported yet.
265 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
266 IN BOOLEAN ReadOrWrite
,
273 Reads the current interrupt status and recycled transmit buffer status from
276 @param This Protocol instance pointer.
277 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
278 If this is NULL, the interrupt status will not be read from
279 the device. If this is not NULL, the interrupt status will
280 be read from the device. When the interrupt status is read,
281 it will also be cleared. Clearing the transmit interrupt
282 does not empty the recycled transmit buffer array.
283 @param TxBuffer Recycled transmit buffer address. The network interface will
284 not transmit if its internal recycled transmit buffer array
285 is full. Reading the transmit buffer does not clear the
286 transmit interrupt. If this is NULL, then the transmit buffer
287 status will not be read. If there are no transmit buffers to
288 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
290 @retval EFI_SUCCESS Always succeeds.
296 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
297 OUT UINT32
*InterruptStatus
,
302 Places a packet in the transmit queue of a network interface.
304 @param This Protocol instance pointer.
305 @param HeaderSize The size, in bytes, of the media header to be filled in by
306 the Transmit() function. If HeaderSize is non-zero, then it
307 must be equal to This->Mode->MediaHeaderSize and the DestAddr
308 and Protocol parameters must not be NULL.
309 @param BufferSize The size, in bytes, of the entire packet (media header and
310 data) to be transmitted through the network interface.
311 @param Buffer A pointer to the packet (media header followed by data) to be
312 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
313 then the media header in Buffer must already be filled in by the
314 caller. If HeaderSize is non-zero, then the media header will be
315 filled in by the Transmit() function.
316 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
317 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
318 This->Mode->CurrentAddress is used for the source HW MAC address.
319 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
320 parameter is ignored.
321 @param Protocol The type of header to build. If HeaderSize is zero, then this
322 parameter is ignored. See RFC 1700, section "Ether Types", for
325 @retval EFI_SUCCESS The packet was placed on the transmit queue.
326 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
327 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
333 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
337 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
338 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
339 IN UINT16
*Protocol OPTIONAL
343 Receives a packet from a network interface.
345 @param This Protocol instance pointer.
346 @param HeaderSize The size, in bytes, of the media header received on the network
347 interface. If this parameter is NULL, then the media header size
348 will not be returned.
349 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
350 bytes, of the packet that was received on the network interface.
351 @param Buffer A pointer to the data buffer to receive both the media header and
353 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
354 HW MAC source address will not be extracted from the media
356 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
357 the HW MAC destination address will not be extracted from the
359 @param Protocol The media header type. If this parameter is NULL, then the
360 protocol will not be extracted from the media header. See
361 RFC 1700 section "Ether Types" for examples.
363 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
364 been updated to the number of bytes received.
365 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
367 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
368 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
369 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
375 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
376 OUT UINTN
*HeaderSize
,
377 IN OUT UINTN
*BuffSize
,
379 OUT EFI_MAC_ADDRESS
*SourceAddr
,
380 OUT EFI_MAC_ADDRESS
*DestinationAddr
,
384 SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate
= {
385 SNP_NT32_INSTANCE_SIGNATURE
, // Signature
390 NULL
, // RecycledTxBuf
391 0, // RecycledTxBufCount
392 32, // MaxRecycledTxBuf
394 NULL
, // DeviceHandle
397 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
, // Revision
398 SnpNt32Start
, // Start
400 SnpNt32Initialize
, // Initialize
401 SnpNt32Reset
, // Reset
402 SnpNt32Shutdown
, // Shutdown
403 SnpNt32ReceiveFilters
, // ReceiveFilters
404 SnpNt32StationAddress
, // StationAddress
405 SnpNt32Statistics
, // Statistics
406 SnpNt32McastIptoMac
, // MCastIpToMac
407 SnpNt32Nvdata
, // NvData
408 SnpNt32GetStatus
, // GetStatus
409 SnpNt32Transmit
, // Transmit
410 SnpNt32Receive
, // Receive
411 NULL
, // WaitForPacket
415 EfiSimpleNetworkInitialized
, // State
416 NET_ETHER_ADDR_LEN
, // HwAddressSize
417 NET_ETHER_HEADER_SIZE
, // MediaHeaderSize
418 1500, // MaxPacketSize
420 0, // NvRamAccessSize
421 0, // ReceiveFilterMask
422 0, // ReceiveFilterSetting
423 MAX_MCAST_FILTER_CNT
, // MaxMCastFilterCount
424 0, // MCastFilterCount
433 }, // BroadcastAddress
436 }, // PermanentAddress
437 NET_IFTYPE_ETHERNET
, // IfType
438 FALSE
, // MacAddressChangeable
439 FALSE
, // MultipleTxSupported
440 TRUE
, // MediaPresentSupported
449 Test to see if this driver supports ControllerHandle. This service
450 is called by the EFI boot service ConnectController(). In
451 order to make drivers as small as possible, there are a few calling
452 restrictions for this service. ConnectController() must
453 follow these calling restrictions. If any other agent wishes to call
454 Supported() it must also follow these calling restrictions.
456 @param This Protocol instance pointer.
457 @param ControllerHandle Handle of device to test
458 @param RemainingDevicePath Optional parameter use to pick a specific child
461 @retval EFI_SUCCESS This driver supports this device
462 @retval EFI_UNSUPPORTED This driver does not support this device
467 SnpNt32DriverBindingSupported (
468 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
469 IN EFI_HANDLE ControllerHandle
,
470 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
474 SNPNT32_GLOBAL_DATA
*GlobalData
;
476 SNPNT32_INSTANCE_DATA
*Instance
;
478 GlobalData
= &gSnpNt32GlobalData
;
480 NET_LIST_FOR_EACH (Entry
, &GlobalData
->InstanceList
) {
482 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
484 if (Instance
->DeviceHandle
== ControllerHandle
) {
490 return EFI_UNSUPPORTED
;
495 Start this driver on ControllerHandle. This service is called by the
496 EFI boot service ConnectController(). In order to make
497 drivers as small as possible, there are a few calling restrictions for
498 this service. ConnectController() must follow these
499 calling restrictions. If any other agent wishes to call Start() it
500 must also follow these calling restrictions.
502 @param This Protocol instance pointer.
503 @param ControllerHandle Handle of device to bind driver to
504 @param RemainingDevicePath Optional parameter use to pick a specific child
507 @retval EFI_SUCCESS Always succeeds.
512 SnpNt32DriverBindingStart (
513 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
514 IN EFI_HANDLE ControllerHandle
,
515 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
522 Stop this driver on ControllerHandle. This service is called by the
523 EFI boot service DisconnectController(). In order to
524 make drivers as small as possible, there are a few calling
525 restrictions for this service. DisconnectController()
526 must follow these calling restrictions. If any other agent wishes
527 to call Stop() it must also follow these calling restrictions.
529 @param This Protocol instance pointer.
530 @param ControllerHandle Handle of device to stop driver on
531 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
532 children is zero stop the entire bus driver.
533 @param ChildHandleBuffer List of Child Handles to Stop.
535 @retval EFI_SUCCESS Always succeeds.
540 SnpNt32DriverBindingStop (
541 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
542 IN EFI_HANDLE ControllerHandle
,
543 IN UINTN NumberOfChildren
,
544 IN EFI_HANDLE
*ChildHandleBuffer
552 Changes the state of a network interface from "stopped" to "started".
554 @param This Protocol instance pointer.
556 @retval EFI_SUCCESS Always succeeds.
562 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
570 Changes the state of a network interface from "started" to "stopped".
572 @param This Protocol instance pointer.
574 @retval EFI_SUCCESS Always succeeds.
580 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
587 Resets a network adapter and allocates the transmit and receive buffers
588 required by the network interface; optionally, also requests allocation
589 of additional transmit and receive buffers.
591 @param This Protocol instance pointer.
592 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
593 that the driver should allocate for the network interface.
594 Some network interfaces will not be able to use the extra
595 buffer, and the caller will not know if it is actually
597 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
598 that the driver should allocate for the network interface.
599 Some network interfaces will not be able to use the extra
600 buffer, and the caller will not know if it is actually
603 @retval EFI_SUCCESS Always succeeds.
609 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
610 IN UINTN ExtraRxBufferSize OPTIONAL
,
611 IN UINTN ExtraTxBufferSize OPTIONAL
618 Resets a network adapter and re-initializes it with the parameters that were
619 provided in the previous call to Initialize().
621 @param This Protocol instance pointer.
622 @param ExtendedVerification Indicates that the driver may perform a more
623 exhaustive verification operation of the device
626 @retval EFI_SUCCESS Always succeeds.
632 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
633 IN BOOLEAN ExtendedVerification
640 Resets a network adapter and leaves it in a state that is safe for
641 another driver to initialize.
643 @param This Protocol instance pointer.
645 @retval EFI_SUCCESS Always succeeds.
651 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
658 Manages the multicast receive filters of a network interface.
660 @param This Protocol instance pointer.
661 @param EnableBits A bit mask of receive filters to enable on the network interface.
662 @param DisableBits A bit mask of receive filters to disable on the network interface.
663 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
664 filters on the network interface to their default values.
665 @param McastFilterCount Number of multicast HW MAC addresses in the new
666 MCastFilter list. This value must be less than or equal to
667 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
668 field is optional if ResetMCastFilter is TRUE.
669 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
670 addresses. This list will replace any existing multicast
671 HW MAC address list. This field is optional if
672 ResetMCastFilter is TRUE.
674 @retval EFI_SUCCESS The multicast receive filter list was updated.
675 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
680 SnpNt32ReceiveFilters (
681 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
682 IN UINT32 EnableBits
,
683 IN UINT32 DisableBits
,
684 IN BOOLEAN ResetMcastFilter
,
685 IN UINTN McastFilterCount OPTIONAL
,
686 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
689 SNPNT32_INSTANCE_DATA
*Instance
;
690 SNPNT32_GLOBAL_DATA
*GlobalData
;
693 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
695 GlobalData
= Instance
->GlobalData
;
697 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
698 return EFI_ACCESS_DENIED
;
701 ReturnValue
= GlobalData
->NtNetUtilityTable
.SetReceiveFilter (
702 Instance
->InterfaceInfo
.InterfaceIndex
,
704 (UINT32
)McastFilterCount
,
708 EfiReleaseLock (&GlobalData
->Lock
);
710 if (ReturnValue
<= 0) {
711 return EFI_DEVICE_ERROR
;
718 Modifies or resets the current station address, if supported.
720 @param This Protocol instance pointer.
721 @param Reset Flag used to reset the station address to the network interfaces
723 @param NewMacAddr New station address to be used for the network interface.
725 @retval EFI_UNSUPPORTED Not supported yet.
730 SnpNt32StationAddress (
731 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
733 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
736 return EFI_UNSUPPORTED
;
740 Resets or collects the statistics on a network interface.
742 @param This Protocol instance pointer.
743 @param Reset Set to TRUE to reset the statistics for the network interface.
744 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
745 output the size, in bytes, of the resulting table of
747 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
748 contains the statistics.
750 @retval EFI_SUCCESS The statistics were collected from the network interface.
751 @retval EFI_NOT_STARTED The network interface has not been started.
752 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
753 size needed to hold the statistics is returned in
755 @retval EFI_UNSUPPORTED Not supported yet.
761 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
763 IN OUT UINTN
*StatisticsSize OPTIONAL
,
764 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
767 return EFI_UNSUPPORTED
;
771 Converts a multicast IP address to a multicast HW MAC address.
773 @param This Protocol instance pointer.
774 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
775 to FALSE if the multicast IP address is IPv4 [RFC 791].
776 @param Ip The multicast IP address that is to be converted to a multicast
778 @param Mac The multicast HW MAC address that is to be generated from IP.
780 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
782 @retval EFI_NOT_STARTED The network interface has not been started.
783 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
784 size needed to hold the statistics is returned in
786 @retval EFI_UNSUPPORTED Not supported yet.
791 SnpNt32McastIptoMac (
792 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
794 IN EFI_IP_ADDRESS
*Ip
,
795 OUT EFI_MAC_ADDRESS
*Mac
798 return EFI_UNSUPPORTED
;
803 Performs read and write operations on the NVRAM device attached to a
806 @param This Protocol instance pointer.
807 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
808 @param Offset Byte offset in the NVRAM device at which to start the read or
809 write operation. This must be a multiple of NvRamAccessSize and
811 @param BufferSize The number of bytes to read or write from the NVRAM device.
812 This must also be a multiple of NvramAccessSize.
813 @param Buffer A pointer to the data buffer.
815 @retval EFI_UNSUPPORTED Not supported yet.
821 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
822 IN BOOLEAN ReadOrWrite
,
828 return EFI_UNSUPPORTED
;
833 Reads the current interrupt status and recycled transmit buffer status from
836 @param This Protocol instance pointer.
837 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
838 If this is NULL, the interrupt status will not be read from
839 the device. If this is not NULL, the interrupt status will
840 be read from the device. When the interrupt status is read,
841 it will also be cleared. Clearing the transmit interrupt
842 does not empty the recycled transmit buffer array.
843 @param TxBuffer Recycled transmit buffer address. The network interface will
844 not transmit if its internal recycled transmit buffer array
845 is full. Reading the transmit buffer does not clear the
846 transmit interrupt. If this is NULL, then the transmit buffer
847 status will not be read. If there are no transmit buffers to
848 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
850 @retval EFI_SUCCESS Always succeeds.
856 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
857 OUT UINT32
*InterruptStatus
,
861 SNPNT32_INSTANCE_DATA
*Instance
;
863 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
865 if (TxBuffer
!= NULL
) {
866 if (Instance
->RecycledTxBufCount
!= 0) {
867 Instance
->RecycledTxBufCount
--;
868 *((UINT8
**) TxBuffer
) = (UINT8
*) (UINTN
)Instance
->RecycledTxBuf
[Instance
->RecycledTxBufCount
];
870 *((UINT8
**) TxBuffer
) = NULL
;
874 if (InterruptStatus
!= NULL
) {
875 *InterruptStatus
= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
883 Places a packet in the transmit queue of a network interface.
885 @param This Protocol instance pointer.
886 @param HeaderSize The size, in bytes, of the media header to be filled in by
887 the Transmit() function. If HeaderSize is non-zero, then it
888 must be equal to This->Mode->MediaHeaderSize and the DestAddr
889 and Protocol parameters must not be NULL.
890 @param BufferSize The size, in bytes, of the entire packet (media header and
891 data) to be transmitted through the network interface.
892 @param Buffer A pointer to the packet (media header followed by data) to be
893 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
894 then the media header in Buffer must already be filled in by the
895 caller. If HeaderSize is non-zero, then the media header will be
896 filled in by the Transmit() function.
897 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
898 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
899 This->Mode->CurrentAddress is used for the source HW MAC address.
900 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
901 parameter is ignored.
902 @param Protocol The type of header to build. If HeaderSize is zero, then this
903 parameter is ignored. See RFC 1700, section "Ether Types", for
906 @retval EFI_SUCCESS The packet was placed on the transmit queue.
907 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
908 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
914 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
918 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
919 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
920 IN UINT16
*Protocol OPTIONAL
923 SNPNT32_INSTANCE_DATA
*Instance
;
924 SNPNT32_GLOBAL_DATA
*GlobalData
;
928 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
930 GlobalData
= Instance
->GlobalData
;
932 if ((HeaderSize
!= 0) && (SrcAddr
== NULL
)) {
933 SrcAddr
= &Instance
->Mode
.CurrentAddress
;
936 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
937 return EFI_ACCESS_DENIED
;
940 ReturnValue
= GlobalData
->NtNetUtilityTable
.Transmit (
941 Instance
->InterfaceInfo
.InterfaceIndex
,
950 EfiReleaseLock (&GlobalData
->Lock
);
952 if (ReturnValue
< 0) {
953 return EFI_DEVICE_ERROR
;
955 if ((Instance
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
) >= SNP_MAX_TX_BUFFER_NUM
) {
956 return EFI_NOT_READY
;
959 if (Instance
->RecycledTxBufCount
< Instance
->MaxRecycledTxBuf
) {
960 Instance
->RecycledTxBuf
[Instance
->RecycledTxBufCount
] = (UINT64
) Buffer
;
961 Instance
->RecycledTxBufCount
++;
963 Tmp
= AllocatePool (sizeof (UINT64
) * (Instance
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
));
965 return EFI_DEVICE_ERROR
;
967 CopyMem (Tmp
, Instance
->RecycledTxBuf
, sizeof (UINT64
) * Instance
->RecycledTxBufCount
);
968 FreePool (Instance
->RecycledTxBuf
);
969 Instance
->RecycledTxBuf
= Tmp
;
970 Instance
->MaxRecycledTxBuf
+= SNP_TX_BUFFER_INCREASEMENT
;
978 Receives a packet from a network interface.
980 @param This Protocol instance pointer.
981 @param HeaderSize The size, in bytes, of the media header received on the network
982 interface. If this parameter is NULL, then the media header size
983 will not be returned.
984 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
985 bytes, of the packet that was received on the network interface.
986 @param Buffer A pointer to the data buffer to receive both the media header and
988 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
989 HW MAC source address will not be extracted from the media
991 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
992 the HW MAC destination address will not be extracted from the
994 @param Protocol The media header type. If this parameter is NULL, then the
995 protocol will not be extracted from the media header. See
996 RFC 1700 section "Ether Types" for examples.
998 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
999 been updated to the number of bytes received.
1000 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
1002 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
1003 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1004 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
1010 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
1011 OUT UINTN
*HeaderSize
,
1012 IN OUT UINTN
*BuffSize
,
1014 OUT EFI_MAC_ADDRESS
*SourceAddr
,
1015 OUT EFI_MAC_ADDRESS
*DestinationAddr
,
1016 OUT UINT16
*Protocol
1019 SNPNT32_INSTANCE_DATA
*Instance
;
1020 SNPNT32_GLOBAL_DATA
*GlobalData
;
1024 BufSize
= *BuffSize
;
1026 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
1028 GlobalData
= Instance
->GlobalData
;
1030 ASSERT (GlobalData
->NtNetUtilityTable
.Receive
!= NULL
);
1032 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
1033 return EFI_ACCESS_DENIED
;
1036 ReturnValue
= GlobalData
->NtNetUtilityTable
.Receive (
1037 Instance
->InterfaceInfo
.InterfaceIndex
,
1042 EfiReleaseLock (&GlobalData
->Lock
);
1044 if (ReturnValue
< 0) {
1045 if (ReturnValue
== -100) {
1046 return EFI_BUFFER_TOO_SMALL
;
1049 return EFI_DEVICE_ERROR
;
1050 } else if (ReturnValue
== 0) {
1051 return EFI_NOT_READY
;
1054 if (HeaderSize
!= NULL
) {
1058 if (SourceAddr
!= NULL
) {
1059 ZeroMem (SourceAddr
, sizeof (EFI_MAC_ADDRESS
));
1060 CopyMem (SourceAddr
, ((UINT8
*) Buffer
) + 6, 6);
1063 if (DestinationAddr
!= NULL
) {
1064 ZeroMem (DestinationAddr
, sizeof (EFI_MAC_ADDRESS
));
1065 CopyMem (DestinationAddr
, ((UINT8
*) Buffer
), 6);
1068 if (Protocol
!= NULL
) {
1069 *Protocol
= NTOHS (*((UINT16
*) (((UINT8
*) Buffer
) + 12)));
1072 return (*BuffSize
<= BufSize
) ? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
1076 Initialize the driver's global data.
1078 @param This Pointer to the global context data.
1080 @retval EFI_SUCCESS The global data is initialized.
1081 @retval EFI_NOT_FOUND The required DLL is not found.
1082 @retval EFI_DEVICE_ERROR Error initialize network utility library.
1083 @retval EFI_OUT_OF_RESOURCES Out of resource.
1084 @retval other Other errors.
1088 SnpNt32InitializeGlobalData (
1089 IN OUT SNPNT32_GLOBAL_DATA
*This
1093 CHAR16
*DllFileNameU
;
1096 BOOLEAN NetUtilityLibInitDone
;
1097 NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer
[MAX_INTERFACE_INFO_NUMBER
];
1098 SNPNT32_INSTANCE_DATA
*Instance
;
1100 UINT32 InterfaceCount
;
1102 ASSERT (This
!= NULL
);
1104 NetUtilityLibInitDone
= FALSE
;
1105 InterfaceCount
= MAX_INTERFACE_INFO_NUMBER
;
1107 InitializeListHead (&This
->InstanceList
);
1108 EfiInitializeLock (&This
->Lock
, TPL_CALLBACK
);
1111 // Get the WinNT thunk
1113 Status
= gBS
->LocateProtocol (&gEfiWinNtThunkProtocolGuid
, NULL
, (VOID
**)&This
->WinNtThunk
);
1115 if (EFI_ERROR (Status
)) {
1119 ASSERT (This
->WinNtThunk
!= NULL
);
1121 DllFileNameU
= NETWORK_LIBRARY_NAME_U
;
1124 // Load network utility library
1126 This
->NetworkLibraryHandle
= This
->WinNtThunk
->LoadLibraryEx (DllFileNameU
, NULL
, 0);
1128 if (NULL
== This
->NetworkLibraryHandle
) {
1129 return EFI_NOT_FOUND
;
1132 This
->NtNetUtilityTable
.Initialize
= (NT_NET_INITIALIZE
) This
->WinNtThunk
->GetProcAddress (
1133 This
->NetworkLibraryHandle
,
1134 NETWORK_LIBRARY_INITIALIZE
1137 if (NULL
== This
->NtNetUtilityTable
.Initialize
) {
1138 Status
= EFI_NOT_FOUND
;
1142 This
->NtNetUtilityTable
.Finalize
= (NT_NET_FINALIZE
) This
->WinNtThunk
->GetProcAddress (
1143 This
->NetworkLibraryHandle
,
1144 NETWORK_LIBRARY_FINALIZE
1147 if (NULL
== This
->NtNetUtilityTable
.Finalize
) {
1148 Status
= EFI_NOT_FOUND
;
1152 This
->NtNetUtilityTable
.SetReceiveFilter
= (NT_NET_SET_RECEIVE_FILTER
) This
->WinNtThunk
->GetProcAddress (
1153 This
->NetworkLibraryHandle
,
1154 NETWORK_LIBRARY_SET_RCV_FILTER
1157 if (NULL
== This
->NtNetUtilityTable
.SetReceiveFilter
) {
1158 Status
= EFI_NOT_FOUND
;
1162 This
->NtNetUtilityTable
.Receive
= (NT_NET_RECEIVE
) This
->WinNtThunk
->GetProcAddress (
1163 This
->NetworkLibraryHandle
,
1164 NETWORK_LIBRARY_RECEIVE
1167 if (NULL
== This
->NtNetUtilityTable
.Receive
) {
1168 Status
= EFI_NOT_FOUND
;
1172 This
->NtNetUtilityTable
.Transmit
= (NT_NET_TRANSMIT
) This
->WinNtThunk
->GetProcAddress (
1173 This
->NetworkLibraryHandle
,
1174 NETWORK_LIBRARY_TRANSMIT
1177 if (NULL
== This
->NtNetUtilityTable
.Transmit
) {
1178 Status
= EFI_NOT_FOUND
;
1182 // Initialize the network utility library
1183 // And enumerate the interfaces in NT32 host
1185 ReturnValue
= This
->NtNetUtilityTable
.Initialize (&InterfaceCount
, &NetInterfaceInfoBuffer
[0]);
1186 if (ReturnValue
<= 0) {
1187 Status
= EFI_DEVICE_ERROR
;
1191 NetUtilityLibInitDone
= TRUE
;
1193 if (InterfaceCount
== 0) {
1194 Status
= EFI_NOT_FOUND
;
1198 // Create fake SNP instances
1200 for (Index
= 0; Index
< InterfaceCount
; Index
++) {
1202 Instance
= AllocateZeroPool (sizeof (SNPNT32_INSTANCE_DATA
));
1204 if (NULL
== Instance
) {
1205 Status
= EFI_OUT_OF_RESOURCES
;
1209 // Copy the content from a template
1211 CopyMem (Instance
, &gSnpNt32InstanceTemplate
, sizeof (SNPNT32_INSTANCE_DATA
));
1214 // Allocate the RecycledTxBuf.
1216 Instance
->RecycledTxBuf
= AllocatePool (sizeof (UINT64
) * Instance
->MaxRecycledTxBuf
);
1217 if (Instance
->RecycledTxBuf
== NULL
) {
1218 return EFI_OUT_OF_RESOURCES
;
1222 // Set the interface information.
1224 CopyMem (&Instance
->InterfaceInfo
, &NetInterfaceInfoBuffer
[Index
], sizeof(Instance
->InterfaceInfo
));
1226 // Initialize this instance
1228 Status
= This
->InitializeInstanceData (This
, Instance
);
1229 if (EFI_ERROR (Status
)) {
1231 gBS
->FreePool (Instance
);
1235 // Insert this instance into the instance list
1237 InsertTailList (&This
->InstanceList
, &Instance
->Entry
);
1244 while (!IsListEmpty (&This
->InstanceList
)) {
1246 Entry
= This
->InstanceList
.ForwardLink
;
1248 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
1250 RemoveEntryList (Entry
);
1252 This
->CloseInstance (This
, Instance
);
1253 gBS
->FreePool (Instance
);
1256 if (NetUtilityLibInitDone
) {
1258 ASSERT (This
->WinNtThunk
!= NULL
);
1260 if (This
->NtNetUtilityTable
.Finalize
!= NULL
) {
1261 This
->NtNetUtilityTable
.Finalize ();
1262 This
->NtNetUtilityTable
.Finalize
= NULL
;
1271 Initialize the snpnt32 driver instance.
1273 @param This Pointer to the SnpNt32 global data.
1274 @param Instance Pointer to the instance context data.
1276 @retval EFI_SUCCESS The driver instance is initialized.
1277 @retval other Initialization errors.
1281 SnpNt32InitializeInstanceData (
1282 IN SNPNT32_GLOBAL_DATA
*This
,
1283 IN OUT SNPNT32_INSTANCE_DATA
*Instance
1287 EFI_DEV_PATH EndNode
;
1290 Instance
->GlobalData
= This
;
1291 Instance
->Snp
.Mode
= &Instance
->Mode
;
1293 // Set broadcast address
1295 SetMem (&Instance
->Mode
.BroadcastAddress
, sizeof (EFI_MAC_ADDRESS
), 0xFF);
1298 // Copy Current/PermanentAddress MAC address
1300 CopyMem (&Instance
->Mode
.CurrentAddress
, &Instance
->InterfaceInfo
.MacAddr
, sizeof(Instance
->Mode
.CurrentAddress
));
1301 CopyMem (&Instance
->Mode
.PermanentAddress
, &Instance
->InterfaceInfo
.MacAddr
, sizeof(Instance
->Mode
.PermanentAddress
));
1304 // Since the fake SNP is based on a real NIC, to avoid conflict with the host
1305 // NIC network stack, we use a different MAC address.
1306 // So just change the last byte of the MAC address for the real NIC.
1308 Instance
->Mode
.CurrentAddress
.Addr
[NET_ETHER_ADDR_LEN
- 1]++;
1311 // Create a fake device path for the instance
1313 ZeroMem (&Node
, sizeof (Node
));
1315 Node
.DevPath
.Type
= MESSAGING_DEVICE_PATH
;
1316 Node
.DevPath
.SubType
= MSG_MAC_ADDR_DP
;
1317 SetDevicePathNodeLength (&Node
.DevPath
, sizeof (MAC_ADDR_DEVICE_PATH
));
1320 &Node
.MacAddr
.MacAddress
,
1321 &Instance
->Mode
.CurrentAddress
,
1325 Node
.MacAddr
.IfType
= Instance
->Mode
.IfType
;
1327 SetDevicePathEndNode (&EndNode
.DevPath
);
1329 Instance
->DevicePath
= AppendDevicePathNode (
1335 // Create a fake device handle for the fake SNP
1337 Status
= gBS
->InstallMultipleProtocolInterfaces (
1338 &Instance
->DeviceHandle
,
1339 &gEfiSimpleNetworkProtocolGuid
,
1341 &gEfiDevicePathProtocolGuid
,
1342 Instance
->DevicePath
,
1350 Close the SnpNt32 driver instance.
1352 @param This Pointer to the SnpNt32 global data.
1353 @param Instance Pointer to the instance context data.
1355 @retval EFI_SUCCESS The instance is closed.
1359 SnpNt32CloseInstance (
1360 IN SNPNT32_GLOBAL_DATA
*This
,
1361 IN OUT SNPNT32_INSTANCE_DATA
*Instance
1364 ASSERT (This
!= NULL
);
1365 ASSERT (Instance
!= NULL
);
1367 gBS
->UninstallMultipleProtocolInterfaces (
1368 Instance
->DeviceHandle
,
1369 &gEfiSimpleNetworkProtocolGuid
,
1371 &gEfiDevicePathProtocolGuid
,
1372 Instance
->DevicePath
,
1376 if (Instance
->DevicePath
!= NULL
) {
1377 gBS
->FreePool (Instance
->DevicePath
);
1386 @param ImageHandle Handle that identifies the image to be unloaded.
1388 @retval EFI_SUCCESS The image has been unloaded.
1389 @return Exit code from the image's unload handler
1395 IN EFI_HANDLE ImageHandle
1399 SNPNT32_GLOBAL_DATA
*This
;
1401 SNPNT32_INSTANCE_DATA
*Instance
;
1403 This
= &gSnpNt32GlobalData
;
1405 Status
= NetLibDefaultUnload (ImageHandle
);
1407 if (EFI_ERROR (Status
)) {
1411 while (!IsListEmpty (&This
->InstanceList
)) {
1413 // Walkthrough the interfaces and remove all the SNP instance
1415 Entry
= This
->InstanceList
.ForwardLink
;
1417 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
1419 RemoveEntryList (Entry
);
1421 This
->CloseInstance (This
, Instance
);
1422 gBS
->FreePool (Instance
);
1425 if (This
->NtNetUtilityTable
.Finalize
!= NULL
) {
1426 This
->NtNetUtilityTable
.Finalize ();
1429 This
->WinNtThunk
->FreeLibrary (This
->NetworkLibraryHandle
);
1435 This is the declaration of an EFI image entry point. This entry point is
1436 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1437 both device drivers and bus drivers.
1439 @param ImageHandle The firmware allocated handle for the UEFI image.
1440 @param SystemTable A pointer to the EFI System Table.
1442 @retval EFI_SUCCESS The operation completed successfully.
1443 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1447 InitializeSnpNt32Driver (
1448 IN EFI_HANDLE ImageHandle
,
1449 IN EFI_SYSTEM_TABLE
*SystemTable
1456 // Install the Driver Protocols
1459 Status
= EfiLibInstallDriverBindingComponentName2 (
1462 &gSnpNt32DriverBinding
,
1464 &gSnpNt32DriverComponentName
,
1465 &gSnpNt32DriverComponentName2
1467 if (EFI_ERROR (Status
)) {
1472 // Initialize the global data
1474 Status
= SnpNt32InitializeGlobalData (&gSnpNt32GlobalData
);
1475 if (EFI_ERROR (Status
)) {
1476 SnpNt32Unload (ImageHandle
);