3 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding
= {
23 SnpNt32DriverBindingSupported
,
24 SnpNt32DriverBindingStart
,
25 SnpNt32DriverBindingStop
,
31 SNPNT32_GLOBAL_DATA gSnpNt32GlobalData
= {
32 SNP_NT32_DRIVER_SIGNATURE
, // Signature
38 NULL
, // NetworkLibraryHandle
41 }, // NtNetUtilityTable
50 SnpNt32InitializeGlobalData
, // InitializeGlobalData
51 SnpNt32InitializeInstanceData
, // InitializeInstanceData
52 SnpNt32CloseInstance
// CloseInstance
56 Changes the state of a network interface from "stopped" to "started".
58 @param This Protocol instance pointer.
60 @retval EFI_SUCCESS Always succeeds.
66 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
70 Changes the state of a network interface from "started" to "stopped".
72 @param This Protocol instance pointer.
74 @retval EFI_SUCCESS Always succeeds.
80 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
84 Resets a network adapter and allocates the transmit and receive buffers
85 required by the network interface; optionally, also requests allocation
86 of additional transmit and receive buffers.
88 @param This Protocol instance pointer.
89 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
90 that the driver should allocate for the network interface.
91 Some network interfaces will not be able to use the extra
92 buffer, and the caller will not know if it is actually
94 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
95 that the driver should allocate for the network interface.
96 Some network interfaces will not be able to use the extra
97 buffer, and the caller will not know if it is actually
100 @retval EFI_SUCCESS Always succeeds.
106 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
107 IN UINTN ExtraRxBufferSize OPTIONAL
,
108 IN UINTN ExtraTxBufferSize OPTIONAL
112 Resets a network adapter and re-initializes it with the parameters that were
113 provided in the previous call to Initialize().
115 @param This Protocol instance pointer.
116 @param ExtendedVerification Indicates that the driver may perform a more
117 exhaustive verification operation of the device
120 @retval EFI_SUCCESS Always succeeds.
126 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
127 IN BOOLEAN ExtendedVerification
131 Resets a network adapter and leaves it in a state that is safe for
132 another driver to initialize.
134 @param This Protocol instance pointer.
136 @retval EFI_SUCCESS Always succeeds.
142 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
146 Manages the multicast receive filters of a network interface.
148 @param This Protocol instance pointer.
149 @param EnableBits A bit mask of receive filters to enable on the network interface.
150 @param DisableBits A bit mask of receive filters to disable on the network interface.
151 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
152 filters on the network interface to their default values.
153 @param McastFilterCount Number of multicast HW MAC addresses in the new
154 MCastFilter list. This value must be less than or equal to
155 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
156 field is optional if ResetMCastFilter is TRUE.
157 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
158 addresses. This list will replace any existing multicast
159 HW MAC address list. This field is optional if
160 ResetMCastFilter is TRUE.
162 @retval EFI_SUCCESS The multicast receive filter list was updated.
163 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
168 SnpNt32ReceiveFilters (
169 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
170 IN UINT32 EnableBits
,
171 IN UINT32 DisableBits
,
172 IN BOOLEAN ResetMcastFilter
,
173 IN UINTN McastFilterCount OPTIONAL
,
174 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
178 Modifies or resets the current station address, if supported.
180 @param This Protocol instance pointer.
181 @param Reset Flag used to reset the station address to the network interfaces
183 @param NewMacAddr New station address to be used for the network interface.
185 @retval EFI_UNSUPPORTED Not supported yet.
190 SnpNt32StationAddress (
191 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
193 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
197 Resets or collects the statistics on a network interface.
199 @param This Protocol instance pointer.
200 @param Reset Set to TRUE to reset the statistics for the network interface.
201 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
202 output the size, in bytes, of the resulting table of
204 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
205 contains the statistics.
207 @retval EFI_SUCCESS The statistics were collected from the network interface.
208 @retval EFI_NOT_STARTED The network interface has not been started.
209 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
210 size needed to hold the statistics is returned in
212 @retval EFI_UNSUPPORTED Not supported yet.
218 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
220 IN OUT UINTN
*StatisticsSize OPTIONAL
,
221 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
225 Converts a multicast IP address to a multicast HW MAC address.
227 @param This Protocol instance pointer.
228 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
229 to FALSE if the multicast IP address is IPv4 [RFC 791].
230 @param Ip The multicast IP address that is to be converted to a multicast
232 @param Mac The multicast HW MAC address that is to be generated from IP.
234 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
236 @retval EFI_NOT_STARTED The network interface has not been started.
237 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
238 size needed to hold the statistics is returned in
240 @retval EFI_UNSUPPORTED Not supported yet.
245 SnpNt32McastIptoMac (
246 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
248 IN EFI_IP_ADDRESS
*Ip
,
249 OUT EFI_MAC_ADDRESS
*Mac
253 Performs read and write operations on the NVRAM device attached to a
256 @param This Protocol instance pointer.
257 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
258 @param Offset Byte offset in the NVRAM device at which to start the read or
259 write operation. This must be a multiple of NvRamAccessSize and
261 @param BufferSize The number of bytes to read or write from the NVRAM device.
262 This must also be a multiple of NvramAccessSize.
263 @param Buffer A pointer to the data buffer.
265 @retval EFI_UNSUPPORTED Not supported yet.
271 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
272 IN BOOLEAN ReadOrWrite
,
279 Reads the current interrupt status and recycled transmit buffer status from
282 @param This Protocol instance pointer.
283 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
284 If this is NULL, the interrupt status will not be read from
285 the device. If this is not NULL, the interrupt status will
286 be read from the device. When the interrupt status is read,
287 it will also be cleared. Clearing the transmit interrupt
288 does not empty the recycled transmit buffer array.
289 @param TxBuffer Recycled transmit buffer address. The network interface will
290 not transmit if its internal recycled transmit buffer array
291 is full. Reading the transmit buffer does not clear the
292 transmit interrupt. If this is NULL, then the transmit buffer
293 status will not be read. If there are no transmit buffers to
294 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
296 @retval EFI_SUCCESS Always succeeds.
302 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
303 OUT UINT32
*InterruptStatus
,
308 Places a packet in the transmit queue of a network interface.
310 @param This Protocol instance pointer.
311 @param HeaderSize The size, in bytes, of the media header to be filled in by
312 the Transmit() function. If HeaderSize is non-zero, then it
313 must be equal to This->Mode->MediaHeaderSize and the DestAddr
314 and Protocol parameters must not be NULL.
315 @param BufferSize The size, in bytes, of the entire packet (media header and
316 data) to be transmitted through the network interface.
317 @param Buffer A pointer to the packet (media header followed by data) to be
318 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
319 then the media header in Buffer must already be filled in by the
320 caller. If HeaderSize is non-zero, then the media header will be
321 filled in by the Transmit() function.
322 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
323 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
324 This->Mode->CurrentAddress is used for the source HW MAC address.
325 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
326 parameter is ignored.
327 @param Protocol The type of header to build. If HeaderSize is zero, then this
328 parameter is ignored. See RFC 1700, section "Ether Types", for
331 @retval EFI_SUCCESS The packet was placed on the transmit queue.
332 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
333 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
339 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
343 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
344 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
345 IN UINT16
*Protocol OPTIONAL
349 Receives a packet from a network interface.
351 @param This Protocol instance pointer.
352 @param HeaderSize The size, in bytes, of the media header received on the network
353 interface. If this parameter is NULL, then the media header size
354 will not be returned.
355 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
356 bytes, of the packet that was received on the network interface.
357 @param Buffer A pointer to the data buffer to receive both the media header and
359 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
360 HW MAC source address will not be extracted from the media
362 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
363 the HW MAC destination address will not be extracted from the
365 @param Protocol The media header type. If this parameter is NULL, then the
366 protocol will not be extracted from the media header. See
367 RFC 1700 section "Ether Types" for examples.
369 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
370 been updated to the number of bytes received.
371 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
373 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
374 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
375 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
381 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
382 OUT UINTN
*HeaderSize
,
383 IN OUT UINTN
*BuffSize
,
385 OUT EFI_MAC_ADDRESS
*SourceAddr
,
386 OUT EFI_MAC_ADDRESS
*DestinationAddr
,
390 SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate
= {
391 SNP_NT32_INSTANCE_SIGNATURE
, // Signature
396 NULL
, // RecycledTxBuf
397 0, // RecycledTxBufCount
398 32, // MaxRecycledTxBuf
400 NULL
, // DeviceHandle
403 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
, // Revision
404 SnpNt32Start
, // Start
406 SnpNt32Initialize
, // Initialize
407 SnpNt32Reset
, // Reset
408 SnpNt32Shutdown
, // Shutdown
409 SnpNt32ReceiveFilters
, // ReceiveFilters
410 SnpNt32StationAddress
, // StationAddress
411 SnpNt32Statistics
, // Statistics
412 SnpNt32McastIptoMac
, // MCastIpToMac
413 SnpNt32Nvdata
, // NvData
414 SnpNt32GetStatus
, // GetStatus
415 SnpNt32Transmit
, // Transmit
416 SnpNt32Receive
, // Receive
417 NULL
, // WaitForPacket
421 EfiSimpleNetworkInitialized
, // State
422 NET_ETHER_ADDR_LEN
, // HwAddressSize
423 NET_ETHER_HEADER_SIZE
, // MediaHeaderSize
424 1500, // MaxPacketSize
426 0, // NvRamAccessSize
427 0, // ReceiveFilterMask
428 0, // ReceiveFilterSetting
429 MAX_MCAST_FILTER_CNT
, // MaxMCastFilterCount
430 0, // MCastFilterCount
439 }, // BroadcastAddress
442 }, // PermanentAddress
443 NET_IFTYPE_ETHERNET
, // IfType
444 FALSE
, // MacAddressChangeable
445 FALSE
, // MultipleTxSupported
446 TRUE
, // MediaPresentSupported
455 Test to see if this driver supports ControllerHandle. This service
456 is called by the EFI boot service ConnectController(). In
457 order to make drivers as small as possible, there are a few calling
458 restrictions for this service. ConnectController() must
459 follow these calling restrictions. If any other agent wishes to call
460 Supported() it must also follow these calling restrictions.
462 @param This Protocol instance pointer.
463 @param ControllerHandle Handle of device to test
464 @param RemainingDevicePath Optional parameter use to pick a specific child
467 @retval EFI_SUCCESS This driver supports this device
468 @retval EFI_UNSUPPORTED This driver does not support this device
473 SnpNt32DriverBindingSupported (
474 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
475 IN EFI_HANDLE ControllerHandle
,
476 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
480 SNPNT32_GLOBAL_DATA
*GlobalData
;
482 SNPNT32_INSTANCE_DATA
*Instance
;
484 GlobalData
= &gSnpNt32GlobalData
;
486 NET_LIST_FOR_EACH (Entry
, &GlobalData
->InstanceList
) {
488 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
490 if (Instance
->DeviceHandle
== ControllerHandle
) {
496 return EFI_UNSUPPORTED
;
501 Start this driver on ControllerHandle. This service is called by the
502 EFI boot service ConnectController(). In order to make
503 drivers as small as possible, there are a few calling restrictions for
504 this service. ConnectController() must follow these
505 calling restrictions. If any other agent wishes to call Start() it
506 must also follow these calling restrictions.
508 @param This Protocol instance pointer.
509 @param ControllerHandle Handle of device to bind driver to
510 @param RemainingDevicePath Optional parameter use to pick a specific child
513 @retval EFI_SUCCESS Always succeeds.
518 SnpNt32DriverBindingStart (
519 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
520 IN EFI_HANDLE ControllerHandle
,
521 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
528 Stop this driver on ControllerHandle. This service is called by the
529 EFI boot service DisconnectController(). In order to
530 make drivers as small as possible, there are a few calling
531 restrictions for this service. DisconnectController()
532 must follow these calling restrictions. If any other agent wishes
533 to call Stop() it must also follow these calling restrictions.
535 @param This Protocol instance pointer.
536 @param ControllerHandle Handle of device to stop driver on
537 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
538 children is zero stop the entire bus driver.
539 @param ChildHandleBuffer List of Child Handles to Stop.
541 @retval EFI_SUCCESS Always succeeds.
546 SnpNt32DriverBindingStop (
547 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
548 IN EFI_HANDLE ControllerHandle
,
549 IN UINTN NumberOfChildren
,
550 IN EFI_HANDLE
*ChildHandleBuffer
558 Changes the state of a network interface from "stopped" to "started".
560 @param This Protocol instance pointer.
562 @retval EFI_SUCCESS Always succeeds.
568 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
576 Changes the state of a network interface from "started" to "stopped".
578 @param This Protocol instance pointer.
580 @retval EFI_SUCCESS Always succeeds.
586 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
593 Resets a network adapter and allocates the transmit and receive buffers
594 required by the network interface; optionally, also requests allocation
595 of additional transmit and receive buffers.
597 @param This Protocol instance pointer.
598 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
599 that the driver should allocate for the network interface.
600 Some network interfaces will not be able to use the extra
601 buffer, and the caller will not know if it is actually
603 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
604 that the driver should allocate for the network interface.
605 Some network interfaces will not be able to use the extra
606 buffer, and the caller will not know if it is actually
609 @retval EFI_SUCCESS Always succeeds.
615 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
616 IN UINTN ExtraRxBufferSize OPTIONAL
,
617 IN UINTN ExtraTxBufferSize OPTIONAL
624 Resets a network adapter and re-initializes it with the parameters that were
625 provided in the previous call to Initialize().
627 @param This Protocol instance pointer.
628 @param ExtendedVerification Indicates that the driver may perform a more
629 exhaustive verification operation of the device
632 @retval EFI_SUCCESS Always succeeds.
638 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
639 IN BOOLEAN ExtendedVerification
646 Resets a network adapter and leaves it in a state that is safe for
647 another driver to initialize.
649 @param This Protocol instance pointer.
651 @retval EFI_SUCCESS Always succeeds.
657 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
664 Manages the multicast receive filters of a network interface.
666 @param This Protocol instance pointer.
667 @param EnableBits A bit mask of receive filters to enable on the network interface.
668 @param DisableBits A bit mask of receive filters to disable on the network interface.
669 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
670 filters on the network interface to their default values.
671 @param McastFilterCount Number of multicast HW MAC addresses in the new
672 MCastFilter list. This value must be less than or equal to
673 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
674 field is optional if ResetMCastFilter is TRUE.
675 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
676 addresses. This list will replace any existing multicast
677 HW MAC address list. This field is optional if
678 ResetMCastFilter is TRUE.
680 @retval EFI_SUCCESS The multicast receive filter list was updated.
681 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
686 SnpNt32ReceiveFilters (
687 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
688 IN UINT32 EnableBits
,
689 IN UINT32 DisableBits
,
690 IN BOOLEAN ResetMcastFilter
,
691 IN UINTN McastFilterCount OPTIONAL
,
692 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
695 SNPNT32_INSTANCE_DATA
*Instance
;
696 SNPNT32_GLOBAL_DATA
*GlobalData
;
699 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
701 GlobalData
= Instance
->GlobalData
;
703 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
704 return EFI_ACCESS_DENIED
;
707 ReturnValue
= GlobalData
->NtNetUtilityTable
.SetReceiveFilter (
708 Instance
->InterfaceInfo
.InterfaceIndex
,
710 (UINT32
)McastFilterCount
,
714 EfiReleaseLock (&GlobalData
->Lock
);
716 if (ReturnValue
<= 0) {
717 return EFI_DEVICE_ERROR
;
724 Modifies or resets the current station address, if supported.
726 @param This Protocol instance pointer.
727 @param Reset Flag used to reset the station address to the network interfaces
729 @param NewMacAddr New station address to be used for the network interface.
731 @retval EFI_UNSUPPORTED Not supported yet.
736 SnpNt32StationAddress (
737 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
739 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
742 return EFI_UNSUPPORTED
;
746 Resets or collects the statistics on a network interface.
748 @param This Protocol instance pointer.
749 @param Reset Set to TRUE to reset the statistics for the network interface.
750 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
751 output the size, in bytes, of the resulting table of
753 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
754 contains the statistics.
756 @retval EFI_SUCCESS The statistics were collected from the network interface.
757 @retval EFI_NOT_STARTED The network interface has not been started.
758 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
759 size needed to hold the statistics is returned in
761 @retval EFI_UNSUPPORTED Not supported yet.
767 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
769 IN OUT UINTN
*StatisticsSize OPTIONAL
,
770 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
773 return EFI_UNSUPPORTED
;
777 Converts a multicast IP address to a multicast HW MAC address.
779 @param This Protocol instance pointer.
780 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
781 to FALSE if the multicast IP address is IPv4 [RFC 791].
782 @param Ip The multicast IP address that is to be converted to a multicast
784 @param Mac The multicast HW MAC address that is to be generated from IP.
786 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
788 @retval EFI_NOT_STARTED The network interface has not been started.
789 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
790 size needed to hold the statistics is returned in
792 @retval EFI_UNSUPPORTED Not supported yet.
797 SnpNt32McastIptoMac (
798 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
800 IN EFI_IP_ADDRESS
*Ip
,
801 OUT EFI_MAC_ADDRESS
*Mac
804 return EFI_UNSUPPORTED
;
809 Performs read and write operations on the NVRAM device attached to a
812 @param This Protocol instance pointer.
813 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
814 @param Offset Byte offset in the NVRAM device at which to start the read or
815 write operation. This must be a multiple of NvRamAccessSize and
817 @param BufferSize The number of bytes to read or write from the NVRAM device.
818 This must also be a multiple of NvramAccessSize.
819 @param Buffer A pointer to the data buffer.
821 @retval EFI_UNSUPPORTED Not supported yet.
827 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
828 IN BOOLEAN ReadOrWrite
,
834 return EFI_UNSUPPORTED
;
839 Reads the current interrupt status and recycled transmit buffer status from
842 @param This Protocol instance pointer.
843 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
844 If this is NULL, the interrupt status will not be read from
845 the device. If this is not NULL, the interrupt status will
846 be read from the device. When the interrupt status is read,
847 it will also be cleared. Clearing the transmit interrupt
848 does not empty the recycled transmit buffer array.
849 @param TxBuffer Recycled transmit buffer address. The network interface will
850 not transmit if its internal recycled transmit buffer array
851 is full. Reading the transmit buffer does not clear the
852 transmit interrupt. If this is NULL, then the transmit buffer
853 status will not be read. If there are no transmit buffers to
854 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
856 @retval EFI_SUCCESS Always succeeds.
862 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
863 OUT UINT32
*InterruptStatus
,
867 SNPNT32_INSTANCE_DATA
*Instance
;
869 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
871 if (TxBuffer
!= NULL
) {
872 if (Instance
->RecycledTxBufCount
!= 0) {
873 Instance
->RecycledTxBufCount
--;
874 *((UINT8
**) TxBuffer
) = (UINT8
*) (UINTN
)Instance
->RecycledTxBuf
[Instance
->RecycledTxBufCount
];
876 *((UINT8
**) TxBuffer
) = NULL
;
880 if (InterruptStatus
!= NULL
) {
881 *InterruptStatus
= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
889 Places a packet in the transmit queue of a network interface.
891 @param This Protocol instance pointer.
892 @param HeaderSize The size, in bytes, of the media header to be filled in by
893 the Transmit() function. If HeaderSize is non-zero, then it
894 must be equal to This->Mode->MediaHeaderSize and the DestAddr
895 and Protocol parameters must not be NULL.
896 @param BufferSize The size, in bytes, of the entire packet (media header and
897 data) to be transmitted through the network interface.
898 @param Buffer A pointer to the packet (media header followed by data) to be
899 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
900 then the media header in Buffer must already be filled in by the
901 caller. If HeaderSize is non-zero, then the media header will be
902 filled in by the Transmit() function.
903 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
904 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
905 This->Mode->CurrentAddress is used for the source HW MAC address.
906 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
907 parameter is ignored.
908 @param Protocol The type of header to build. If HeaderSize is zero, then this
909 parameter is ignored. See RFC 1700, section "Ether Types", for
912 @retval EFI_SUCCESS The packet was placed on the transmit queue.
913 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
914 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
920 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
924 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
925 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
926 IN UINT16
*Protocol OPTIONAL
929 SNPNT32_INSTANCE_DATA
*Instance
;
930 SNPNT32_GLOBAL_DATA
*GlobalData
;
934 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
936 GlobalData
= Instance
->GlobalData
;
938 if ((HeaderSize
!= 0) && (SrcAddr
== NULL
)) {
939 SrcAddr
= &Instance
->Mode
.CurrentAddress
;
942 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
943 return EFI_ACCESS_DENIED
;
946 ReturnValue
= GlobalData
->NtNetUtilityTable
.Transmit (
947 Instance
->InterfaceInfo
.InterfaceIndex
,
956 EfiReleaseLock (&GlobalData
->Lock
);
958 if (ReturnValue
< 0) {
959 return EFI_DEVICE_ERROR
;
961 if ((Instance
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
) >= SNP_MAX_TX_BUFFER_NUM
) {
962 return EFI_NOT_READY
;
965 if (Instance
->RecycledTxBufCount
< Instance
->MaxRecycledTxBuf
) {
966 Instance
->RecycledTxBuf
[Instance
->RecycledTxBufCount
] = (UINT64
) Buffer
;
967 Instance
->RecycledTxBufCount
++;
969 Tmp
= AllocatePool (sizeof (UINT64
) * (Instance
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
));
971 return EFI_DEVICE_ERROR
;
973 CopyMem (Tmp
, Instance
->RecycledTxBuf
, sizeof (UINT64
) * Instance
->RecycledTxBufCount
);
974 FreePool (Instance
->RecycledTxBuf
);
975 Instance
->RecycledTxBuf
= Tmp
;
976 Instance
->MaxRecycledTxBuf
+= SNP_TX_BUFFER_INCREASEMENT
;
984 Receives a packet from a network interface.
986 @param This Protocol instance pointer.
987 @param HeaderSize The size, in bytes, of the media header received on the network
988 interface. If this parameter is NULL, then the media header size
989 will not be returned.
990 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
991 bytes, of the packet that was received on the network interface.
992 @param Buffer A pointer to the data buffer to receive both the media header and
994 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
995 HW MAC source address will not be extracted from the media
997 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
998 the HW MAC destination address will not be extracted from the
1000 @param Protocol The media header type. If this parameter is NULL, then the
1001 protocol will not be extracted from the media header. See
1002 RFC 1700 section "Ether Types" for examples.
1004 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
1005 been updated to the number of bytes received.
1006 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
1008 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
1009 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1010 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
1016 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
1017 OUT UINTN
*HeaderSize
,
1018 IN OUT UINTN
*BuffSize
,
1020 OUT EFI_MAC_ADDRESS
*SourceAddr
,
1021 OUT EFI_MAC_ADDRESS
*DestinationAddr
,
1022 OUT UINT16
*Protocol
1025 SNPNT32_INSTANCE_DATA
*Instance
;
1026 SNPNT32_GLOBAL_DATA
*GlobalData
;
1030 BufSize
= *BuffSize
;
1032 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
1034 GlobalData
= Instance
->GlobalData
;
1036 ASSERT (GlobalData
->NtNetUtilityTable
.Receive
!= NULL
);
1038 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
1039 return EFI_ACCESS_DENIED
;
1042 ReturnValue
= GlobalData
->NtNetUtilityTable
.Receive (
1043 Instance
->InterfaceInfo
.InterfaceIndex
,
1048 EfiReleaseLock (&GlobalData
->Lock
);
1050 if (ReturnValue
< 0) {
1051 if (ReturnValue
== -100) {
1052 return EFI_BUFFER_TOO_SMALL
;
1055 return EFI_DEVICE_ERROR
;
1056 } else if (ReturnValue
== 0) {
1057 return EFI_NOT_READY
;
1060 if (HeaderSize
!= NULL
) {
1064 if (SourceAddr
!= NULL
) {
1065 ZeroMem (SourceAddr
, sizeof (EFI_MAC_ADDRESS
));
1066 CopyMem (SourceAddr
, ((UINT8
*) Buffer
) + 6, 6);
1069 if (DestinationAddr
!= NULL
) {
1070 ZeroMem (DestinationAddr
, sizeof (EFI_MAC_ADDRESS
));
1071 CopyMem (DestinationAddr
, ((UINT8
*) Buffer
), 6);
1074 if (Protocol
!= NULL
) {
1075 *Protocol
= NTOHS (*((UINT16
*) (((UINT8
*) Buffer
) + 12)));
1078 return (*BuffSize
<= BufSize
) ? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
1082 Initialize the driver's global data.
1084 @param This Pointer to the global context data.
1086 @retval EFI_SUCCESS The global data is initialized.
1087 @retval EFI_NOT_FOUND The required DLL is not found.
1088 @retval EFI_DEVICE_ERROR Error initialize network utility library.
1089 @retval EFI_OUT_OF_RESOURCES Out of resource.
1090 @retval other Other errors.
1094 SnpNt32InitializeGlobalData (
1095 IN OUT SNPNT32_GLOBAL_DATA
*This
1099 CHAR16
*DllFileNameU
;
1102 BOOLEAN NetUtilityLibInitDone
;
1103 NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer
[MAX_INTERFACE_INFO_NUMBER
];
1104 SNPNT32_INSTANCE_DATA
*Instance
;
1106 UINT32 InterfaceCount
;
1108 ASSERT (This
!= NULL
);
1110 NetUtilityLibInitDone
= FALSE
;
1111 InterfaceCount
= MAX_INTERFACE_INFO_NUMBER
;
1113 InitializeListHead (&This
->InstanceList
);
1114 EfiInitializeLock (&This
->Lock
, TPL_CALLBACK
);
1117 // Get the WinNT thunk
1119 Status
= gBS
->LocateProtocol (&gEfiWinNtThunkProtocolGuid
, NULL
, (VOID
**)&This
->WinNtThunk
);
1121 if (EFI_ERROR (Status
)) {
1125 ASSERT (This
->WinNtThunk
!= NULL
);
1127 DllFileNameU
= NETWORK_LIBRARY_NAME_U
;
1130 // Load network utility library
1132 This
->NetworkLibraryHandle
= This
->WinNtThunk
->LoadLibraryEx (DllFileNameU
, NULL
, 0);
1134 if (NULL
== This
->NetworkLibraryHandle
) {
1135 return EFI_NOT_FOUND
;
1138 This
->NtNetUtilityTable
.Initialize
= (NT_NET_INITIALIZE
) This
->WinNtThunk
->GetProcAddress (
1139 This
->NetworkLibraryHandle
,
1140 NETWORK_LIBRARY_INITIALIZE
1143 if (NULL
== This
->NtNetUtilityTable
.Initialize
) {
1144 Status
= EFI_NOT_FOUND
;
1148 This
->NtNetUtilityTable
.Finalize
= (NT_NET_FINALIZE
) This
->WinNtThunk
->GetProcAddress (
1149 This
->NetworkLibraryHandle
,
1150 NETWORK_LIBRARY_FINALIZE
1153 if (NULL
== This
->NtNetUtilityTable
.Finalize
) {
1154 Status
= EFI_NOT_FOUND
;
1158 This
->NtNetUtilityTable
.SetReceiveFilter
= (NT_NET_SET_RECEIVE_FILTER
) This
->WinNtThunk
->GetProcAddress (
1159 This
->NetworkLibraryHandle
,
1160 NETWORK_LIBRARY_SET_RCV_FILTER
1163 if (NULL
== This
->NtNetUtilityTable
.SetReceiveFilter
) {
1164 Status
= EFI_NOT_FOUND
;
1168 This
->NtNetUtilityTable
.Receive
= (NT_NET_RECEIVE
) This
->WinNtThunk
->GetProcAddress (
1169 This
->NetworkLibraryHandle
,
1170 NETWORK_LIBRARY_RECEIVE
1173 if (NULL
== This
->NtNetUtilityTable
.Receive
) {
1174 Status
= EFI_NOT_FOUND
;
1178 This
->NtNetUtilityTable
.Transmit
= (NT_NET_TRANSMIT
) This
->WinNtThunk
->GetProcAddress (
1179 This
->NetworkLibraryHandle
,
1180 NETWORK_LIBRARY_TRANSMIT
1183 if (NULL
== This
->NtNetUtilityTable
.Transmit
) {
1184 Status
= EFI_NOT_FOUND
;
1188 // Initialize the network utility library
1189 // And enumerate the interfaces in NT32 host
1191 ReturnValue
= This
->NtNetUtilityTable
.Initialize (&InterfaceCount
, &NetInterfaceInfoBuffer
[0]);
1192 if (ReturnValue
<= 0) {
1193 Status
= EFI_DEVICE_ERROR
;
1197 NetUtilityLibInitDone
= TRUE
;
1199 if (InterfaceCount
== 0) {
1200 Status
= EFI_NOT_FOUND
;
1204 // Create fake SNP instances
1206 for (Index
= 0; Index
< InterfaceCount
; Index
++) {
1208 Instance
= AllocateZeroPool (sizeof (SNPNT32_INSTANCE_DATA
));
1210 if (NULL
== Instance
) {
1211 Status
= EFI_OUT_OF_RESOURCES
;
1215 // Copy the content from a template
1217 CopyMem (Instance
, &gSnpNt32InstanceTemplate
, sizeof (SNPNT32_INSTANCE_DATA
));
1220 // Allocate the RecycledTxBuf.
1222 Instance
->RecycledTxBuf
= AllocatePool (sizeof (UINT64
) * Instance
->MaxRecycledTxBuf
);
1223 if (Instance
->RecycledTxBuf
== NULL
) {
1224 return EFI_OUT_OF_RESOURCES
;
1228 // Set the interface information.
1230 CopyMem (&Instance
->InterfaceInfo
, &NetInterfaceInfoBuffer
[Index
], sizeof(Instance
->InterfaceInfo
));
1232 // Initialize this instance
1234 Status
= This
->InitializeInstanceData (This
, Instance
);
1235 if (EFI_ERROR (Status
)) {
1237 gBS
->FreePool (Instance
);
1241 // Insert this instance into the instance list
1243 InsertTailList (&This
->InstanceList
, &Instance
->Entry
);
1250 while (!IsListEmpty (&This
->InstanceList
)) {
1252 Entry
= This
->InstanceList
.ForwardLink
;
1254 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
1256 RemoveEntryList (Entry
);
1258 This
->CloseInstance (This
, Instance
);
1259 gBS
->FreePool (Instance
);
1262 if (NetUtilityLibInitDone
) {
1264 ASSERT (This
->WinNtThunk
!= NULL
);
1266 if (This
->NtNetUtilityTable
.Finalize
!= NULL
) {
1267 This
->NtNetUtilityTable
.Finalize ();
1268 This
->NtNetUtilityTable
.Finalize
= NULL
;
1277 Initialize the snpnt32 driver instance.
1279 @param This Pointer to the SnpNt32 global data.
1280 @param Instance Pointer to the instance context data.
1282 @retval EFI_SUCCESS The driver instance is initialized.
1283 @retval other Initialization errors.
1287 SnpNt32InitializeInstanceData (
1288 IN SNPNT32_GLOBAL_DATA
*This
,
1289 IN OUT SNPNT32_INSTANCE_DATA
*Instance
1293 EFI_DEV_PATH EndNode
;
1296 Instance
->GlobalData
= This
;
1297 Instance
->Snp
.Mode
= &Instance
->Mode
;
1299 // Set broadcast address
1301 SetMem (&Instance
->Mode
.BroadcastAddress
, sizeof (EFI_MAC_ADDRESS
), 0xFF);
1304 // Copy Current/PermanentAddress MAC address
1306 CopyMem (&Instance
->Mode
.CurrentAddress
, &Instance
->InterfaceInfo
.MacAddr
, sizeof(Instance
->Mode
.CurrentAddress
));
1307 CopyMem (&Instance
->Mode
.PermanentAddress
, &Instance
->InterfaceInfo
.MacAddr
, sizeof(Instance
->Mode
.PermanentAddress
));
1310 // Since the fake SNP is based on a real NIC, to avoid conflict with the host
1311 // NIC network stack, we use a different MAC address.
1312 // So just change the last byte of the MAC address for the real NIC.
1314 Instance
->Mode
.CurrentAddress
.Addr
[NET_ETHER_ADDR_LEN
- 1]++;
1317 // Create a fake device path for the instance
1319 ZeroMem (&Node
, sizeof (Node
));
1321 Node
.DevPath
.Type
= MESSAGING_DEVICE_PATH
;
1322 Node
.DevPath
.SubType
= MSG_MAC_ADDR_DP
;
1323 SetDevicePathNodeLength (&Node
.DevPath
, sizeof (MAC_ADDR_DEVICE_PATH
));
1326 &Node
.MacAddr
.MacAddress
,
1327 &Instance
->Mode
.CurrentAddress
,
1331 Node
.MacAddr
.IfType
= Instance
->Mode
.IfType
;
1333 SetDevicePathEndNode (&EndNode
.DevPath
);
1335 Instance
->DevicePath
= AppendDevicePathNode (
1341 // Create a fake device handle for the fake SNP
1343 Status
= gBS
->InstallMultipleProtocolInterfaces (
1344 &Instance
->DeviceHandle
,
1345 &gEfiSimpleNetworkProtocolGuid
,
1347 &gEfiDevicePathProtocolGuid
,
1348 Instance
->DevicePath
,
1356 Close the SnpNt32 driver instance.
1358 @param This Pointer to the SnpNt32 global data.
1359 @param Instance Pointer to the instance context data.
1361 @retval EFI_SUCCESS The instance is closed.
1365 SnpNt32CloseInstance (
1366 IN SNPNT32_GLOBAL_DATA
*This
,
1367 IN OUT SNPNT32_INSTANCE_DATA
*Instance
1370 ASSERT (This
!= NULL
);
1371 ASSERT (Instance
!= NULL
);
1373 gBS
->UninstallMultipleProtocolInterfaces (
1374 Instance
->DeviceHandle
,
1375 &gEfiSimpleNetworkProtocolGuid
,
1377 &gEfiDevicePathProtocolGuid
,
1378 Instance
->DevicePath
,
1382 if (Instance
->DevicePath
!= NULL
) {
1383 gBS
->FreePool (Instance
->DevicePath
);
1392 @param ImageHandle Handle that identifies the image to be unloaded.
1394 @retval EFI_SUCCESS The image has been unloaded.
1395 @return Exit code from the image's unload handler
1401 IN EFI_HANDLE ImageHandle
1405 SNPNT32_GLOBAL_DATA
*This
;
1407 SNPNT32_INSTANCE_DATA
*Instance
;
1409 This
= &gSnpNt32GlobalData
;
1411 Status
= NetLibDefaultUnload (ImageHandle
);
1413 if (EFI_ERROR (Status
)) {
1417 while (!IsListEmpty (&This
->InstanceList
)) {
1419 // Walkthrough the interfaces and remove all the SNP instance
1421 Entry
= This
->InstanceList
.ForwardLink
;
1423 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
1425 RemoveEntryList (Entry
);
1427 This
->CloseInstance (This
, Instance
);
1428 gBS
->FreePool (Instance
);
1431 if (This
->NtNetUtilityTable
.Finalize
!= NULL
) {
1432 This
->NtNetUtilityTable
.Finalize ();
1435 This
->WinNtThunk
->FreeLibrary (This
->NetworkLibraryHandle
);
1441 This is the declaration of an EFI image entry point. This entry point is
1442 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1443 both device drivers and bus drivers.
1445 @param ImageHandle The firmware allocated handle for the UEFI image.
1446 @param SystemTable A pointer to the EFI System Table.
1448 @retval EFI_SUCCESS The operation completed successfully.
1449 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1453 InitializeSnpNt32Driver (
1454 IN EFI_HANDLE ImageHandle
,
1455 IN EFI_SYSTEM_TABLE
*SystemTable
1462 // Install the Driver Protocols
1465 Status
= EfiLibInstallDriverBindingComponentName2 (
1468 &gSnpNt32DriverBinding
,
1470 &gSnpNt32DriverComponentName
,
1471 &gSnpNt32DriverComponentName2
1473 if (EFI_ERROR (Status
)) {
1478 // Initialize the global data
1480 Status
= SnpNt32InitializeGlobalData (&gSnpNt32GlobalData
);
1481 if (EFI_ERROR (Status
)) {
1482 SnpNt32Unload (ImageHandle
);