fixed 2 k8 issues.
[edk2.git] / Nt32Pkg / SnpNt32Dxe / SnpNt32.c
blob29cee4f915fad31b4c100f4fb989075a17bd6cf7
1 /** @file
3 Copyright (c) 2006 - 2009, Intel Corporation
4 All rights reserved. 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.
12 Module Name:
14 SnpNt32.c
16 Abstract:
18 -**/
20 #include "SnpNt32.h"
22 EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding = {
23 SnpNt32DriverBindingSupported,
24 SnpNt32DriverBindingStart,
25 SnpNt32DriverBindingStop,
26 0xa,
27 NULL,
28 NULL
31 SNPNT32_GLOBAL_DATA gSnpNt32GlobalData = {
32 SNP_NT32_DRIVER_SIGNATURE, // Signature
34 NULL,
35 NULL
36 }, // InstanceList
37 NULL, // WinNtThunk
38 NULL, // NetworkLibraryHandle
41 }, // NtNetUtilityTable
46 }, // Lock
48 // Private functions
50 SnpNt32InitializeGlobalData, // InitializeGlobalData
51 SnpNt32InitializeInstanceData, // InitializeInstanceData
52 SnpNt32CloseInstance // CloseInstance
55 /**
56 Changes the state of a network interface from "stopped" to "started".
58 @param This Protocol instance pointer.
60 @retval EFI_SUCCESS Always succeeds.
62 **/
63 EFI_STATUS
64 EFIAPI
65 SnpNt32Start (
66 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
69 /**
70 Changes the state of a network interface from "started" to "stopped".
72 @param This Protocol instance pointer.
74 @retval EFI_SUCCESS Always succeeds.
76 **/
77 EFI_STATUS
78 EFIAPI
79 SnpNt32Stop (
80 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
83 /**
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
93 being used.
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
98 being used.
100 @retval EFI_SUCCESS Always succeeds.
103 EFI_STATUS
104 EFIAPI
105 SnpNt32Initialize (
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
118 during reset.
120 @retval EFI_SUCCESS Always succeeds.
123 EFI_STATUS
124 EFIAPI
125 SnpNt32Reset (
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.
139 EFI_STATUS
140 EFIAPI
141 SnpNt32Shutdown (
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.
166 EFI_STATUS
167 EFIAPI
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
182 permanent address.
183 @param NewMacAddr New station address to be used for the network interface.
185 @retval EFI_UNSUPPORTED Not supported yet.
188 EFI_STATUS
189 EFIAPI
190 SnpNt32StationAddress (
191 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
192 IN BOOLEAN Reset,
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
203 statistics.
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
211 StatisticsSize.
212 @retval EFI_UNSUPPORTED Not supported yet.
215 EFI_STATUS
216 EFIAPI
217 SnpNt32Statistics (
218 IN EFI_SIMPLE_NETWORK_PROTOCOL * This,
219 IN BOOLEAN Reset,
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
231 HW MAC address.
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
235 HW MAC address.
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
239 StatisticsSize.
240 @retval EFI_UNSUPPORTED Not supported yet.
243 EFI_STATUS
244 EFIAPI
245 SnpNt32McastIptoMac (
246 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
247 IN BOOLEAN Ipv6,
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
254 network interface.
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
260 less than NvRamSize.
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.
268 EFI_STATUS
269 EFIAPI
270 SnpNt32Nvdata (
271 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
272 IN BOOLEAN ReadOrWrite,
273 IN UINTN Offset,
274 IN UINTN BufferSize,
275 IN OUT VOID *Buffer
279 Reads the current interrupt status and recycled transmit buffer status from
280 a network interface.
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.
299 EFI_STATUS
300 EFIAPI
301 SnpNt32GetStatus (
302 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
303 OUT UINT32 *InterruptStatus,
304 OUT VOID **TxBuffer
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
329 examples.
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.
336 EFI_STATUS
337 EFIAPI
338 SnpNt32Transmit (
339 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
340 IN UINTN HeaderSize,
341 IN UINTN BufferSize,
342 IN VOID *Buffer,
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
358 the data.
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
361 header.
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
364 media header.
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
372 request.
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.
378 EFI_STATUS
379 EFIAPI
380 SnpNt32Receive (
381 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
382 OUT UINTN *HeaderSize,
383 IN OUT UINTN *BuffSize,
384 OUT VOID *Buffer,
385 OUT EFI_MAC_ADDRESS *SourceAddr,
386 OUT EFI_MAC_ADDRESS *DestinationAddr,
387 OUT UINT16 *Protocol
390 SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = {
391 SNP_NT32_INSTANCE_SIGNATURE, // Signature
393 NULL,
394 NULL
395 }, // Entry
396 NULL, // GlobalData
397 NULL, // DeviceHandle
398 NULL, // DevicePath
399 { // Snp
400 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, // Revision
401 SnpNt32Start, // Start
402 SnpNt32Stop, // Stop
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
415 NULL // Mode
417 { // Mode
418 EfiSimpleNetworkInitialized, // State
419 NET_ETHER_ADDR_LEN, // HwAddressSize
420 NET_ETHER_HEADER_SIZE, // MediaHeaderSize
421 1500, // MaxPacketSize
422 0, // NvRamSize
423 0, // NvRamAccessSize
424 0, // ReceiveFilterMask
425 0, // ReceiveFilterSetting
426 MAX_MCAST_FILTER_CNT, // MaxMCastFilterCount
427 0, // MCastFilterCount
430 }, // MCastFilter
433 }, // CurrentAddress
436 }, // BroadcastAddress
439 }, // PermanentAddress
440 NET_IFTYPE_ETHERNET, // IfType
441 FALSE, // MacAddressChangeable
442 FALSE, // MultipleTxSupported
443 FALSE, // MediaPresentSupported
444 TRUE // MediaPresent
448 } // InterfaceInfo
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
462 device to start.
464 @retval EFI_SUCCESS This driver supports this device
465 @retval EFI_UNSUPPORTED This driver does not support this device
468 EFI_STATUS
469 EFIAPI
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;
478 LIST_ENTRY *Entry;
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) {
488 return EFI_SUCCESS;
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
508 device to start.
510 @retval EFI_SUCCESS Always succeeds.
513 EFI_STATUS
514 EFIAPI
515 SnpNt32DriverBindingStart (
516 IN EFI_DRIVER_BINDING_PROTOCOL * This,
517 IN EFI_HANDLE ControllerHandle,
518 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
521 return EFI_SUCCESS;
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.
541 EFI_STATUS
542 EFIAPI
543 SnpNt32DriverBindingStop (
544 IN EFI_DRIVER_BINDING_PROTOCOL *This,
545 IN EFI_HANDLE ControllerHandle,
546 IN UINTN NumberOfChildren,
547 IN EFI_HANDLE *ChildHandleBuffer
550 return EFI_SUCCESS;
555 Changes the state of a network interface from "stopped" to "started".
557 @param This Protocol instance pointer.
559 @retval EFI_SUCCESS Always succeeds.
562 EFI_STATUS
563 EFIAPI
564 SnpNt32Start (
565 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
568 return EFI_SUCCESS;
573 Changes the state of a network interface from "started" to "stopped".
575 @param This Protocol instance pointer.
577 @retval EFI_SUCCESS Always succeeds.
580 EFI_STATUS
581 EFIAPI
582 SnpNt32Stop (
583 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
586 return EFI_SUCCESS;
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
599 being used.
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
604 being used.
606 @retval EFI_SUCCESS Always succeeds.
609 EFI_STATUS
610 EFIAPI
611 SnpNt32Initialize (
612 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
613 IN UINTN ExtraRxBufferSize OPTIONAL,
614 IN UINTN ExtraTxBufferSize OPTIONAL
617 return EFI_SUCCESS;
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
627 during reset.
629 @retval EFI_SUCCESS Always succeeds.
632 EFI_STATUS
633 EFIAPI
634 SnpNt32Reset (
635 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
636 IN BOOLEAN ExtendedVerification
639 return EFI_SUCCESS;
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.
651 EFI_STATUS
652 EFIAPI
653 SnpNt32Shutdown (
654 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
657 return EFI_SUCCESS;
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.
681 EFI_STATUS
682 EFIAPI
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;
694 INT32 ReturnValue;
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,
706 EnableBits,
707 McastFilterCount,
708 McastFilter
711 EfiReleaseLock (&GlobalData->Lock);
713 if (ReturnValue <= 0) {
714 return EFI_DEVICE_ERROR;
717 return EFI_SUCCESS;
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
725 permanent address.
726 @param NewMacAddr New station address to be used for the network interface.
728 @retval EFI_UNSUPPORTED Not supported yet.
731 EFI_STATUS
732 EFIAPI
733 SnpNt32StationAddress (
734 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
735 IN BOOLEAN Reset,
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
749 statistics.
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
757 StatisticsSize.
758 @retval EFI_UNSUPPORTED Not supported yet.
761 EFI_STATUS
762 EFIAPI
763 SnpNt32Statistics (
764 IN EFI_SIMPLE_NETWORK_PROTOCOL * This,
765 IN BOOLEAN Reset,
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
780 HW MAC address.
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
784 HW MAC address.
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
788 StatisticsSize.
789 @retval EFI_UNSUPPORTED Not supported yet.
792 EFI_STATUS
793 EFIAPI
794 SnpNt32McastIptoMac (
795 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
796 IN BOOLEAN Ipv6,
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
807 network interface.
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
813 less than NvRamSize.
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.
821 EFI_STATUS
822 EFIAPI
823 SnpNt32Nvdata (
824 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
825 IN BOOLEAN ReadOrWrite,
826 IN UINTN Offset,
827 IN UINTN BufferSize,
828 IN OUT VOID *Buffer
831 return EFI_UNSUPPORTED;
836 Reads the current interrupt status and recycled transmit buffer status from
837 a network interface.
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.
856 EFI_STATUS
857 EFIAPI
858 SnpNt32GetStatus (
859 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
860 OUT UINT32 *InterruptStatus,
861 OUT VOID **TxBuffer
865 if (TxBuffer != NULL) {
866 *((UINT8 **) TxBuffer) = (UINT8 *) 1;
869 if (InterruptStatus != NULL) {
870 *InterruptStatus = EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
873 return EFI_SUCCESS;
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
899 examples.
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.
906 EFI_STATUS
907 EFIAPI
908 SnpNt32Transmit (
909 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
910 IN UINTN HeaderSize,
911 IN UINTN BufferSize,
912 IN VOID *Buffer,
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;
920 INT32 ReturnValue;
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,
936 HeaderSize,
937 BufferSize,
938 Buffer,
939 SrcAddr,
940 DestAddr,
941 Protocol
944 EfiReleaseLock (&GlobalData->Lock);
946 if (ReturnValue < 0) {
947 return EFI_DEVICE_ERROR;
950 return EFI_SUCCESS;
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
963 the data.
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
966 header.
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
969 media header.
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
977 request.
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.
983 EFI_STATUS
984 EFIAPI
985 SnpNt32Receive (
986 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
987 OUT UINTN *HeaderSize,
988 IN OUT UINTN *BuffSize,
989 OUT VOID *Buffer,
990 OUT EFI_MAC_ADDRESS *SourceAddr,
991 OUT EFI_MAC_ADDRESS *DestinationAddr,
992 OUT UINT16 *Protocol
995 SNPNT32_INSTANCE_DATA *Instance;
996 SNPNT32_GLOBAL_DATA *GlobalData;
997 INT32 ReturnValue;
999 Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);
1001 GlobalData = Instance->GlobalData;
1003 ASSERT (GlobalData->NtNetUtilityTable.Receive != NULL);
1005 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {
1006 return EFI_ACCESS_DENIED;
1009 ReturnValue = GlobalData->NtNetUtilityTable.Receive (
1010 Instance->InterfaceInfo.InterfaceIndex,
1011 BuffSize,
1012 Buffer
1015 EfiReleaseLock (&GlobalData->Lock);
1017 if (ReturnValue < 0) {
1018 if (ReturnValue == -100) {
1019 return EFI_BUFFER_TOO_SMALL;
1022 return EFI_DEVICE_ERROR;
1023 } else if (ReturnValue == 0) {
1024 return EFI_NOT_READY;
1027 if (HeaderSize != NULL) {
1028 *HeaderSize = 14;
1031 if (SourceAddr != NULL) {
1032 ZeroMem (SourceAddr, sizeof (EFI_MAC_ADDRESS));
1033 CopyMem (SourceAddr, ((UINT8 *) Buffer) + 6, 6);
1036 if (DestinationAddr != NULL) {
1037 ZeroMem (DestinationAddr, sizeof (EFI_MAC_ADDRESS));
1038 CopyMem (DestinationAddr, ((UINT8 *) Buffer), 6);
1041 if (Protocol != NULL) {
1042 *Protocol = NTOHS (*((UINT16 *) (((UINT8 *) Buffer) + 12)));
1045 return EFI_SUCCESS;
1049 Initialize the driver's global data.
1051 @param This Pointer to the global context data.
1053 @retval EFI_SUCCESS The global data is initialized.
1054 @retval EFI_NOT_FOUND The required DLL is not found.
1055 @retval EFI_DEVICE_ERROR Error initialize network utility library.
1056 @retval EFI_OUT_OF_RESOURCES Out of resource.
1057 @retval other Other errors.
1060 EFI_STATUS
1061 SnpNt32InitializeGlobalData (
1062 IN OUT SNPNT32_GLOBAL_DATA *This
1065 EFI_STATUS Status;
1066 CHAR16 *DllFileNameU;
1067 UINT32 Index;
1068 INT32 ReturnValue;
1069 BOOLEAN NetUtilityLibInitDone;
1070 NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer[MAX_INTERFACE_INFO_NUMBER];
1071 SNPNT32_INSTANCE_DATA *Instance;
1072 LIST_ENTRY *Entry;
1073 UINT32 InterfaceCount;
1075 ASSERT (This != NULL);
1077 NetUtilityLibInitDone = FALSE;
1078 InterfaceCount = MAX_INTERFACE_INFO_NUMBER;
1080 InitializeListHead (&This->InstanceList);
1081 EfiInitializeLock (&This->Lock, TPL_CALLBACK);
1084 // Get the WinNT thunk
1086 Status = gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, &This->WinNtThunk);
1088 if (EFI_ERROR (Status)) {
1089 return Status;
1092 ASSERT (This->WinNtThunk != NULL);
1094 DllFileNameU = NETWORK_LIBRARY_NAME_U;
1097 // Load network utility library
1099 This->NetworkLibraryHandle = This->WinNtThunk->LoadLibraryEx (DllFileNameU, NULL, 0);
1101 if (NULL == This->NetworkLibraryHandle) {
1102 return EFI_NOT_FOUND;
1105 This->NtNetUtilityTable.Initialize = (NT_NET_INITIALIZE) This->WinNtThunk->GetProcAddress (
1106 This->NetworkLibraryHandle,
1107 NETWORK_LIBRARY_INITIALIZE
1110 if (NULL == This->NtNetUtilityTable.Initialize) {
1111 Status = EFI_NOT_FOUND;
1112 goto ErrorReturn;
1115 This->NtNetUtilityTable.Finalize = (NT_NET_FINALIZE) This->WinNtThunk->GetProcAddress (
1116 This->NetworkLibraryHandle,
1117 NETWORK_LIBRARY_FINALIZE
1120 if (NULL == This->NtNetUtilityTable.Finalize) {
1121 Status = EFI_NOT_FOUND;
1122 goto ErrorReturn;
1125 This->NtNetUtilityTable.SetReceiveFilter = (NT_NET_SET_RECEIVE_FILTER) This->WinNtThunk->GetProcAddress (
1126 This->NetworkLibraryHandle,
1127 NETWORK_LIBRARY_SET_RCV_FILTER
1130 if (NULL == This->NtNetUtilityTable.SetReceiveFilter) {
1131 Status = EFI_NOT_FOUND;
1132 goto ErrorReturn;
1135 This->NtNetUtilityTable.Receive = (NT_NET_RECEIVE) This->WinNtThunk->GetProcAddress (
1136 This->NetworkLibraryHandle,
1137 NETWORK_LIBRARY_RECEIVE
1140 if (NULL == This->NtNetUtilityTable.Receive) {
1141 Status = EFI_NOT_FOUND;
1142 goto ErrorReturn;
1145 This->NtNetUtilityTable.Transmit = (NT_NET_TRANSMIT) This->WinNtThunk->GetProcAddress (
1146 This->NetworkLibraryHandle,
1147 NETWORK_LIBRARY_TRANSMIT
1150 if (NULL == This->NtNetUtilityTable.Transmit) {
1151 Status = EFI_NOT_FOUND;
1152 goto ErrorReturn;
1155 // Initialize the network utility library
1156 // And enumerate the interfaces in NT32 host
1158 ReturnValue = This->NtNetUtilityTable.Initialize (&InterfaceCount, &NetInterfaceInfoBuffer[0]);
1159 if (ReturnValue <= 0) {
1160 Status = EFI_DEVICE_ERROR;
1161 goto ErrorReturn;
1164 NetUtilityLibInitDone = TRUE;
1166 if (InterfaceCount == 0) {
1167 Status = EFI_NOT_FOUND;
1168 goto ErrorReturn;
1171 // Create fake SNP instances
1173 for (Index = 0; Index < InterfaceCount; Index++) {
1175 Instance = AllocatePool (sizeof (SNPNT32_INSTANCE_DATA));
1177 if (NULL == Instance) {
1178 Status = EFI_OUT_OF_RESOURCES;
1179 goto ErrorReturn;
1182 // Copy the content from a template
1184 CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA));
1187 // Set the interface information.
1189 Instance->InterfaceInfo = NetInterfaceInfoBuffer[Index];
1191 // Initialize this instance
1193 Status = This->InitializeInstanceData (This, Instance);
1194 if (EFI_ERROR (Status)) {
1196 gBS->FreePool (Instance);
1197 goto ErrorReturn;
1200 // Insert this instance into the instance list
1202 InsertTailList (&This->InstanceList, &Instance->Entry);
1205 return EFI_SUCCESS;
1207 ErrorReturn:
1209 while (!IsListEmpty (&This->InstanceList)) {
1211 Entry = This->InstanceList.ForwardLink;
1213 Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);
1215 RemoveEntryList (Entry);
1217 This->CloseInstance (This, Instance);
1218 gBS->FreePool (Instance);
1221 if (NetUtilityLibInitDone) {
1223 ASSERT (This->WinNtThunk != NULL);
1225 if (This->NtNetUtilityTable.Finalize != NULL) {
1226 This->NtNetUtilityTable.Finalize ();
1227 This->NtNetUtilityTable.Finalize = NULL;
1231 return Status;
1236 Initialize the snpnt32 driver instance.
1238 @param This Pointer to the SnpNt32 global data.
1239 @param Instance Pointer to the instance context data.
1241 @retval EFI_SUCCESS The driver instance is initialized.
1242 @retval other Initialization errors.
1245 EFI_STATUS
1246 SnpNt32InitializeInstanceData (
1247 IN SNPNT32_GLOBAL_DATA *This,
1248 IN OUT SNPNT32_INSTANCE_DATA *Instance
1251 EFI_STATUS Status;
1252 EFI_DEV_PATH EndNode;
1253 EFI_DEV_PATH Node;
1255 Instance->GlobalData = This;
1256 Instance->Snp.Mode = &Instance->Mode;
1258 // Set broadcast address
1260 SetMem (&Instance->Mode.BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF);
1263 // Copy Current/PermanentAddress MAC address
1265 Instance->Mode.CurrentAddress = Instance->InterfaceInfo.MacAddr;
1266 Instance->Mode.PermanentAddress = Instance->InterfaceInfo.MacAddr;
1269 // Since the fake SNP is based on a real NIC, to avoid conflict with the host
1270 // NIC network stack, we use a different MAC address.
1271 // So just change the last byte of the MAC address for the real NIC.
1273 Instance->Mode.CurrentAddress.Addr[NET_ETHER_ADDR_LEN - 1]++;
1276 // Create a fake device path for the instance
1278 ZeroMem (&Node, sizeof (Node));
1280 Node.DevPath.Type = MESSAGING_DEVICE_PATH;
1281 Node.DevPath.SubType = MSG_MAC_ADDR_DP;
1282 SetDevicePathNodeLength (&Node.DevPath, sizeof (MAC_ADDR_DEVICE_PATH));
1284 CopyMem (
1285 &Node.MacAddr.MacAddress,
1286 &Instance->Mode.CurrentAddress,
1287 NET_ETHER_ADDR_LEN
1290 Node.MacAddr.IfType = Instance->Mode.IfType;
1292 SetDevicePathEndNode (&EndNode.DevPath);
1294 Instance->DevicePath = AppendDevicePathNode (
1295 &EndNode.DevPath,
1296 &Node.DevPath
1300 // Create a fake device handle for the fake SNP
1302 Status = gBS->InstallMultipleProtocolInterfaces (
1303 &Instance->DeviceHandle,
1304 &gEfiSimpleNetworkProtocolGuid,
1305 &Instance->Snp,
1306 &gEfiDevicePathProtocolGuid,
1307 Instance->DevicePath,
1308 NULL
1310 return Status;
1315 Close the SnpNt32 driver instance.
1317 @param This Pointer to the SnpNt32 global data.
1318 @param Instance Pointer to the instance context data.
1320 @retval EFI_SUCCESS The instance is closed.
1323 EFI_STATUS
1324 SnpNt32CloseInstance (
1325 IN SNPNT32_GLOBAL_DATA *This,
1326 IN OUT SNPNT32_INSTANCE_DATA *Instance
1329 ASSERT (This != NULL);
1330 ASSERT (Instance != NULL);
1332 gBS->UninstallMultipleProtocolInterfaces (
1333 Instance->DeviceHandle,
1334 &gEfiSimpleNetworkProtocolGuid,
1335 &Instance->Snp,
1336 &gEfiDevicePathProtocolGuid,
1337 Instance->DevicePath,
1338 NULL
1341 if (Instance->DevicePath != NULL) {
1342 gBS->FreePool (Instance->DevicePath);
1345 return EFI_SUCCESS;
1349 Unloads an image.
1351 @param ImageHandle Handle that identifies the image to be unloaded.
1353 @retval EFI_SUCCESS The image has been unloaded.
1354 @return Exit code from the image's unload handler
1357 EFI_STATUS
1358 EFIAPI
1359 SnpNt32Unload (
1360 IN EFI_HANDLE ImageHandle
1363 EFI_STATUS Status;
1364 SNPNT32_GLOBAL_DATA *This;
1365 LIST_ENTRY *Entry;
1366 SNPNT32_INSTANCE_DATA *Instance;
1368 This = &gSnpNt32GlobalData;
1370 Status = NetLibDefaultUnload (ImageHandle);
1372 if (EFI_ERROR (Status)) {
1373 return Status;
1376 while (!IsListEmpty (&This->InstanceList)) {
1378 // Walkthrough the interfaces and remove all the SNP instance
1380 Entry = This->InstanceList.ForwardLink;
1382 Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);
1384 RemoveEntryList (Entry);
1386 This->CloseInstance (This, Instance);
1387 gBS->FreePool (Instance);
1390 if (This->NtNetUtilityTable.Finalize != NULL) {
1391 This->NtNetUtilityTable.Finalize ();
1394 This->WinNtThunk->FreeLibrary (This->NetworkLibraryHandle);
1396 return EFI_SUCCESS;
1400 This is the declaration of an EFI image entry point. This entry point is
1401 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1402 both device drivers and bus drivers.
1404 @param ImageHandle The firmware allocated handle for the UEFI image.
1405 @param SystemTable A pointer to the EFI System Table.
1407 @retval EFI_SUCCESS The operation completed successfully.
1408 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1411 EFI_STATUS
1412 InitializeSnpNt32Driver (
1413 IN EFI_HANDLE ImageHandle,
1414 IN EFI_SYSTEM_TABLE *SystemTable
1418 EFI_STATUS Status;
1421 // Install the Driver Protocols
1424 Status = EfiLibInstallDriverBindingComponentName2 (
1425 ImageHandle,
1426 SystemTable,
1427 &gSnpNt32DriverBinding,
1428 ImageHandle,
1429 &gSnpNt32DriverComponentName,
1430 &gSnpNt32DriverComponentName2
1432 if (EFI_ERROR (Status)) {
1433 return Status;
1437 // Initialize the global data
1439 Status = SnpNt32InitializeGlobalData (&gSnpNt32GlobalData);
1440 if (EFI_ERROR (Status)) {
1441 SnpNt32Unload (ImageHandle);
1444 return Status;