+++ /dev/null
-/** @file\r
-\r
-Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-Module Name:\r
-\r
- SnpNt32.c\r
-\r
-Abstract:\r
-\r
--**/\r
-\r
-#include "SnpNt32.h"\r
-\r
-EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding = {\r
- SnpNt32DriverBindingSupported,\r
- SnpNt32DriverBindingStart,\r
- SnpNt32DriverBindingStop,\r
- 0xa,\r
- NULL,\r
- NULL\r
-};\r
-\r
-SNPNT32_GLOBAL_DATA gSnpNt32GlobalData = {\r
- SNP_NT32_DRIVER_SIGNATURE, // Signature\r
- {\r
- NULL,\r
- NULL\r
- }, // InstanceList\r
- NULL, // WinNtThunk\r
- NULL, // NetworkLibraryHandle\r
- {\r
- 0\r
- }, // NtNetUtilityTable\r
- {\r
- 0,\r
- 0,\r
- EfiLockUninitialized\r
- }, // Lock\r
- //\r
- // Private functions\r
- //\r
- SnpNt32InitializeGlobalData, // InitializeGlobalData\r
- SnpNt32InitializeInstanceData, // InitializeInstanceData\r
- SnpNt32CloseInstance // CloseInstance\r
-};\r
-\r
-/**\r
- Changes the state of a network interface from "stopped" to "started".\r
-\r
- @param This Protocol instance pointer.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Start (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
- );\r
- \r
-/**\r
- Changes the state of a network interface from "started" to "stopped".\r
-\r
- @param This Protocol instance pointer.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Stop (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
- );\r
- \r
-/**\r
- Resets a network adapter and allocates the transmit and receive buffers \r
- required by the network interface; optionally, also requests allocation \r
- of additional transmit and receive buffers.\r
-\r
- @param This Protocol instance pointer.\r
- @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
- that the driver should allocate for the network interface.\r
- Some network interfaces will not be able to use the extra\r
- buffer, and the caller will not know if it is actually\r
- being used.\r
- @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
- that the driver should allocate for the network interface.\r
- Some network interfaces will not be able to use the extra\r
- buffer, and the caller will not know if it is actually\r
- being used.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Initialize (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN UINTN ExtraRxBufferSize OPTIONAL,\r
- IN UINTN ExtraTxBufferSize OPTIONAL\r
- );\r
- \r
-/**\r
- Resets a network adapter and re-initializes it with the parameters that were \r
- provided in the previous call to Initialize(). \r
-\r
- @param This Protocol instance pointer.\r
- @param ExtendedVerification Indicates that the driver may perform a more\r
- exhaustive verification operation of the device\r
- during reset.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Reset (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN ExtendedVerification\r
- );\r
-\r
-/**\r
- Resets a network adapter and leaves it in a state that is safe for \r
- another driver to initialize.\r
-\r
- @param This Protocol instance pointer.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Shutdown (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
- );\r
-\r
-/**\r
- Manages the multicast receive filters of a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param EnableBits A bit mask of receive filters to enable on the network interface.\r
- @param DisableBits A bit mask of receive filters to disable on the network interface.\r
- @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive\r
- filters on the network interface to their default values.\r
- @param McastFilterCount Number of multicast HW MAC addresses in the new\r
- MCastFilter list. This value must be less than or equal to\r
- the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r
- field is optional if ResetMCastFilter is TRUE.\r
- @param McastFilter A pointer to a list of new multicast receive filter HW MAC\r
- addresses. This list will replace any existing multicast\r
- HW MAC address list. This field is optional if\r
- ResetMCastFilter is TRUE.\r
-\r
- @retval EFI_SUCCESS The multicast receive filter list was updated.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32ReceiveFilters (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN UINT32 EnableBits,\r
- IN UINT32 DisableBits,\r
- IN BOOLEAN ResetMcastFilter,\r
- IN UINTN McastFilterCount OPTIONAL,\r
- IN EFI_MAC_ADDRESS *McastFilter OPTIONAL\r
- );\r
-\r
-/**\r
- Modifies or resets the current station address, if supported.\r
-\r
- @param This Protocol instance pointer.\r
- @param Reset Flag used to reset the station address to the network interfaces\r
- permanent address.\r
- @param NewMacAddr New station address to be used for the network interface.\r
-\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32StationAddress (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN Reset,\r
- IN EFI_MAC_ADDRESS *NewMacAddr OPTIONAL\r
- );\r
-\r
-/**\r
- Resets or collects the statistics on a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param Reset Set to TRUE to reset the statistics for the network interface.\r
- @param StatisticsSize On input the size, in bytes, of StatisticsTable. On\r
- output the size, in bytes, of the resulting table of\r
- statistics.\r
- @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
- contains the statistics.\r
-\r
- @retval EFI_SUCCESS The statistics were collected from the network interface.\r
- @retval EFI_NOT_STARTED The network interface has not been started.\r
- @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
- size needed to hold the statistics is returned in\r
- StatisticsSize.\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Statistics (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r
- IN BOOLEAN Reset,\r
- IN OUT UINTN *StatisticsSize OPTIONAL,\r
- OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL\r
- );\r
- \r
-/**\r
- Converts a multicast IP address to a multicast HW MAC address.\r
- \r
- @param This Protocol instance pointer.\r
- @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
- to FALSE if the multicast IP address is IPv4 [RFC 791].\r
- @param Ip The multicast IP address that is to be converted to a multicast\r
- HW MAC address.\r
- @param Mac The multicast HW MAC address that is to be generated from IP.\r
-\r
- @retval EFI_SUCCESS The multicast IP address was mapped to the multicast\r
- HW MAC address.\r
- @retval EFI_NOT_STARTED The network interface has not been started.\r
- @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
- size needed to hold the statistics is returned in\r
- StatisticsSize.\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32McastIptoMac (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN Ipv6,\r
- IN EFI_IP_ADDRESS *Ip,\r
- OUT EFI_MAC_ADDRESS *Mac\r
- );\r
-\r
-/**\r
- Performs read and write operations on the NVRAM device attached to a \r
- network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param ReadOrWrite TRUE for read operations, FALSE for write operations.\r
- @param Offset Byte offset in the NVRAM device at which to start the read or\r
- write operation. This must be a multiple of NvRamAccessSize and\r
- less than NvRamSize.\r
- @param BufferSize The number of bytes to read or write from the NVRAM device.\r
- This must also be a multiple of NvramAccessSize.\r
- @param Buffer A pointer to the data buffer.\r
-\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Nvdata (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN ReadOrWrite,\r
- IN UINTN Offset,\r
- IN UINTN BufferSize,\r
- IN OUT VOID *Buffer\r
- );\r
-\r
-/**\r
- Reads the current interrupt status and recycled transmit buffer status from \r
- a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param InterruptStatus A pointer to the bit mask of the currently active interrupts\r
- If this is NULL, the interrupt status will not be read from\r
- the device. If this is not NULL, the interrupt status will\r
- be read from the device. When the interrupt status is read,\r
- it will also be cleared. Clearing the transmit interrupt\r
- does not empty the recycled transmit buffer array.\r
- @param TxBuffer Recycled transmit buffer address. The network interface will\r
- not transmit if its internal recycled transmit buffer array\r
- is full. Reading the transmit buffer does not clear the\r
- transmit interrupt. If this is NULL, then the transmit buffer\r
- status will not be read. If there are no transmit buffers to\r
- recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32GetStatus (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- OUT UINT32 *InterruptStatus,\r
- OUT VOID **TxBuffer\r
- );\r
-\r
-/**\r
- Places a packet in the transmit queue of a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param HeaderSize The size, in bytes, of the media header to be filled in by\r
- the Transmit() function. If HeaderSize is non-zero, then it\r
- must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
- and Protocol parameters must not be NULL.\r
- @param BufferSize The size, in bytes, of the entire packet (media header and\r
- data) to be transmitted through the network interface.\r
- @param Buffer A pointer to the packet (media header followed by data) to be\r
- transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
- then the media header in Buffer must already be filled in by the\r
- caller. If HeaderSize is non-zero, then the media header will be\r
- filled in by the Transmit() function.\r
- @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter\r
- is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
- This->Mode->CurrentAddress is used for the source HW MAC address.\r
- @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this\r
- parameter is ignored.\r
- @param Protocol The type of header to build. If HeaderSize is zero, then this\r
- parameter is ignored. See RFC 1700, section "Ether Types", for\r
- examples.\r
-\r
- @retval EFI_SUCCESS The packet was placed on the transmit queue.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
- @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Transmit (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN UINTN HeaderSize,\r
- IN UINTN BufferSize,\r
- IN VOID *Buffer,\r
- IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r
- IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r
- IN UINT16 *Protocol OPTIONAL\r
- );\r
-\r
-/**\r
- Receives a packet from a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param HeaderSize The size, in bytes, of the media header received on the network\r
- interface. If this parameter is NULL, then the media header size\r
- will not be returned.\r
- @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
- bytes, of the packet that was received on the network interface.\r
- @param Buffer A pointer to the data buffer to receive both the media header and\r
- the data.\r
- @param SourceAddr The source HW MAC address. If this parameter is NULL, the\r
- HW MAC source address will not be extracted from the media\r
- header.\r
- @param DestinationAddr The destination HW MAC address. If this parameter is NULL,\r
- the HW MAC destination address will not be extracted from the\r
- media header.\r
- @param Protocol The media header type. If this parameter is NULL, then the\r
- protocol will not be extracted from the media header. See\r
- RFC 1700 section "Ether Types" for examples.\r
-\r
- @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has\r
- been updated to the number of bytes received.\r
- @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r
- request.\r
- @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
- @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Receive (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- OUT UINTN *HeaderSize,\r
- IN OUT UINTN *BuffSize,\r
- OUT VOID *Buffer,\r
- OUT EFI_MAC_ADDRESS *SourceAddr,\r
- OUT EFI_MAC_ADDRESS *DestinationAddr,\r
- OUT UINT16 *Protocol\r
- );\r
-\r
-SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = {\r
- SNP_NT32_INSTANCE_SIGNATURE, // Signature\r
- {\r
- NULL,\r
- NULL\r
- }, // Entry\r
- NULL, // RecycledTxBuf\r
- 0, // RecycledTxBufCount\r
- 32, // MaxRecycledTxBuf\r
- NULL, // GlobalData\r
- NULL, // DeviceHandle\r
- NULL, // DevicePath\r
- { // Snp\r
- EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, // Revision\r
- SnpNt32Start, // Start\r
- SnpNt32Stop, // Stop\r
- SnpNt32Initialize, // Initialize\r
- SnpNt32Reset, // Reset\r
- SnpNt32Shutdown, // Shutdown\r
- SnpNt32ReceiveFilters, // ReceiveFilters\r
- SnpNt32StationAddress, // StationAddress\r
- SnpNt32Statistics, // Statistics\r
- SnpNt32McastIptoMac, // MCastIpToMac\r
- SnpNt32Nvdata, // NvData\r
- SnpNt32GetStatus, // GetStatus\r
- SnpNt32Transmit, // Transmit\r
- SnpNt32Receive, // Receive\r
- NULL, // WaitForPacket\r
- NULL // Mode\r
- },\r
- { // Mode\r
- EfiSimpleNetworkInitialized, // State\r
- NET_ETHER_ADDR_LEN, // HwAddressSize\r
- NET_ETHER_HEADER_SIZE, // MediaHeaderSize\r
- 1500, // MaxPacketSize\r
- 0, // NvRamSize\r
- 0, // NvRamAccessSize\r
- 0, // ReceiveFilterMask\r
- 0, // ReceiveFilterSetting\r
- MAX_MCAST_FILTER_CNT, // MaxMCastFilterCount\r
- 0, // MCastFilterCount\r
- {\r
- 0\r
- }, // MCastFilter\r
- {\r
- 0\r
- }, // CurrentAddress\r
- {\r
- 0\r
- }, // BroadcastAddress\r
- {\r
- 0\r
- }, // PermanentAddress\r
- NET_IFTYPE_ETHERNET, // IfType\r
- FALSE, // MacAddressChangeable\r
- FALSE, // MultipleTxSupported\r
- TRUE, // MediaPresentSupported\r
- TRUE // MediaPresent\r
- },\r
- {\r
- 0\r
- } // InterfaceInfo\r
-};\r
-\r
-/**\r
- Test to see if this driver supports ControllerHandle. This service\r
- is called by the EFI boot service ConnectController(). In\r
- order to make drivers as small as possible, there are a few calling\r
- restrictions for this service. ConnectController() must\r
- follow these calling restrictions. If any other agent wishes to call\r
- Supported() it must also follow these calling restrictions.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to test\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS This driver supports this device\r
- @retval EFI_UNSUPPORTED This driver does not support this device\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32DriverBindingSupported (\r
- IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
- )\r
-{\r
-\r
- SNPNT32_GLOBAL_DATA *GlobalData;\r
- LIST_ENTRY *Entry;\r
- SNPNT32_INSTANCE_DATA *Instance;\r
-\r
- GlobalData = &gSnpNt32GlobalData;\r
-\r
- NET_LIST_FOR_EACH (Entry, &GlobalData->InstanceList) {\r
-\r
- Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
-\r
- if (Instance->DeviceHandle == ControllerHandle) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- }\r
-\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-/**\r
- Start this driver on ControllerHandle. This service is called by the\r
- EFI boot service ConnectController(). In order to make\r
- drivers as small as possible, there are a few calling restrictions for\r
- this service. ConnectController() must follow these\r
- calling restrictions. If any other agent wishes to call Start() it\r
- must also follow these calling restrictions.\r
-\r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to bind driver to\r
- @param RemainingDevicePath Optional parameter use to pick a specific child\r
- device to start.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32DriverBindingStart (\r
- IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Stop this driver on ControllerHandle. This service is called by the\r
- EFI boot service DisconnectController(). In order to\r
- make drivers as small as possible, there are a few calling\r
- restrictions for this service. DisconnectController()\r
- must follow these calling restrictions. If any other agent wishes\r
- to call Stop() it must also follow these calling restrictions.\r
- \r
- @param This Protocol instance pointer.\r
- @param ControllerHandle Handle of device to stop driver on\r
- @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
- children is zero stop the entire bus driver.\r
- @param ChildHandleBuffer List of Child Handles to Stop.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32DriverBindingStop (\r
- IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
- IN EFI_HANDLE ControllerHandle,\r
- IN UINTN NumberOfChildren,\r
- IN EFI_HANDLE *ChildHandleBuffer\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Changes the state of a network interface from "stopped" to "started".\r
-\r
- @param This Protocol instance pointer.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Start (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Changes the state of a network interface from "started" to "stopped".\r
-\r
- @param This Protocol instance pointer.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Stop (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Resets a network adapter and allocates the transmit and receive buffers \r
- required by the network interface; optionally, also requests allocation \r
- of additional transmit and receive buffers.\r
-\r
- @param This Protocol instance pointer.\r
- @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
- that the driver should allocate for the network interface.\r
- Some network interfaces will not be able to use the extra\r
- buffer, and the caller will not know if it is actually\r
- being used.\r
- @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
- that the driver should allocate for the network interface.\r
- Some network interfaces will not be able to use the extra\r
- buffer, and the caller will not know if it is actually\r
- being used.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Initialize (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN UINTN ExtraRxBufferSize OPTIONAL,\r
- IN UINTN ExtraTxBufferSize OPTIONAL\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Resets a network adapter and re-initializes it with the parameters that were \r
- provided in the previous call to Initialize(). \r
-\r
- @param This Protocol instance pointer.\r
- @param ExtendedVerification Indicates that the driver may perform a more\r
- exhaustive verification operation of the device\r
- during reset.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Reset (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN ExtendedVerification\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Resets a network adapter and leaves it in a state that is safe for \r
- another driver to initialize.\r
-\r
- @param This Protocol instance pointer.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Shutdown (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
- )\r
-{\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Manages the multicast receive filters of a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param EnableBits A bit mask of receive filters to enable on the network interface.\r
- @param DisableBits A bit mask of receive filters to disable on the network interface.\r
- @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive\r
- filters on the network interface to their default values.\r
- @param McastFilterCount Number of multicast HW MAC addresses in the new\r
- MCastFilter list. This value must be less than or equal to\r
- the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r
- field is optional if ResetMCastFilter is TRUE.\r
- @param McastFilter A pointer to a list of new multicast receive filter HW MAC\r
- addresses. This list will replace any existing multicast\r
- HW MAC address list. This field is optional if\r
- ResetMCastFilter is TRUE.\r
-\r
- @retval EFI_SUCCESS The multicast receive filter list was updated.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32ReceiveFilters (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN UINT32 EnableBits,\r
- IN UINT32 DisableBits,\r
- IN BOOLEAN ResetMcastFilter,\r
- IN UINTN McastFilterCount OPTIONAL,\r
- IN EFI_MAC_ADDRESS *McastFilter OPTIONAL\r
- )\r
-{\r
- SNPNT32_INSTANCE_DATA *Instance;\r
- SNPNT32_GLOBAL_DATA *GlobalData;\r
- INT32 ReturnValue;\r
-\r
- Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
-\r
- GlobalData = Instance->GlobalData;\r
-\r
- if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- ReturnValue = GlobalData->NtNetUtilityTable.SetReceiveFilter (\r
- Instance->InterfaceInfo.InterfaceIndex,\r
- EnableBits,\r
- (UINT32)McastFilterCount,\r
- McastFilter\r
- );\r
-\r
- EfiReleaseLock (&GlobalData->Lock);\r
-\r
- if (ReturnValue <= 0) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Modifies or resets the current station address, if supported.\r
-\r
- @param This Protocol instance pointer.\r
- @param Reset Flag used to reset the station address to the network interfaces\r
- permanent address.\r
- @param NewMacAddr New station address to be used for the network interface.\r
-\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32StationAddress (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN Reset,\r
- IN EFI_MAC_ADDRESS *NewMacAddr OPTIONAL\r
- )\r
-{\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
- Resets or collects the statistics on a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param Reset Set to TRUE to reset the statistics for the network interface.\r
- @param StatisticsSize On input the size, in bytes, of StatisticsTable. On\r
- output the size, in bytes, of the resulting table of\r
- statistics.\r
- @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
- contains the statistics.\r
-\r
- @retval EFI_SUCCESS The statistics were collected from the network interface.\r
- @retval EFI_NOT_STARTED The network interface has not been started.\r
- @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
- size needed to hold the statistics is returned in\r
- StatisticsSize.\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Statistics (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r
- IN BOOLEAN Reset,\r
- IN OUT UINTN *StatisticsSize OPTIONAL,\r
- OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL\r
- )\r
-{\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-/**\r
- Converts a multicast IP address to a multicast HW MAC address.\r
-\r
- @param This Protocol instance pointer.\r
- @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
- to FALSE if the multicast IP address is IPv4 [RFC 791].\r
- @param Ip The multicast IP address that is to be converted to a multicast\r
- HW MAC address.\r
- @param Mac The multicast HW MAC address that is to be generated from IP.\r
-\r
- @retval EFI_SUCCESS The multicast IP address was mapped to the multicast\r
- HW MAC address.\r
- @retval EFI_NOT_STARTED The network interface has not been started.\r
- @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
- size needed to hold the statistics is returned in\r
- StatisticsSize.\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32McastIptoMac (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN Ipv6,\r
- IN EFI_IP_ADDRESS *Ip,\r
- OUT EFI_MAC_ADDRESS *Mac\r
- )\r
-{\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-/**\r
- Performs read and write operations on the NVRAM device attached to a \r
- network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param ReadOrWrite TRUE for read operations, FALSE for write operations.\r
- @param Offset Byte offset in the NVRAM device at which to start the read or\r
- write operation. This must be a multiple of NvRamAccessSize and\r
- less than NvRamSize.\r
- @param BufferSize The number of bytes to read or write from the NVRAM device.\r
- This must also be a multiple of NvramAccessSize.\r
- @param Buffer A pointer to the data buffer.\r
-\r
- @retval EFI_UNSUPPORTED Not supported yet.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Nvdata (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN BOOLEAN ReadOrWrite,\r
- IN UINTN Offset,\r
- IN UINTN BufferSize,\r
- IN OUT VOID *Buffer\r
- )\r
-{\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-/**\r
- Reads the current interrupt status and recycled transmit buffer status from \r
- a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param InterruptStatus A pointer to the bit mask of the currently active interrupts\r
- If this is NULL, the interrupt status will not be read from\r
- the device. If this is not NULL, the interrupt status will\r
- be read from the device. When the interrupt status is read,\r
- it will also be cleared. Clearing the transmit interrupt\r
- does not empty the recycled transmit buffer array.\r
- @param TxBuffer Recycled transmit buffer address. The network interface will\r
- not transmit if its internal recycled transmit buffer array\r
- is full. Reading the transmit buffer does not clear the\r
- transmit interrupt. If this is NULL, then the transmit buffer\r
- status will not be read. If there are no transmit buffers to\r
- recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
-\r
- @retval EFI_SUCCESS Always succeeds.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32GetStatus (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- OUT UINT32 *InterruptStatus,\r
- OUT VOID **TxBuffer\r
- )\r
-{\r
- SNPNT32_INSTANCE_DATA *Instance;\r
-\r
- Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
-\r
- if (TxBuffer != NULL) {\r
- if (Instance->RecycledTxBufCount != 0) {\r
- Instance->RecycledTxBufCount --;\r
- *((UINT8 **) TxBuffer) = (UINT8 *) (UINTN)Instance->RecycledTxBuf[Instance->RecycledTxBufCount];\r
- } else {\r
- *((UINT8 **) TxBuffer) = NULL;\r
- }\r
- }\r
-\r
- if (InterruptStatus != NULL) {\r
- *InterruptStatus = EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
- Places a packet in the transmit queue of a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param HeaderSize The size, in bytes, of the media header to be filled in by\r
- the Transmit() function. If HeaderSize is non-zero, then it\r
- must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
- and Protocol parameters must not be NULL.\r
- @param BufferSize The size, in bytes, of the entire packet (media header and\r
- data) to be transmitted through the network interface.\r
- @param Buffer A pointer to the packet (media header followed by data) to be\r
- transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
- then the media header in Buffer must already be filled in by the\r
- caller. If HeaderSize is non-zero, then the media header will be\r
- filled in by the Transmit() function.\r
- @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter\r
- is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
- This->Mode->CurrentAddress is used for the source HW MAC address.\r
- @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this\r
- parameter is ignored.\r
- @param Protocol The type of header to build. If HeaderSize is zero, then this\r
- parameter is ignored. See RFC 1700, section "Ether Types", for\r
- examples.\r
-\r
- @retval EFI_SUCCESS The packet was placed on the transmit queue.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
- @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Transmit (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN UINTN HeaderSize,\r
- IN UINTN BufferSize,\r
- IN VOID *Buffer,\r
- IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r
- IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r
- IN UINT16 *Protocol OPTIONAL\r
- )\r
-{\r
- SNPNT32_INSTANCE_DATA *Instance;\r
- SNPNT32_GLOBAL_DATA *GlobalData;\r
- INT32 ReturnValue;\r
- UINT64 *Tmp;\r
-\r
- Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
-\r
- GlobalData = Instance->GlobalData;\r
-\r
- if ((HeaderSize != 0) && (SrcAddr == NULL)) {\r
- SrcAddr = &Instance->Mode.CurrentAddress;\r
- }\r
-\r
- if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- ReturnValue = GlobalData->NtNetUtilityTable.Transmit (\r
- Instance->InterfaceInfo.InterfaceIndex,\r
- (UINT32)HeaderSize,\r
- (UINT32)BufferSize,\r
- Buffer,\r
- SrcAddr,\r
- DestAddr,\r
- Protocol\r
- );\r
-\r
- EfiReleaseLock (&GlobalData->Lock);\r
-\r
- if (ReturnValue < 0) {\r
- return EFI_DEVICE_ERROR;\r
- } else {\r
- if ((Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) {\r
- return EFI_NOT_READY;\r
- }\r
-\r
- if (Instance->RecycledTxBufCount < Instance->MaxRecycledTxBuf) {\r
- Instance->RecycledTxBuf[Instance->RecycledTxBufCount] = (UINT64) Buffer;\r
- Instance->RecycledTxBufCount ++;\r
- } else {\r
- Tmp = AllocatePool (sizeof (UINT64) * (Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT));\r
- if (Tmp == NULL) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- CopyMem (Tmp, Instance->RecycledTxBuf, sizeof (UINT64) * Instance->RecycledTxBufCount);\r
- FreePool (Instance->RecycledTxBuf);\r
- Instance->RecycledTxBuf = Tmp;\r
- Instance->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT;\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Receives a packet from a network interface.\r
-\r
- @param This Protocol instance pointer.\r
- @param HeaderSize The size, in bytes, of the media header received on the network\r
- interface. If this parameter is NULL, then the media header size\r
- will not be returned.\r
- @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
- bytes, of the packet that was received on the network interface.\r
- @param Buffer A pointer to the data buffer to receive both the media header and\r
- the data.\r
- @param SourceAddr The source HW MAC address. If this parameter is NULL, the\r
- HW MAC source address will not be extracted from the media\r
- header.\r
- @param DestinationAddr The destination HW MAC address. If this parameter is NULL,\r
- the HW MAC destination address will not be extracted from the\r
- media header.\r
- @param Protocol The media header type. If this parameter is NULL, then the\r
- protocol will not be extracted from the media header. See\r
- RFC 1700 section "Ether Types" for examples.\r
-\r
- @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has\r
- been updated to the number of bytes received.\r
- @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r
- request.\r
- @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
- @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Receive (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- OUT UINTN *HeaderSize,\r
- IN OUT UINTN *BuffSize,\r
- OUT VOID *Buffer,\r
- OUT EFI_MAC_ADDRESS *SourceAddr,\r
- OUT EFI_MAC_ADDRESS *DestinationAddr,\r
- OUT UINT16 *Protocol\r
- )\r
-{\r
- SNPNT32_INSTANCE_DATA *Instance;\r
- SNPNT32_GLOBAL_DATA *GlobalData;\r
- INT32 ReturnValue;\r
- UINTN BufSize;\r
- \r
- BufSize = *BuffSize;\r
-\r
- Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
-\r
- GlobalData = Instance->GlobalData;\r
-\r
- ASSERT (GlobalData->NtNetUtilityTable.Receive != NULL);\r
-\r
- if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- ReturnValue = GlobalData->NtNetUtilityTable.Receive (\r
- Instance->InterfaceInfo.InterfaceIndex,\r
- BuffSize,\r
- Buffer\r
- );\r
-\r
- EfiReleaseLock (&GlobalData->Lock);\r
-\r
- if (ReturnValue < 0) {\r
- if (ReturnValue == -100) {\r
- return EFI_BUFFER_TOO_SMALL;\r
- }\r
-\r
- return EFI_DEVICE_ERROR;\r
- } else if (ReturnValue == 0) {\r
- return EFI_NOT_READY;\r
- }\r
-\r
- if (HeaderSize != NULL) {\r
- *HeaderSize = 14;\r
- }\r
-\r
- if (SourceAddr != NULL) {\r
- ZeroMem (SourceAddr, sizeof (EFI_MAC_ADDRESS));\r
- CopyMem (SourceAddr, ((UINT8 *) Buffer) + 6, 6);\r
- }\r
-\r
- if (DestinationAddr != NULL) {\r
- ZeroMem (DestinationAddr, sizeof (EFI_MAC_ADDRESS));\r
- CopyMem (DestinationAddr, ((UINT8 *) Buffer), 6);\r
- }\r
-\r
- if (Protocol != NULL) {\r
- *Protocol = NTOHS (*((UINT16 *) (((UINT8 *) Buffer) + 12)));\r
- }\r
-\r
- return (*BuffSize <= BufSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; \r
-}\r
-\r
-/**\r
- Initialize the driver's global data.\r
-\r
- @param This Pointer to the global context data.\r
-\r
- @retval EFI_SUCCESS The global data is initialized.\r
- @retval EFI_NOT_FOUND The required DLL is not found.\r
- @retval EFI_DEVICE_ERROR Error initialize network utility library.\r
- @retval EFI_OUT_OF_RESOURCES Out of resource.\r
- @retval other Other errors.\r
-\r
-**/\r
-EFI_STATUS\r
-SnpNt32InitializeGlobalData (\r
- IN OUT SNPNT32_GLOBAL_DATA *This\r
- )\r
-{\r
- EFI_STATUS Status;\r
- CHAR16 *DllFileNameU;\r
- UINT32 Index;\r
- INT32 ReturnValue;\r
- BOOLEAN NetUtilityLibInitDone;\r
- NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer[MAX_INTERFACE_INFO_NUMBER];\r
- SNPNT32_INSTANCE_DATA *Instance;\r
- LIST_ENTRY *Entry;\r
- UINT32 InterfaceCount;\r
-\r
- ASSERT (This != NULL);\r
-\r
- NetUtilityLibInitDone = FALSE;\r
- InterfaceCount = MAX_INTERFACE_INFO_NUMBER;\r
-\r
- InitializeListHead (&This->InstanceList);\r
- EfiInitializeLock (&This->Lock, TPL_CALLBACK);\r
-\r
- //\r
- // Get the WinNT thunk\r
- //\r
- Status = gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, (VOID **)&This->WinNtThunk);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- ASSERT (This->WinNtThunk != NULL);\r
-\r
- DllFileNameU = NETWORK_LIBRARY_NAME_U;\r
-\r
- //\r
- // Load network utility library\r
- //\r
- This->NetworkLibraryHandle = This->WinNtThunk->LoadLibraryEx (DllFileNameU, NULL, 0);\r
-\r
- if (NULL == This->NetworkLibraryHandle) {\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- This->NtNetUtilityTable.Initialize = (NT_NET_INITIALIZE) This->WinNtThunk->GetProcAddress (\r
- This->NetworkLibraryHandle,\r
- NETWORK_LIBRARY_INITIALIZE\r
- );\r
-\r
- if (NULL == This->NtNetUtilityTable.Initialize) {\r
- Status = EFI_NOT_FOUND;\r
- goto ErrorReturn;\r
- }\r
-\r
- This->NtNetUtilityTable.Finalize = (NT_NET_FINALIZE) This->WinNtThunk->GetProcAddress (\r
- This->NetworkLibraryHandle,\r
- NETWORK_LIBRARY_FINALIZE\r
- );\r
-\r
- if (NULL == This->NtNetUtilityTable.Finalize) {\r
- Status = EFI_NOT_FOUND;\r
- goto ErrorReturn;\r
- }\r
-\r
- This->NtNetUtilityTable.SetReceiveFilter = (NT_NET_SET_RECEIVE_FILTER) This->WinNtThunk->GetProcAddress (\r
- This->NetworkLibraryHandle,\r
- NETWORK_LIBRARY_SET_RCV_FILTER\r
- );\r
-\r
- if (NULL == This->NtNetUtilityTable.SetReceiveFilter) {\r
- Status = EFI_NOT_FOUND;\r
- goto ErrorReturn;\r
- }\r
-\r
- This->NtNetUtilityTable.Receive = (NT_NET_RECEIVE) This->WinNtThunk->GetProcAddress (\r
- This->NetworkLibraryHandle,\r
- NETWORK_LIBRARY_RECEIVE\r
- );\r
-\r
- if (NULL == This->NtNetUtilityTable.Receive) {\r
- Status = EFI_NOT_FOUND;\r
- goto ErrorReturn;\r
- }\r
-\r
- This->NtNetUtilityTable.Transmit = (NT_NET_TRANSMIT) This->WinNtThunk->GetProcAddress (\r
- This->NetworkLibraryHandle,\r
- NETWORK_LIBRARY_TRANSMIT\r
- );\r
-\r
- if (NULL == This->NtNetUtilityTable.Transmit) {\r
- Status = EFI_NOT_FOUND;\r
- goto ErrorReturn;\r
- }\r
- //\r
- // Initialize the network utility library\r
- // And enumerate the interfaces in NT32 host\r
- //\r
- ReturnValue = This->NtNetUtilityTable.Initialize (&InterfaceCount, &NetInterfaceInfoBuffer[0]);\r
- if (ReturnValue <= 0) {\r
- Status = EFI_DEVICE_ERROR;\r
- goto ErrorReturn;\r
- }\r
-\r
- NetUtilityLibInitDone = TRUE;\r
-\r
- if (InterfaceCount == 0) {\r
- Status = EFI_NOT_FOUND;\r
- goto ErrorReturn;\r
- }\r
- //\r
- // Create fake SNP instances\r
- //\r
- for (Index = 0; Index < InterfaceCount; Index++) {\r
-\r
- Instance = AllocateZeroPool (sizeof (SNPNT32_INSTANCE_DATA));\r
-\r
- if (NULL == Instance) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto ErrorReturn;\r
- }\r
- //\r
- // Copy the content from a template\r
- //\r
- CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA));\r
-\r
- //\r
- // Allocate the RecycledTxBuf.\r
- //\r
- Instance->RecycledTxBuf = AllocatePool (sizeof (UINT64) * Instance->MaxRecycledTxBuf);\r
- if (Instance->RecycledTxBuf == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- //\r
- // Set the interface information.\r
- //\r
- CopyMem (&Instance->InterfaceInfo, &NetInterfaceInfoBuffer[Index], sizeof(Instance->InterfaceInfo));\r
- //\r
- // Initialize this instance\r
- //\r
- Status = This->InitializeInstanceData (This, Instance);\r
- if (EFI_ERROR (Status)) {\r
-\r
- gBS->FreePool (Instance);\r
- goto ErrorReturn;\r
- }\r
- //\r
- // Insert this instance into the instance list\r
- //\r
- InsertTailList (&This->InstanceList, &Instance->Entry);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-\r
-ErrorReturn:\r
-\r
- while (!IsListEmpty (&This->InstanceList)) {\r
-\r
- Entry = This->InstanceList.ForwardLink;\r
-\r
- Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
-\r
- RemoveEntryList (Entry);\r
-\r
- This->CloseInstance (This, Instance);\r
- gBS->FreePool (Instance);\r
- }\r
-\r
- if (NetUtilityLibInitDone) {\r
-\r
- ASSERT (This->WinNtThunk != NULL);\r
-\r
- if (This->NtNetUtilityTable.Finalize != NULL) {\r
- This->NtNetUtilityTable.Finalize ();\r
- This->NtNetUtilityTable.Finalize = NULL;\r
- }\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Initialize the snpnt32 driver instance.\r
-\r
- @param This Pointer to the SnpNt32 global data.\r
- @param Instance Pointer to the instance context data.\r
-\r
- @retval EFI_SUCCESS The driver instance is initialized.\r
- @retval other Initialization errors.\r
-\r
-**/\r
-EFI_STATUS\r
-SnpNt32InitializeInstanceData (\r
- IN SNPNT32_GLOBAL_DATA *This,\r
- IN OUT SNPNT32_INSTANCE_DATA *Instance\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_DEV_PATH EndNode;\r
- EFI_DEV_PATH Node;\r
-\r
- Instance->GlobalData = This;\r
- Instance->Snp.Mode = &Instance->Mode;\r
- //\r
- // Set broadcast address\r
- //\r
- SetMem (&Instance->Mode.BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF);\r
-\r
- //\r
- // Copy Current/PermanentAddress MAC address\r
- //\r
- CopyMem (&Instance->Mode.CurrentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.CurrentAddress));\r
- CopyMem (&Instance->Mode.PermanentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.PermanentAddress));\r
-\r
- //\r
- // Since the fake SNP is based on a real NIC, to avoid conflict with the host\r
- // NIC network stack, we use a different MAC address.\r
- // So just change the last byte of the MAC address for the real NIC.\r
- //\r
- Instance->Mode.CurrentAddress.Addr[NET_ETHER_ADDR_LEN - 1]++;\r
-\r
- //\r
- // Create a fake device path for the instance\r
- //\r
- ZeroMem (&Node, sizeof (Node));\r
-\r
- Node.DevPath.Type = MESSAGING_DEVICE_PATH;\r
- Node.DevPath.SubType = MSG_MAC_ADDR_DP;\r
- SetDevicePathNodeLength (&Node.DevPath, sizeof (MAC_ADDR_DEVICE_PATH));\r
-\r
- CopyMem (\r
- &Node.MacAddr.MacAddress,\r
- &Instance->Mode.CurrentAddress,\r
- NET_ETHER_ADDR_LEN\r
- );\r
-\r
- Node.MacAddr.IfType = Instance->Mode.IfType;\r
-\r
- SetDevicePathEndNode (&EndNode.DevPath);\r
-\r
- Instance->DevicePath = AppendDevicePathNode (\r
- &EndNode.DevPath,\r
- &Node.DevPath\r
- );\r
-\r
- //\r
- // Create a fake device handle for the fake SNP\r
- //\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &Instance->DeviceHandle,\r
- &gEfiSimpleNetworkProtocolGuid,\r
- &Instance->Snp,\r
- &gEfiDevicePathProtocolGuid,\r
- Instance->DevicePath,\r
- NULL\r
- );\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Close the SnpNt32 driver instance.\r
-\r
- @param This Pointer to the SnpNt32 global data.\r
- @param Instance Pointer to the instance context data.\r
-\r
- @retval EFI_SUCCESS The instance is closed.\r
-\r
-**/\r
-EFI_STATUS\r
-SnpNt32CloseInstance (\r
- IN SNPNT32_GLOBAL_DATA *This,\r
- IN OUT SNPNT32_INSTANCE_DATA *Instance\r
- )\r
-{\r
- ASSERT (This != NULL);\r
- ASSERT (Instance != NULL);\r
-\r
- gBS->UninstallMultipleProtocolInterfaces (\r
- Instance->DeviceHandle,\r
- &gEfiSimpleNetworkProtocolGuid,\r
- &Instance->Snp,\r
- &gEfiDevicePathProtocolGuid,\r
- Instance->DevicePath,\r
- NULL\r
- );\r
-\r
- if (Instance->DevicePath != NULL) {\r
- gBS->FreePool (Instance->DevicePath);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Unloads an image.\r
-\r
- @param ImageHandle Handle that identifies the image to be unloaded.\r
-\r
- @retval EFI_SUCCESS The image has been unloaded.\r
- @return Exit code from the image's unload handler\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpNt32Unload (\r
- IN EFI_HANDLE ImageHandle\r
- )\r
-{\r
- EFI_STATUS Status;\r
- SNPNT32_GLOBAL_DATA *This;\r
- LIST_ENTRY *Entry;\r
- SNPNT32_INSTANCE_DATA *Instance;\r
-\r
- This = &gSnpNt32GlobalData;\r
-\r
- Status = NetLibDefaultUnload (ImageHandle);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- while (!IsListEmpty (&This->InstanceList)) {\r
- //\r
- // Walkthrough the interfaces and remove all the SNP instance\r
- //\r
- Entry = This->InstanceList.ForwardLink;\r
-\r
- Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
-\r
- RemoveEntryList (Entry);\r
-\r
- This->CloseInstance (This, Instance);\r
- gBS->FreePool (Instance);\r
- }\r
-\r
- if (This->NtNetUtilityTable.Finalize != NULL) {\r
- This->NtNetUtilityTable.Finalize ();\r
- }\r
-\r
- This->WinNtThunk->FreeLibrary (This->NetworkLibraryHandle);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- This is the declaration of an EFI image entry point. This entry point is\r
- the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
- both device drivers and bus drivers.\r
-\r
- @param ImageHandle The firmware allocated handle for the UEFI image.\r
- @param SystemTable A pointer to the EFI System Table.\r
-\r
- @retval EFI_SUCCESS The operation completed successfully.\r
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
-\r
-**/\r
-EFI_STATUS\r
-InitializeSnpNt32Driver (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
-\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Install the Driver Protocols\r
- //\r
-\r
- Status = EfiLibInstallDriverBindingComponentName2 (\r
- ImageHandle,\r
- SystemTable,\r
- &gSnpNt32DriverBinding,\r
- ImageHandle,\r
- &gSnpNt32DriverComponentName,\r
- &gSnpNt32DriverComponentName2\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- //\r
- // Initialize the global data\r
- //\r
- Status = SnpNt32InitializeGlobalData (&gSnpNt32GlobalData);\r
- if (EFI_ERROR (Status)) {\r
- SnpNt32Unload (ImageHandle);\r
- }\r
-\r
- return Status;\r
-}\r