3 Copyright (c) 2006 - 2010, 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
397 NULL
, // DeviceHandle
400 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION
, // Revision
401 SnpNt32Start
, // Start
403 SnpNt32Initialize
, // Initialize
404 SnpNt32Reset
, // Reset
405 SnpNt32Shutdown
, // Shutdown
406 SnpNt32ReceiveFilters
, // ReceiveFilters
407 SnpNt32StationAddress
, // StationAddress
408 SnpNt32Statistics
, // Statistics
409 SnpNt32McastIptoMac
, // MCastIpToMac
410 SnpNt32Nvdata
, // NvData
411 SnpNt32GetStatus
, // GetStatus
412 SnpNt32Transmit
, // Transmit
413 SnpNt32Receive
, // Receive
414 NULL
, // WaitForPacket
418 EfiSimpleNetworkInitialized
, // State
419 NET_ETHER_ADDR_LEN
, // HwAddressSize
420 NET_ETHER_HEADER_SIZE
, // MediaHeaderSize
421 1500, // MaxPacketSize
423 0, // NvRamAccessSize
424 0, // ReceiveFilterMask
425 0, // ReceiveFilterSetting
426 MAX_MCAST_FILTER_CNT
, // MaxMCastFilterCount
427 0, // MCastFilterCount
436 }, // BroadcastAddress
439 }, // PermanentAddress
440 NET_IFTYPE_ETHERNET
, // IfType
441 FALSE
, // MacAddressChangeable
442 FALSE
, // MultipleTxSupported
443 TRUE
, // MediaPresentSupported
452 Test to see if this driver supports ControllerHandle. This service
453 is called by the EFI boot service ConnectController(). In
454 order to make drivers as small as possible, there are a few calling
455 restrictions for this service. ConnectController() must
456 follow these calling restrictions. If any other agent wishes to call
457 Supported() it must also follow these calling restrictions.
459 @param This Protocol instance pointer.
460 @param ControllerHandle Handle of device to test
461 @param RemainingDevicePath Optional parameter use to pick a specific child
464 @retval EFI_SUCCESS This driver supports this device
465 @retval EFI_UNSUPPORTED This driver does not support this device
470 SnpNt32DriverBindingSupported (
471 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
472 IN EFI_HANDLE ControllerHandle
,
473 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
477 SNPNT32_GLOBAL_DATA
*GlobalData
;
479 SNPNT32_INSTANCE_DATA
*Instance
;
481 GlobalData
= &gSnpNt32GlobalData
;
483 NET_LIST_FOR_EACH (Entry
, &GlobalData
->InstanceList
) {
485 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
487 if (Instance
->DeviceHandle
== ControllerHandle
) {
493 return EFI_UNSUPPORTED
;
498 Start this driver on ControllerHandle. This service is called by the
499 EFI boot service ConnectController(). In order to make
500 drivers as small as possible, there are a few calling restrictions for
501 this service. ConnectController() must follow these
502 calling restrictions. If any other agent wishes to call Start() it
503 must also follow these calling restrictions.
505 @param This Protocol instance pointer.
506 @param ControllerHandle Handle of device to bind driver to
507 @param RemainingDevicePath Optional parameter use to pick a specific child
510 @retval EFI_SUCCESS Always succeeds.
515 SnpNt32DriverBindingStart (
516 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
517 IN EFI_HANDLE ControllerHandle
,
518 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
525 Stop this driver on ControllerHandle. This service is called by the
526 EFI boot service DisconnectController(). In order to
527 make drivers as small as possible, there are a few calling
528 restrictions for this service. DisconnectController()
529 must follow these calling restrictions. If any other agent wishes
530 to call Stop() it must also follow these calling restrictions.
532 @param This Protocol instance pointer.
533 @param ControllerHandle Handle of device to stop driver on
534 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
535 children is zero stop the entire bus driver.
536 @param ChildHandleBuffer List of Child Handles to Stop.
538 @retval EFI_SUCCESS Always succeeds.
543 SnpNt32DriverBindingStop (
544 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
545 IN EFI_HANDLE ControllerHandle
,
546 IN UINTN NumberOfChildren
,
547 IN EFI_HANDLE
*ChildHandleBuffer
555 Changes the state of a network interface from "stopped" to "started".
557 @param This Protocol instance pointer.
559 @retval EFI_SUCCESS Always succeeds.
565 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
573 Changes the state of a network interface from "started" to "stopped".
575 @param This Protocol instance pointer.
577 @retval EFI_SUCCESS Always succeeds.
583 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
590 Resets a network adapter and allocates the transmit and receive buffers
591 required by the network interface; optionally, also requests allocation
592 of additional transmit and receive buffers.
594 @param This Protocol instance pointer.
595 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
596 that the driver should allocate for the network interface.
597 Some network interfaces will not be able to use the extra
598 buffer, and the caller will not know if it is actually
600 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
601 that the driver should allocate for the network interface.
602 Some network interfaces will not be able to use the extra
603 buffer, and the caller will not know if it is actually
606 @retval EFI_SUCCESS Always succeeds.
612 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
613 IN UINTN ExtraRxBufferSize OPTIONAL
,
614 IN UINTN ExtraTxBufferSize OPTIONAL
621 Resets a network adapter and re-initializes it with the parameters that were
622 provided in the previous call to Initialize().
624 @param This Protocol instance pointer.
625 @param ExtendedVerification Indicates that the driver may perform a more
626 exhaustive verification operation of the device
629 @retval EFI_SUCCESS Always succeeds.
635 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
636 IN BOOLEAN ExtendedVerification
643 Resets a network adapter and leaves it in a state that is safe for
644 another driver to initialize.
646 @param This Protocol instance pointer.
648 @retval EFI_SUCCESS Always succeeds.
654 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
661 Manages the multicast receive filters of a network interface.
663 @param This Protocol instance pointer.
664 @param EnableBits A bit mask of receive filters to enable on the network interface.
665 @param DisableBits A bit mask of receive filters to disable on the network interface.
666 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive
667 filters on the network interface to their default values.
668 @param McastFilterCount Number of multicast HW MAC addresses in the new
669 MCastFilter list. This value must be less than or equal to
670 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This
671 field is optional if ResetMCastFilter is TRUE.
672 @param McastFilter A pointer to a list of new multicast receive filter HW MAC
673 addresses. This list will replace any existing multicast
674 HW MAC address list. This field is optional if
675 ResetMCastFilter is TRUE.
677 @retval EFI_SUCCESS The multicast receive filter list was updated.
678 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
683 SnpNt32ReceiveFilters (
684 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
685 IN UINT32 EnableBits
,
686 IN UINT32 DisableBits
,
687 IN BOOLEAN ResetMcastFilter
,
688 IN UINTN McastFilterCount OPTIONAL
,
689 IN EFI_MAC_ADDRESS
*McastFilter OPTIONAL
692 SNPNT32_INSTANCE_DATA
*Instance
;
693 SNPNT32_GLOBAL_DATA
*GlobalData
;
696 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
698 GlobalData
= Instance
->GlobalData
;
700 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
701 return EFI_ACCESS_DENIED
;
704 ReturnValue
= GlobalData
->NtNetUtilityTable
.SetReceiveFilter (
705 Instance
->InterfaceInfo
.InterfaceIndex
,
711 EfiReleaseLock (&GlobalData
->Lock
);
713 if (ReturnValue
<= 0) {
714 return EFI_DEVICE_ERROR
;
721 Modifies or resets the current station address, if supported.
723 @param This Protocol instance pointer.
724 @param Reset Flag used to reset the station address to the network interfaces
726 @param NewMacAddr New station address to be used for the network interface.
728 @retval EFI_UNSUPPORTED Not supported yet.
733 SnpNt32StationAddress (
734 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
736 IN EFI_MAC_ADDRESS
*NewMacAddr OPTIONAL
739 return EFI_UNSUPPORTED
;
743 Resets or collects the statistics on a network interface.
745 @param This Protocol instance pointer.
746 @param Reset Set to TRUE to reset the statistics for the network interface.
747 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
748 output the size, in bytes, of the resulting table of
750 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
751 contains the statistics.
753 @retval EFI_SUCCESS The statistics were collected from the network interface.
754 @retval EFI_NOT_STARTED The network interface has not been started.
755 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
756 size needed to hold the statistics is returned in
758 @retval EFI_UNSUPPORTED Not supported yet.
764 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
766 IN OUT UINTN
*StatisticsSize OPTIONAL
,
767 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
770 return EFI_UNSUPPORTED
;
774 Converts a multicast IP address to a multicast HW MAC address.
776 @param This Protocol instance pointer.
777 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
778 to FALSE if the multicast IP address is IPv4 [RFC 791].
779 @param Ip The multicast IP address that is to be converted to a multicast
781 @param Mac The multicast HW MAC address that is to be generated from IP.
783 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
785 @retval EFI_NOT_STARTED The network interface has not been started.
786 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
787 size needed to hold the statistics is returned in
789 @retval EFI_UNSUPPORTED Not supported yet.
794 SnpNt32McastIptoMac (
795 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
797 IN EFI_IP_ADDRESS
*Ip
,
798 OUT EFI_MAC_ADDRESS
*Mac
801 return EFI_UNSUPPORTED
;
806 Performs read and write operations on the NVRAM device attached to a
809 @param This Protocol instance pointer.
810 @param ReadOrWrite TRUE for read operations, FALSE for write operations.
811 @param Offset Byte offset in the NVRAM device at which to start the read or
812 write operation. This must be a multiple of NvRamAccessSize and
814 @param BufferSize The number of bytes to read or write from the NVRAM device.
815 This must also be a multiple of NvramAccessSize.
816 @param Buffer A pointer to the data buffer.
818 @retval EFI_UNSUPPORTED Not supported yet.
824 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
825 IN BOOLEAN ReadOrWrite
,
831 return EFI_UNSUPPORTED
;
836 Reads the current interrupt status and recycled transmit buffer status from
839 @param This Protocol instance pointer.
840 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
841 If this is NULL, the interrupt status will not be read from
842 the device. If this is not NULL, the interrupt status will
843 be read from the device. When the interrupt status is read,
844 it will also be cleared. Clearing the transmit interrupt
845 does not empty the recycled transmit buffer array.
846 @param TxBuffer Recycled transmit buffer address. The network interface will
847 not transmit if its internal recycled transmit buffer array
848 is full. Reading the transmit buffer does not clear the
849 transmit interrupt. If this is NULL, then the transmit buffer
850 status will not be read. If there are no transmit buffers to
851 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
853 @retval EFI_SUCCESS Always succeeds.
859 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
860 OUT UINT32
*InterruptStatus
,
865 if (TxBuffer
!= NULL
) {
866 *((UINT8
**) TxBuffer
) = (UINT8
*) 1;
869 if (InterruptStatus
!= NULL
) {
870 *InterruptStatus
= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
878 Places a packet in the transmit queue of a network interface.
880 @param This Protocol instance pointer.
881 @param HeaderSize The size, in bytes, of the media header to be filled in by
882 the Transmit() function. If HeaderSize is non-zero, then it
883 must be equal to This->Mode->MediaHeaderSize and the DestAddr
884 and Protocol parameters must not be NULL.
885 @param BufferSize The size, in bytes, of the entire packet (media header and
886 data) to be transmitted through the network interface.
887 @param Buffer A pointer to the packet (media header followed by data) to be
888 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
889 then the media header in Buffer must already be filled in by the
890 caller. If HeaderSize is non-zero, then the media header will be
891 filled in by the Transmit() function.
892 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
893 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
894 This->Mode->CurrentAddress is used for the source HW MAC address.
895 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
896 parameter is ignored.
897 @param Protocol The type of header to build. If HeaderSize is zero, then this
898 parameter is ignored. See RFC 1700, section "Ether Types", for
901 @retval EFI_SUCCESS The packet was placed on the transmit queue.
902 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
903 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
909 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
913 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
914 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
915 IN UINT16
*Protocol OPTIONAL
918 SNPNT32_INSTANCE_DATA
*Instance
;
919 SNPNT32_GLOBAL_DATA
*GlobalData
;
922 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
924 GlobalData
= Instance
->GlobalData
;
926 if ((HeaderSize
!= 0) && (SrcAddr
== NULL
)) {
927 SrcAddr
= &Instance
->Mode
.CurrentAddress
;
930 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
931 return EFI_ACCESS_DENIED
;
934 ReturnValue
= GlobalData
->NtNetUtilityTable
.Transmit (
935 Instance
->InterfaceInfo
.InterfaceIndex
,
944 EfiReleaseLock (&GlobalData
->Lock
);
946 if (ReturnValue
< 0) {
947 return EFI_DEVICE_ERROR
;
954 Receives a packet from a network interface.
956 @param This Protocol instance pointer.
957 @param HeaderSize The size, in bytes, of the media header received on the network
958 interface. If this parameter is NULL, then the media header size
959 will not be returned.
960 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in
961 bytes, of the packet that was received on the network interface.
962 @param Buffer A pointer to the data buffer to receive both the media header and
964 @param SourceAddr The source HW MAC address. If this parameter is NULL, the
965 HW MAC source address will not be extracted from the media
967 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,
968 the HW MAC destination address will not be extracted from the
970 @param Protocol The media header type. If this parameter is NULL, then the
971 protocol will not be extracted from the media header. See
972 RFC 1700 section "Ether Types" for examples.
974 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
975 been updated to the number of bytes received.
976 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
978 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
979 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
980 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.
986 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
987 OUT UINTN
*HeaderSize
,
988 IN OUT UINTN
*BuffSize
,
990 OUT EFI_MAC_ADDRESS
*SourceAddr
,
991 OUT EFI_MAC_ADDRESS
*DestinationAddr
,
995 SNPNT32_INSTANCE_DATA
*Instance
;
996 SNPNT32_GLOBAL_DATA
*GlobalData
;
1000 BufSize
= *BuffSize
;
1002 Instance
= SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This
);
1004 GlobalData
= Instance
->GlobalData
;
1006 ASSERT (GlobalData
->NtNetUtilityTable
.Receive
!= NULL
);
1008 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData
->Lock
))) {
1009 return EFI_ACCESS_DENIED
;
1012 ReturnValue
= GlobalData
->NtNetUtilityTable
.Receive (
1013 Instance
->InterfaceInfo
.InterfaceIndex
,
1018 EfiReleaseLock (&GlobalData
->Lock
);
1020 if (ReturnValue
< 0) {
1021 if (ReturnValue
== -100) {
1022 return EFI_BUFFER_TOO_SMALL
;
1025 return EFI_DEVICE_ERROR
;
1026 } else if (ReturnValue
== 0) {
1027 return EFI_NOT_READY
;
1030 if (HeaderSize
!= NULL
) {
1034 if (SourceAddr
!= NULL
) {
1035 ZeroMem (SourceAddr
, sizeof (EFI_MAC_ADDRESS
));
1036 CopyMem (SourceAddr
, ((UINT8
*) Buffer
) + 6, 6);
1039 if (DestinationAddr
!= NULL
) {
1040 ZeroMem (DestinationAddr
, sizeof (EFI_MAC_ADDRESS
));
1041 CopyMem (DestinationAddr
, ((UINT8
*) Buffer
), 6);
1044 if (Protocol
!= NULL
) {
1045 *Protocol
= NTOHS (*((UINT16
*) (((UINT8
*) Buffer
) + 12)));
1048 return (*BuffSize
<= BufSize
) ? EFI_SUCCESS
: EFI_BUFFER_TOO_SMALL
;
1052 Initialize the driver's global data.
1054 @param This Pointer to the global context data.
1056 @retval EFI_SUCCESS The global data is initialized.
1057 @retval EFI_NOT_FOUND The required DLL is not found.
1058 @retval EFI_DEVICE_ERROR Error initialize network utility library.
1059 @retval EFI_OUT_OF_RESOURCES Out of resource.
1060 @retval other Other errors.
1064 SnpNt32InitializeGlobalData (
1065 IN OUT SNPNT32_GLOBAL_DATA
*This
1069 CHAR16
*DllFileNameU
;
1072 BOOLEAN NetUtilityLibInitDone
;
1073 NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer
[MAX_INTERFACE_INFO_NUMBER
];
1074 SNPNT32_INSTANCE_DATA
*Instance
;
1076 UINT32 InterfaceCount
;
1078 ASSERT (This
!= NULL
);
1080 NetUtilityLibInitDone
= FALSE
;
1081 InterfaceCount
= MAX_INTERFACE_INFO_NUMBER
;
1083 InitializeListHead (&This
->InstanceList
);
1084 EfiInitializeLock (&This
->Lock
, TPL_CALLBACK
);
1087 // Get the WinNT thunk
1089 Status
= gBS
->LocateProtocol (&gEfiWinNtThunkProtocolGuid
, NULL
, (VOID
**)&This
->WinNtThunk
);
1091 if (EFI_ERROR (Status
)) {
1095 ASSERT (This
->WinNtThunk
!= NULL
);
1097 DllFileNameU
= NETWORK_LIBRARY_NAME_U
;
1100 // Load network utility library
1102 This
->NetworkLibraryHandle
= This
->WinNtThunk
->LoadLibraryEx (DllFileNameU
, NULL
, 0);
1104 if (NULL
== This
->NetworkLibraryHandle
) {
1105 return EFI_NOT_FOUND
;
1108 This
->NtNetUtilityTable
.Initialize
= (NT_NET_INITIALIZE
) This
->WinNtThunk
->GetProcAddress (
1109 This
->NetworkLibraryHandle
,
1110 NETWORK_LIBRARY_INITIALIZE
1113 if (NULL
== This
->NtNetUtilityTable
.Initialize
) {
1114 Status
= EFI_NOT_FOUND
;
1118 This
->NtNetUtilityTable
.Finalize
= (NT_NET_FINALIZE
) This
->WinNtThunk
->GetProcAddress (
1119 This
->NetworkLibraryHandle
,
1120 NETWORK_LIBRARY_FINALIZE
1123 if (NULL
== This
->NtNetUtilityTable
.Finalize
) {
1124 Status
= EFI_NOT_FOUND
;
1128 This
->NtNetUtilityTable
.SetReceiveFilter
= (NT_NET_SET_RECEIVE_FILTER
) This
->WinNtThunk
->GetProcAddress (
1129 This
->NetworkLibraryHandle
,
1130 NETWORK_LIBRARY_SET_RCV_FILTER
1133 if (NULL
== This
->NtNetUtilityTable
.SetReceiveFilter
) {
1134 Status
= EFI_NOT_FOUND
;
1138 This
->NtNetUtilityTable
.Receive
= (NT_NET_RECEIVE
) This
->WinNtThunk
->GetProcAddress (
1139 This
->NetworkLibraryHandle
,
1140 NETWORK_LIBRARY_RECEIVE
1143 if (NULL
== This
->NtNetUtilityTable
.Receive
) {
1144 Status
= EFI_NOT_FOUND
;
1148 This
->NtNetUtilityTable
.Transmit
= (NT_NET_TRANSMIT
) This
->WinNtThunk
->GetProcAddress (
1149 This
->NetworkLibraryHandle
,
1150 NETWORK_LIBRARY_TRANSMIT
1153 if (NULL
== This
->NtNetUtilityTable
.Transmit
) {
1154 Status
= EFI_NOT_FOUND
;
1158 // Initialize the network utility library
1159 // And enumerate the interfaces in NT32 host
1161 ReturnValue
= This
->NtNetUtilityTable
.Initialize (&InterfaceCount
, &NetInterfaceInfoBuffer
[0]);
1162 if (ReturnValue
<= 0) {
1163 Status
= EFI_DEVICE_ERROR
;
1167 NetUtilityLibInitDone
= TRUE
;
1169 if (InterfaceCount
== 0) {
1170 Status
= EFI_NOT_FOUND
;
1174 // Create fake SNP instances
1176 for (Index
= 0; Index
< InterfaceCount
; Index
++) {
1178 Instance
= AllocatePool (sizeof (SNPNT32_INSTANCE_DATA
));
1180 if (NULL
== Instance
) {
1181 Status
= EFI_OUT_OF_RESOURCES
;
1185 // Copy the content from a template
1187 CopyMem (Instance
, &gSnpNt32InstanceTemplate
, sizeof (SNPNT32_INSTANCE_DATA
));
1190 // Set the interface information.
1192 Instance
->InterfaceInfo
= NetInterfaceInfoBuffer
[Index
];
1194 // Initialize this instance
1196 Status
= This
->InitializeInstanceData (This
, Instance
);
1197 if (EFI_ERROR (Status
)) {
1199 gBS
->FreePool (Instance
);
1203 // Insert this instance into the instance list
1205 InsertTailList (&This
->InstanceList
, &Instance
->Entry
);
1212 while (!IsListEmpty (&This
->InstanceList
)) {
1214 Entry
= This
->InstanceList
.ForwardLink
;
1216 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
1218 RemoveEntryList (Entry
);
1220 This
->CloseInstance (This
, Instance
);
1221 gBS
->FreePool (Instance
);
1224 if (NetUtilityLibInitDone
) {
1226 ASSERT (This
->WinNtThunk
!= NULL
);
1228 if (This
->NtNetUtilityTable
.Finalize
!= NULL
) {
1229 This
->NtNetUtilityTable
.Finalize ();
1230 This
->NtNetUtilityTable
.Finalize
= NULL
;
1239 Initialize the snpnt32 driver instance.
1241 @param This Pointer to the SnpNt32 global data.
1242 @param Instance Pointer to the instance context data.
1244 @retval EFI_SUCCESS The driver instance is initialized.
1245 @retval other Initialization errors.
1249 SnpNt32InitializeInstanceData (
1250 IN SNPNT32_GLOBAL_DATA
*This
,
1251 IN OUT SNPNT32_INSTANCE_DATA
*Instance
1255 EFI_DEV_PATH EndNode
;
1258 Instance
->GlobalData
= This
;
1259 Instance
->Snp
.Mode
= &Instance
->Mode
;
1261 // Set broadcast address
1263 SetMem (&Instance
->Mode
.BroadcastAddress
, sizeof (EFI_MAC_ADDRESS
), 0xFF);
1266 // Copy Current/PermanentAddress MAC address
1268 Instance
->Mode
.CurrentAddress
= Instance
->InterfaceInfo
.MacAddr
;
1269 Instance
->Mode
.PermanentAddress
= Instance
->InterfaceInfo
.MacAddr
;
1272 // Since the fake SNP is based on a real NIC, to avoid conflict with the host
1273 // NIC network stack, we use a different MAC address.
1274 // So just change the last byte of the MAC address for the real NIC.
1276 Instance
->Mode
.CurrentAddress
.Addr
[NET_ETHER_ADDR_LEN
- 1]++;
1279 // Create a fake device path for the instance
1281 ZeroMem (&Node
, sizeof (Node
));
1283 Node
.DevPath
.Type
= MESSAGING_DEVICE_PATH
;
1284 Node
.DevPath
.SubType
= MSG_MAC_ADDR_DP
;
1285 SetDevicePathNodeLength (&Node
.DevPath
, sizeof (MAC_ADDR_DEVICE_PATH
));
1288 &Node
.MacAddr
.MacAddress
,
1289 &Instance
->Mode
.CurrentAddress
,
1293 Node
.MacAddr
.IfType
= Instance
->Mode
.IfType
;
1295 SetDevicePathEndNode (&EndNode
.DevPath
);
1297 Instance
->DevicePath
= AppendDevicePathNode (
1303 // Create a fake device handle for the fake SNP
1305 Status
= gBS
->InstallMultipleProtocolInterfaces (
1306 &Instance
->DeviceHandle
,
1307 &gEfiSimpleNetworkProtocolGuid
,
1309 &gEfiDevicePathProtocolGuid
,
1310 Instance
->DevicePath
,
1318 Close the SnpNt32 driver instance.
1320 @param This Pointer to the SnpNt32 global data.
1321 @param Instance Pointer to the instance context data.
1323 @retval EFI_SUCCESS The instance is closed.
1327 SnpNt32CloseInstance (
1328 IN SNPNT32_GLOBAL_DATA
*This
,
1329 IN OUT SNPNT32_INSTANCE_DATA
*Instance
1332 ASSERT (This
!= NULL
);
1333 ASSERT (Instance
!= NULL
);
1335 gBS
->UninstallMultipleProtocolInterfaces (
1336 Instance
->DeviceHandle
,
1337 &gEfiSimpleNetworkProtocolGuid
,
1339 &gEfiDevicePathProtocolGuid
,
1340 Instance
->DevicePath
,
1344 if (Instance
->DevicePath
!= NULL
) {
1345 gBS
->FreePool (Instance
->DevicePath
);
1354 @param ImageHandle Handle that identifies the image to be unloaded.
1356 @retval EFI_SUCCESS The image has been unloaded.
1357 @return Exit code from the image's unload handler
1363 IN EFI_HANDLE ImageHandle
1367 SNPNT32_GLOBAL_DATA
*This
;
1369 SNPNT32_INSTANCE_DATA
*Instance
;
1371 This
= &gSnpNt32GlobalData
;
1373 Status
= NetLibDefaultUnload (ImageHandle
);
1375 if (EFI_ERROR (Status
)) {
1379 while (!IsListEmpty (&This
->InstanceList
)) {
1381 // Walkthrough the interfaces and remove all the SNP instance
1383 Entry
= This
->InstanceList
.ForwardLink
;
1385 Instance
= NET_LIST_USER_STRUCT_S (Entry
, SNPNT32_INSTANCE_DATA
, Entry
, SNP_NT32_INSTANCE_SIGNATURE
);
1387 RemoveEntryList (Entry
);
1389 This
->CloseInstance (This
, Instance
);
1390 gBS
->FreePool (Instance
);
1393 if (This
->NtNetUtilityTable
.Finalize
!= NULL
) {
1394 This
->NtNetUtilityTable
.Finalize ();
1397 This
->WinNtThunk
->FreeLibrary (This
->NetworkLibraryHandle
);
1403 This is the declaration of an EFI image entry point. This entry point is
1404 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1405 both device drivers and bus drivers.
1407 @param ImageHandle The firmware allocated handle for the UEFI image.
1408 @param SystemTable A pointer to the EFI System Table.
1410 @retval EFI_SUCCESS The operation completed successfully.
1411 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1415 InitializeSnpNt32Driver (
1416 IN EFI_HANDLE ImageHandle
,
1417 IN EFI_SYSTEM_TABLE
*SystemTable
1424 // Install the Driver Protocols
1427 Status
= EfiLibInstallDriverBindingComponentName2 (
1430 &gSnpNt32DriverBinding
,
1432 &gSnpNt32DriverComponentName
,
1433 &gSnpNt32DriverComponentName2
1435 if (EFI_ERROR (Status
)) {
1440 // Initialize the global data
1442 Status
= SnpNt32InitializeGlobalData (&gSnpNt32GlobalData
);
1443 if (EFI_ERROR (Status
)) {
1444 SnpNt32Unload (ImageHandle
);