3 Copyright (c) 2006 - 2016, 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
47 NULL
, // RecycledTxBuf
48 0, // RecycledTxBufCount
49 32, // MaxRecycledTxBuf
53 SnpNt32InitializeGlobalData
, // InitializeGlobalData
54 SnpNt32InitializeInstanceData
, // InitializeInstanceData
55 SnpNt32CloseInstance
// CloseInstance
59 Changes the state of a network interface from "stopped" to "started".
61 @param This Protocol instance pointer.
63 @retval EFI_SUCCESS Always succeeds.
69 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
73 Changes the state of a network interface from "started" to "stopped".
75 @param This Protocol instance pointer.
77 @retval EFI_SUCCESS Always succeeds.
83 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
87 Resets a network adapter and allocates the transmit and receive buffers
88 required by the network interface; optionally, also requests allocation
89 of additional transmit and receive buffers.
91 @param This Protocol instance pointer.
92 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
93 that the driver should allocate for the network interface.
94 Some network interfaces will not be able to use the extra
95 buffer, and the caller will not know if it is actually
97 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
98 that the driver should allocate for the network interface.
99 Some network interfaces will not be able to use the extra
100 buffer, and the caller will not know if it is actually
103 @retval EFI_SUCCESS Always succeeds.
109 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
110 IN UINTN ExtraRxBufferSize OPTIONAL
,
111 IN UINTN ExtraTxBufferSize OPTIONAL
115 Resets a network adapter and re-initializes it with the parameters that were
116 provided in the previous call to Initialize().
118 @param This Protocol instance pointer.
119 @param ExtendedVerification Indicates that the driver may perform a more
120 exhaustive verification operation of the device
123 @retval EFI_SUCCESS Always succeeds.
129 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
130 IN BOOLEAN ExtendedVerification
134 Resets a network adapter and leaves it in a state that is safe for
135 another driver to initialize.
137 @param This Protocol instance pointer.
139 @retval EFI_SUCCESS Always succeeds.
145 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
149 Manages the multicast receive filters of a network interface.
151 @param This Protocol instance pointer.
152 @param EnableBits A bit mask of receive filters to enable on the network interface.
153 @param DisableBits A bit mask of receive filters to disable on the network interface.
154 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
155 filters on the network interface to their default values.
156 @param McastFilterCount Number of multicast HW MAC addresses in the new
157 MCastFilter list. This value must be less than or equal to
158 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
159 field is optional if ResetMCastFilter is TRUE.
160 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
161 addresses. This list will replace any existing multicast
162 HW MAC address list. This field is optional if
163 ResetMCastFilter is TRUE.
165 @retval EFI_SUCCESS The multicast receive filter list was updated.
166 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
171 SnpNt32ReceiveFilters (
172 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
173 IN UINT32 EnableBits
,
174 IN UINT32 DisableBits
,
175 IN BOOLEAN ResetMcastFilter
,
176 IN UINTN McastFilterCount OPTIONAL
,
177 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
181 Modifies or resets the current station address, if supported.
183 @param This Protocol instance pointer.
184 @param Reset Flag used to reset the station address to the network interfaces
186 @param NewMacAddr New station address to be used for the network interface.
188 @retval EFI_UNSUPPORTED Not supported yet.
193 SnpNt32StationAddress (
194 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
196 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
200 Resets or collects the statistics on a network interface.
202 @param This Protocol instance pointer.
203 @param Reset Set to TRUE to reset the statistics for the network interface.
204 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
205 output the size, in bytes, of the resulting table of
207 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
208 contains the statistics.
210 @retval EFI_SUCCESS The statistics were collected from the network interface.
211 @retval EFI_NOT_STARTED The network interface has not been started.
212 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
213 size needed to hold the statistics is returned in
215 @retval EFI_UNSUPPORTED Not supported yet.
221 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
223 IN OUT UINTN
*StatisticsSize OPTIONAL
,
224 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
228 Converts a multicast IP address to a multicast HW MAC address.
230 @param This Protocol instance pointer.
231 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
232 to FALSE if the multicast IP address is IPv4 [RFC 791].
233 @param Ip The multicast IP address that is to be converted to a multicast
235 @param Mac The multicast HW MAC address that is to be generated from IP.
237 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
239 @retval EFI_NOT_STARTED The network interface has not been started.
240 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
241 size needed to hold the statistics is returned in
243 @retval EFI_UNSUPPORTED Not supported yet.
248 SnpNt32McastIptoMac (
249 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
251 IN EFI_IP_ADDRESS
*Ip
,
252 OUT EFI_MAC_ADDRESS
*Mac
256 Performs read and write operations on the NVRAM device attached to a
259 @param This Protocol instance pointer.
260 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
261 @param Offset Byte offset in the NVRAM device at which to start the read or
262 write operation. This must be a multiple of NvRamAccessSize and
264 @param BufferSize The number of bytes to read or write from the NVRAM device.
265 This must also be a multiple of NvramAccessSize.
266 @param Buffer A pointer to the data buffer.
268 @retval EFI_UNSUPPORTED Not supported yet.
274 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
275 IN BOOLEAN ReadOrWrite
,
282 Reads the current interrupt status and recycled transmit buffer status from
285 @param This Protocol instance pointer.
286 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
287 If this is NULL, the interrupt status will not be read from
288 the device. If this is not NULL, the interrupt status will
289 be read from the device. When the interrupt status is read,
290 it will also be cleared. Clearing the transmit interrupt
291 does not empty the recycled transmit buffer array.
292 @param TxBuffer Recycled transmit buffer address. The network interface will
293 not transmit if its internal recycled transmit buffer array
294 is full. Reading the transmit buffer does not clear the
295 transmit interrupt. If this is NULL, then the transmit buffer
296 status will not be read. If there are no transmit buffers to
297 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
299 @retval EFI_SUCCESS Always succeeds.
305 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
306 OUT UINT32
*InterruptStatus
,
311 Places a packet in the transmit queue of a network interface.
313 @param This Protocol instance pointer.
314 @param HeaderSize The size, in bytes, of the media header to be filled in by
315 the Transmit() function. If HeaderSize is non-zero, then it
316 must be equal to This->Mode->MediaHeaderSize and the DestAddr
317 and Protocol parameters must not be NULL.
318 @param BufferSize The size, in bytes, of the entire packet (media header and
319 data) to be transmitted through the network interface.
320 @param Buffer A pointer to the packet (media header followed by data) to be
321 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
322 then the media header in Buffer must already be filled in by the
323 caller. If HeaderSize is non-zero, then the media header will be
324 filled in by the Transmit() function.
325 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
326 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
327 This->Mode->CurrentAddress is used for the source HW MAC address.
328 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
329 parameter is ignored.
330 @param Protocol The type of header to build. If HeaderSize is zero, then this
331 parameter is ignored. See RFC 1700, section "Ether Types", for
334 @retval EFI_SUCCESS The packet was placed on the transmit queue.
335 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
336 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
342 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
346 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
347 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
348 IN UINT16
*Protocol OPTIONAL
352 Receives a packet from a network interface.
354 @param This Protocol instance pointer.
355 @param HeaderSize The size, in bytes, of the media header received on the network
356 interface. If this parameter is NULL, then the media header size
357 will not be returned.
358 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
359 bytes, of the packet that was received on the network interface.
360 @param Buffer A pointer to the data buffer to receive both the media header and
362 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
363 HW MAC source address will not be extracted from the media
365 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
366 the HW MAC destination address will not be extracted from the
368 @param Protocol The media header type. If this parameter is NULL, then the
369 protocol will not be extracted from the media header. See
370 RFC 1700 section "Ether Types" for examples.
372 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
373 been updated to the number of bytes received.
374 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
376 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
377 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
378 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
384 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
385 OUT UINTN
*HeaderSize
,
386 IN OUT UINTN
*BuffSize
,
388 OUT EFI_MAC_ADDRESS
*SourceAddr
,
389 OUT EFI_MAC_ADDRESS
*DestinationAddr
,
393 SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate
= {
394 SNP_NT32_INSTANCE_SIGNATURE
, // Signature
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
;
868 SNPNT32_GLOBAL_DATA
*GlobalData
;
870 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
872 GlobalData
= Instance
->GlobalData
;
874 if (TxBuffer
!= NULL
) {
875 if (GlobalData
->RecycledTxBufCount
!= 0) {
876 GlobalData
->RecycledTxBufCount
--;
877 *((UINT8
**) TxBuffer
) = (UINT8
*) (UINTN
)GlobalData
->RecycledTxBuf
[GlobalData
->RecycledTxBufCount
];
879 *((UINT8
**) TxBuffer
) = NULL
;
883 if (InterruptStatus
!= NULL
) {
884 *InterruptStatus
= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
892 Places a packet in the transmit queue of a network interface.
894 @param This Protocol instance pointer.
895 @param HeaderSize The size, in bytes, of the media header to be filled in by
896 the Transmit() function. If HeaderSize is non-zero, then it
897 must be equal to This->Mode->MediaHeaderSize and the DestAddr
898 and Protocol parameters must not be NULL.
899 @param BufferSize The size, in bytes, of the entire packet (media header and
900 data) to be transmitted through the network interface.
901 @param Buffer A pointer to the packet (media header followed by data) to be
902 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
903 then the media header in Buffer must already be filled in by the
904 caller. If HeaderSize is non-zero, then the media header will be
905 filled in by the Transmit() function.
906 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
907 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
908 This->Mode->CurrentAddress is used for the source HW MAC address.
909 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
910 parameter is ignored.
911 @param Protocol The type of header to build. If HeaderSize is zero, then this
912 parameter is ignored. See RFC 1700, section "Ether Types", for
915 @retval EFI_SUCCESS The packet was placed on the transmit queue.
916 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
917 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
923 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
927 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
928 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
929 IN UINT16
*Protocol OPTIONAL
932 SNPNT32_INSTANCE_DATA
*Instance
;
933 SNPNT32_GLOBAL_DATA
*GlobalData
;
937 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
939 GlobalData
= Instance
->GlobalData
;
941 if ((HeaderSize
!= 0) && (SrcAddr
== NULL
)) {
942 SrcAddr
= &Instance
->Mode
.CurrentAddress
;
945 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
946 return EFI_ACCESS_DENIED
;
949 ReturnValue
= GlobalData
->NtNetUtilityTable
.Transmit (
950 Instance
->InterfaceInfo
.InterfaceIndex
,
959 EfiReleaseLock (&GlobalData
->Lock
);
961 if (ReturnValue
< 0) {
962 return EFI_DEVICE_ERROR
;
964 if ((GlobalData
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
) >= SNP_MAX_TX_BUFFER_NUM
) {
965 return EFI_NOT_READY
;
968 if (GlobalData
->RecycledTxBufCount
< GlobalData
->MaxRecycledTxBuf
) {
969 GlobalData
->RecycledTxBuf
[GlobalData
->RecycledTxBufCount
] = (UINT64
) Buffer
;
970 GlobalData
->RecycledTxBufCount
++;
972 Tmp
= AllocatePool (sizeof (UINT64
) * (GlobalData
->MaxRecycledTxBuf
+ SNP_TX_BUFFER_INCREASEMENT
));
974 return EFI_DEVICE_ERROR
;
976 CopyMem (Tmp
, GlobalData
->RecycledTxBuf
, sizeof (UINT64
) * GlobalData
->RecycledTxBufCount
);
977 FreePool (GlobalData
->RecycledTxBuf
);
978 GlobalData
->RecycledTxBuf
= Tmp
;
979 GlobalData
->MaxRecycledTxBuf
+= SNP_TX_BUFFER_INCREASEMENT
;
987 Receives a packet from a network interface.
989 @param This Protocol instance pointer.
990 @param HeaderSize The size, in bytes, of the media header received on the network
991 interface. If this parameter is NULL, then the media header size
992 will not be returned.
993 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
994 bytes, of the packet that was received on the network interface.
995 @param Buffer A pointer to the data buffer to receive both the media header and
997 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
998 HW MAC source address will not be extracted from the media
1000 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
1001 the HW MAC destination address will not be extracted from the
1003 @param Protocol The media header type. If this parameter is NULL, then the
1004 protocol will not be extracted from the media header. See
1005 RFC 1700 section "Ether Types" for examples.
1007 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
1008 been updated to the number of bytes received.
1009 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
1011 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
1012 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1013 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
1019 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
1020 OUT UINTN
*HeaderSize
,
1021 IN OUT UINTN
*BuffSize
,
1023 OUT EFI_MAC_ADDRESS
*SourceAddr
,
1024 OUT EFI_MAC_ADDRESS
*DestinationAddr
,
1025 OUT UINT16
*Protocol
1028 SNPNT32_INSTANCE_DATA
*Instance
;
1029 SNPNT32_GLOBAL_DATA
*GlobalData
;
1033 BufSize
= *BuffSize
;
1035 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
1037 GlobalData
= Instance
->GlobalData
;
1039 ASSERT (GlobalData
->NtNetUtilityTable
.Receive
!= NULL
);
1041 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
1042 return EFI_ACCESS_DENIED
;
1045 ReturnValue
= GlobalData
->NtNetUtilityTable
.Receive (
1046 Instance
->InterfaceInfo
.InterfaceIndex
,
1051 EfiReleaseLock (&GlobalData
->Lock
);
1053 if (ReturnValue
< 0) {
1054 if (ReturnValue
== -100) {
1055 return EFI_BUFFER_TOO_SMALL
;
1058 return EFI_DEVICE_ERROR
;
1059 } else if (ReturnValue
== 0) {
1060 return EFI_NOT_READY
;
1063 if (HeaderSize
!= NULL
) {
1067 if (SourceAddr
!= NULL
) {
1068 ZeroMem (SourceAddr
, sizeof (EFI_MAC_ADDRESS
));
1069 CopyMem (SourceAddr
, ((UINT8
*) Buffer
) + 6, 6);
1072 if (DestinationAddr
!= NULL
) {
1073 ZeroMem (DestinationAddr
, sizeof (EFI_MAC_ADDRESS
));
1074 CopyMem (DestinationAddr
, ((UINT8
*) Buffer
), 6);
1077 if (Protocol
!= NULL
) {
1078 *Protocol
= NTOHS (*((UINT16
*) (((UINT8
*) Buffer
) + 12)));
1081 return (*BuffSize
<= BufSize
) ? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
1085 Initialize the driver's global data.
1087 @param This Pointer to the global context data.
1089 @retval EFI_SUCCESS The global data is initialized.
1090 @retval EFI_NOT_FOUND The required DLL is not found.
1091 @retval EFI_DEVICE_ERROR Error initialize network utility library.
1092 @retval EFI_OUT_OF_RESOURCES Out of resource.
1093 @retval other Other errors.
1097 SnpNt32InitializeGlobalData (
1098 IN OUT SNPNT32_GLOBAL_DATA
*This
1102 CHAR16
*DllFileNameU
;
1105 BOOLEAN NetUtilityLibInitDone
;
1106 NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer
[MAX_INTERFACE_INFO_NUMBER
];
1107 SNPNT32_INSTANCE_DATA
*Instance
;
1109 UINT32 InterfaceCount
;
1111 ASSERT (This
!= NULL
);
1113 NetUtilityLibInitDone
= FALSE
;
1114 InterfaceCount
= MAX_INTERFACE_INFO_NUMBER
;
1116 InitializeListHead (&This
->InstanceList
);
1117 EfiInitializeLock (&This
->Lock
, TPL_CALLBACK
);
1119 This
->RecycledTxBuf
= AllocatePool (sizeof (UINT64
) * This
->MaxRecycledTxBuf
);
1120 if (This
->RecycledTxBuf
== NULL
) {
1121 return EFI_OUT_OF_RESOURCES
;
1125 // Get the WinNT thunk
1127 Status
= gBS
->LocateProtocol (&gEfiWinNtThunkProtocolGuid
, NULL
, (VOID
**)&This
->WinNtThunk
);
1129 if (EFI_ERROR (Status
)) {
1133 ASSERT (This
->WinNtThunk
!= NULL
);
1135 DllFileNameU
= NETWORK_LIBRARY_NAME_U
;
1138 // Load network utility library
1140 This
->NetworkLibraryHandle
= This
->WinNtThunk
->LoadLibraryEx (DllFileNameU
, NULL
, 0);
1142 if (NULL
== This
->NetworkLibraryHandle
) {
1143 return EFI_NOT_FOUND
;
1146 This
->NtNetUtilityTable
.Initialize
= (NT_NET_INITIALIZE
) This
->WinNtThunk
->GetProcAddress (
1147 This
->NetworkLibraryHandle
,
1148 NETWORK_LIBRARY_INITIALIZE
1151 if (NULL
== This
->NtNetUtilityTable
.Initialize
) {
1152 Status
= EFI_NOT_FOUND
;
1156 This
->NtNetUtilityTable
.Finalize
= (NT_NET_FINALIZE
) This
->WinNtThunk
->GetProcAddress (
1157 This
->NetworkLibraryHandle
,
1158 NETWORK_LIBRARY_FINALIZE
1161 if (NULL
== This
->NtNetUtilityTable
.Finalize
) {
1162 Status
= EFI_NOT_FOUND
;
1166 This
->NtNetUtilityTable
.SetReceiveFilter
= (NT_NET_SET_RECEIVE_FILTER
) This
->WinNtThunk
->GetProcAddress (
1167 This
->NetworkLibraryHandle
,
1168 NETWORK_LIBRARY_SET_RCV_FILTER
1171 if (NULL
== This
->NtNetUtilityTable
.SetReceiveFilter
) {
1172 Status
= EFI_NOT_FOUND
;
1176 This
->NtNetUtilityTable
.Receive
= (NT_NET_RECEIVE
) This
->WinNtThunk
->GetProcAddress (
1177 This
->NetworkLibraryHandle
,
1178 NETWORK_LIBRARY_RECEIVE
1181 if (NULL
== This
->NtNetUtilityTable
.Receive
) {
1182 Status
= EFI_NOT_FOUND
;
1186 This
->NtNetUtilityTable
.Transmit
= (NT_NET_TRANSMIT
) This
->WinNtThunk
->GetProcAddress (
1187 This
->NetworkLibraryHandle
,
1188 NETWORK_LIBRARY_TRANSMIT
1191 if (NULL
== This
->NtNetUtilityTable
.Transmit
) {
1192 Status
= EFI_NOT_FOUND
;
1196 // Initialize the network utility library
1197 // And enumerate the interfaces in NT32 host
1199 ReturnValue
= This
->NtNetUtilityTable
.Initialize (&InterfaceCount
, &NetInterfaceInfoBuffer
[0]);
1200 if (ReturnValue
<= 0) {
1201 Status
= EFI_DEVICE_ERROR
;
1205 NetUtilityLibInitDone
= TRUE
;
1207 if (InterfaceCount
== 0) {
1208 Status
= EFI_NOT_FOUND
;
1212 // Create fake SNP instances
1214 for (Index
= 0; Index
< InterfaceCount
; Index
++) {
1216 Instance
= AllocatePool (sizeof (SNPNT32_INSTANCE_DATA
));
1218 if (NULL
== Instance
) {
1219 Status
= EFI_OUT_OF_RESOURCES
;
1223 // Copy the content from a template
1225 CopyMem (Instance
, &gSnpNt32InstanceTemplate
, sizeof (SNPNT32_INSTANCE_DATA
));
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
);