3 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 #include <Protocol/SimpleNetwork.h>
26 #include <Protocol/DevicePath.h>
27 #include <Protocol/WinNtThunk.h>
29 #include <Library/BaseLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/NetLib.h>
36 #include <Library/MemoryAllocationLib.h>
38 typedef struct _SNPNT32_GLOBAL_DATA SNPNT32_GLOBAL_DATA
;
39 typedef struct _SNPNT32_INSTANCE_DATA SNPNT32_INSTANCE_DATA
;
41 #define NETWORK_LIBRARY_NAME_U L"SnpNt32Io.dll"
43 #define NETWORK_LIBRARY_INITIALIZE "SnpInitialize"
44 #define NETWORK_LIBRARY_FINALIZE "SnpFinalize"
45 #define NETWORK_LIBRARY_SET_RCV_FILTER "SnpSetReceiveFilter"
46 #define NETWORK_LIBRARY_RECEIVE "SnpReceive"
47 #define NETWORK_LIBRARY_TRANSMIT "SnpTransmit"
50 typedef struct _NT_NET_INTERFACE_INFO
{
51 UINT32 InterfaceIndex
;
52 EFI_MAC_ADDRESS MacAddr
;
53 } NT_NET_INTERFACE_INFO
;
56 #define NET_ETHER_HEADER_SIZE 14
58 #define MAX_INTERFACE_INFO_NUMBER 16
59 #define MAX_FILE_NAME_LENGTH 280
61 #define SNP_MAX_TX_BUFFER_NUM 65536
62 #define SNP_TX_BUFFER_INCREASEMENT 32
68 // Functions in Net Library
72 (*NT_NET_INITIALIZE
) (
73 IN OUT UINT32
*InterfaceCount
,
74 IN OUT NT_NET_INTERFACE_INFO
* InterfaceInfoBuffer
85 (*NT_NET_SET_RECEIVE_FILTER
) (
87 IN UINT32 EnableFilter
,
88 IN UINT32 MCastFilterCnt
,
89 IN EFI_MAC_ADDRESS
* MCastFilter
96 IN OUT UINT32
*BufferSize
,
104 IN UINT32 HeaderSize
,
105 IN UINT32 BufferSize
,
107 IN EFI_MAC_ADDRESS
* SrcAddr
,
108 IN EFI_MAC_ADDRESS
* DestAddr
,
112 typedef struct _NT_NET_UTILITY_TABLE
{
113 NT_NET_INITIALIZE Initialize
;
114 NT_NET_FINALIZE Finalize
;
115 NT_NET_SET_RECEIVE_FILTER SetReceiveFilter
;
116 NT_NET_RECEIVE Receive
;
117 NT_NET_TRANSMIT Transmit
;
118 } NT_NET_UTILITY_TABLE
;
125 (*SNPNT32_INITIALIZE_GLOBAL_DATA
) (
126 IN SNPNT32_GLOBAL_DATA
* This
131 (*SNPNT32_INITIALIZE_INSTANCE_DATA
) (
132 IN SNPNT32_GLOBAL_DATA
* This
,
133 IN SNPNT32_INSTANCE_DATA
* Instance
138 (*SNPNT32_CLOSE_INSTANCE
) (
139 IN SNPNT32_GLOBAL_DATA
* This
,
140 IN SNPNT32_INSTANCE_DATA
* Instance
144 // Global data for this driver
146 #define SNP_NT32_DRIVER_SIGNATURE SIGNATURE_32 ('W', 'S', 'N', 'P')
148 struct _SNPNT32_GLOBAL_DATA
{
152 // List for all the fake SNP instance
154 LIST_ENTRY InstanceList
;
156 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
157 HMODULE NetworkLibraryHandle
;
159 NT_NET_UTILITY_TABLE NtNetUtilityTable
;
166 SNPNT32_INITIALIZE_GLOBAL_DATA InitializeGlobalData
;
167 SNPNT32_INITIALIZE_INSTANCE_DATA InitializeInstanceData
;
168 SNPNT32_CLOSE_INSTANCE CloseInstance
;
172 // Instance data for each fake SNP instance
174 #define SNP_NT32_INSTANCE_SIGNATURE SIGNATURE_32 ('w', 'S', 'N', 'P')
176 struct _SNPNT32_INSTANCE_DATA
{
180 // List entry use for linking with other instance
185 // Array of the recycled transmit buffer address.
187 UINT64
*RecycledTxBuf
;
190 // Current number of recycled buffer pointers in RecycledTxBuf.
192 UINT32 RecycledTxBufCount
;
195 // The maximum number of recycled buffer pointers in RecycledTxBuf.
197 UINT32 MaxRecycledTxBuf
;
199 SNPNT32_GLOBAL_DATA
*GlobalData
;
201 EFI_HANDLE DeviceHandle
;
202 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
204 EFI_SIMPLE_NETWORK_PROTOCOL Snp
;
205 EFI_SIMPLE_NETWORK_MODE Mode
;
207 NT_NET_INTERFACE_INFO InterfaceInfo
;
214 #define SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS(a) \
217 SNPNT32_INSTANCE_DATA, \
219 SNP_NT32_INSTANCE_SIGNATURE \
222 extern EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding
;
223 extern EFI_COMPONENT_NAME_PROTOCOL gSnpNt32DriverComponentName
;
224 extern EFI_COMPONENT_NAME2_PROTOCOL gSnpNt32DriverComponentName2
;
227 Test to see if this driver supports ControllerHandle. This service
228 is called by the EFI boot service ConnectController(). In
229 order to make drivers as small as possible, there are a few calling
230 restrictions for this service. ConnectController() must
231 follow these calling restrictions. If any other agent wishes to call
232 Supported() it must also follow these calling restrictions.
234 @param This Protocol instance pointer.
235 @param ControllerHandle Handle of device to test
236 @param RemainingDevicePath Optional parameter use to pick a specific child
239 @retval EFI_SUCCESS This driver supports this device
240 @retval EFI_UNSUPPORTED This driver does not support this device
245 SnpNt32DriverBindingSupported (
246 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
247 IN EFI_HANDLE ControllerHandle
,
248 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
252 Start this driver on ControllerHandle. This service is called by the
253 EFI boot service ConnectController(). In order to make
254 drivers as small as possible, there are a few calling restrictions for
255 this service. ConnectController() must follow these
256 calling restrictions. If any other agent wishes to call Start() it
257 must also follow these calling restrictions.
259 @param This Protocol instance pointer.
260 @param ControllerHandle Handle of device to bind driver to
261 @param RemainingDevicePath Optional parameter use to pick a specific child
264 @retval EFI_SUCCESS Always succeeds.
269 SnpNt32DriverBindingStart (
270 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
271 IN EFI_HANDLE ControllerHandle
,
272 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
276 Stop this driver on ControllerHandle. This service is called by the
277 EFI boot service DisconnectController(). In order to
278 make drivers as small as possible, there are a few calling
279 restrictions for this service. DisconnectController()
280 must follow these calling restrictions. If any other agent wishes
281 to call Stop() it must also follow these calling restrictions.
283 @param This Protocol instance pointer.
284 @param ControllerHandle Handle of device to stop driver on
285 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
286 children is zero stop the entire bus driver.
287 @param ChildHandleBuffer List of Child Handles to Stop.
289 @retval EFI_SUCCESS Always succeeds.
294 SnpNt32DriverBindingStop (
295 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
296 IN EFI_HANDLE ControllerHandle
,
297 IN UINTN NumberOfChildren
,
298 IN EFI_HANDLE
*ChildHandleBuffer
302 Initialize the driver's global data.
304 @param This Pointer to the global context data.
306 @retval EFI_SUCCESS The global data is initialized.
307 @retval EFI_NOT_FOUND The required DLL is not found.
308 @retval EFI_DEVICE_ERROR Error initialize network utility library.
309 @retval EFI_OUT_OF_RESOURCES Out of resource.
310 @retval other Other errors.
314 SnpNt32InitializeGlobalData (
315 IN OUT SNPNT32_GLOBAL_DATA
*This
319 Initialize the snpnt32 driver instance.
321 @param This Pointer to the SnpNt32 global data.
322 @param Instance Pointer to the instance context data.
324 @retval EFI_SUCCESS The driver instance is initialized.
325 @retval other Initialization errors.
329 SnpNt32InitializeInstanceData (
330 IN SNPNT32_GLOBAL_DATA
*This
,
331 IN OUT SNPNT32_INSTANCE_DATA
*Instance
335 Close the SnpNt32 driver instance.
337 @param This Pointer to the SnpNt32 global data.
338 @param Instance Pointer to the instance context data.
340 @retval EFI_SUCCESS The instance is closed.
344 SnpNt32CloseInstance (
345 IN SNPNT32_GLOBAL_DATA
*This
,
346 IN OUT SNPNT32_INSTANCE_DATA
*Instance