3 Copyright (c) 2006 - 2007, 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.
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
62 // Functions in Net Library
66 (*NT_NET_INITIALIZE
) (
67 IN OUT UINT32
*InterfaceCount
,
68 IN OUT NT_NET_INTERFACE_INFO
* InterfaceInfoBuffer
79 (*NT_NET_SET_RECEIVE_FILTER
) (
81 IN UINT32 EnableFilter
,
82 IN UINT32 MCastFilterCnt
,
83 IN EFI_MAC_ADDRESS
* MCastFilter
90 IN OUT UINT32
*BufferSize
,
101 IN EFI_MAC_ADDRESS
* SrcAddr
,
102 IN EFI_MAC_ADDRESS
* DestAddr
,
106 typedef struct _NT_NET_UTILITY_TABLE
{
107 NT_NET_INITIALIZE Initialize
;
108 NT_NET_FINALIZE Finalize
;
109 NT_NET_SET_RECEIVE_FILTER SetReceiveFilter
;
110 NT_NET_RECEIVE Receive
;
111 NT_NET_TRANSMIT Transmit
;
112 } NT_NET_UTILITY_TABLE
;
119 (*SNPNT32_INITIALIZE_GLOBAL_DATA
) (
120 IN SNPNT32_GLOBAL_DATA
* This
125 (*SNPNT32_INITIALIZE_INSTANCE_DATA
) (
126 IN SNPNT32_GLOBAL_DATA
* This
,
127 IN SNPNT32_INSTANCE_DATA
* Instance
132 (*SNPNT32_CLOSE_INSTANCE
) (
133 IN SNPNT32_GLOBAL_DATA
* This
,
134 IN SNPNT32_INSTANCE_DATA
* Instance
138 // Global data for this driver
140 #define SNP_NT32_DRIVER_SIGNATURE SIGNATURE_32 ('W', 'S', 'N', 'P')
142 struct _SNPNT32_GLOBAL_DATA
{
146 // List for all the fake SNP instance
148 LIST_ENTRY InstanceList
;
150 EFI_WIN_NT_THUNK_PROTOCOL
*WinNtThunk
;
151 HMODULE NetworkLibraryHandle
;
153 NT_NET_UTILITY_TABLE NtNetUtilityTable
;
160 SNPNT32_INITIALIZE_GLOBAL_DATA InitializeGlobalData
;
161 SNPNT32_INITIALIZE_INSTANCE_DATA InitializeInstanceData
;
162 SNPNT32_CLOSE_INSTANCE CloseInstance
;
166 // Instance data for each fake SNP instance
168 #define SNP_NT32_INSTANCE_SIGNATURE SIGNATURE_32 ('w', 'S', 'N', 'P')
170 struct _SNPNT32_INSTANCE_DATA
{
174 // List entry use for linking with other instance
178 SNPNT32_GLOBAL_DATA
*GlobalData
;
180 EFI_HANDLE DeviceHandle
;
181 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
183 EFI_SIMPLE_NETWORK_PROTOCOL Snp
;
184 EFI_SIMPLE_NETWORK_MODE Mode
;
186 NT_NET_INTERFACE_INFO InterfaceInfo
;
193 #define SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS(a) \
196 SNPNT32_INSTANCE_DATA, \
198 SNP_NT32_INSTANCE_SIGNATURE \
201 extern EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding
;
202 extern EFI_COMPONENT_NAME_PROTOCOL gSnpNt32DriverComponentName
;
203 extern EFI_COMPONENT_NAME2_PROTOCOL gSnpNt32DriverComponentName2
;
206 Test to see if this driver supports ControllerHandle. This service
207 is called by the EFI boot service ConnectController(). In
208 order to make drivers as small as possible, there are a few calling
209 restrictions for this service. ConnectController() must
210 follow these calling restrictions. If any other agent wishes to call
211 Supported() it must also follow these calling restrictions.
213 @param This Protocol instance pointer.
214 @param ControllerHandle Handle of device to test
215 @param RemainingDevicePath Optional parameter use to pick a specific child
218 @retval EFI_SUCCESS This driver supports this device
219 @retval EFI_UNSUPPORTED This driver does not support this device
224 SnpNt32DriverBindingSupported (
225 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
226 IN EFI_HANDLE ControllerHandle
,
227 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
231 Start this driver on ControllerHandle. This service is called by the
232 EFI boot service ConnectController(). In order to make
233 drivers as small as possible, there are a few calling restrictions for
234 this service. ConnectController() must follow these
235 calling restrictions. If any other agent wishes to call Start() it
236 must also follow these calling restrictions.
238 @param This Protocol instance pointer.
239 @param ControllerHandle Handle of device to bind driver to
240 @param RemainingDevicePath Optional parameter use to pick a specific child
243 @retval EFI_SUCCESS Always succeeds.
248 SnpNt32DriverBindingStart (
249 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
250 IN EFI_HANDLE ControllerHandle
,
251 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
255 Stop this driver on ControllerHandle. This service is called by the
256 EFI boot service DisconnectController(). In order to
257 make drivers as small as possible, there are a few calling
258 restrictions for this service. DisconnectController()
259 must follow these calling restrictions. If any other agent wishes
260 to call Stop() it must also follow these calling restrictions.
262 @param This Protocol instance pointer.
263 @param ControllerHandle Handle of device to stop driver on
264 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
265 children is zero stop the entire bus driver.
266 @param ChildHandleBuffer List of Child Handles to Stop.
268 @retval EFI_SUCCESS Always succeeds.
273 SnpNt32DriverBindingStop (
274 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
275 IN EFI_HANDLE ControllerHandle
,
276 IN UINTN NumberOfChildren
,
277 IN EFI_HANDLE
*ChildHandleBuffer
281 Initialize the driver's global data.
283 @param This Pointer to the global context data.
285 @retval EFI_SUCCESS The global data is initialized.
286 @retval EFI_NOT_FOUND The required DLL is not found.
287 @retval EFI_DEVICE_ERROR Error initialize network utility library.
288 @retval EFI_OUT_OF_RESOURCES Out of resource.
289 @retval other Other errors.
293 SnpNt32InitializeGlobalData (
294 IN OUT SNPNT32_GLOBAL_DATA
*This
298 Initialize the snpnt32 driver instance.
300 @param This Pointer to the SnpNt32 global data.
301 @param Instance Pointer to the instance context data.
303 @retval EFI_SUCCESS The driver instance is initialized.
304 @retval other Initialization errors.
308 SnpNt32InitializeInstanceData (
309 IN SNPNT32_GLOBAL_DATA
*This
,
310 IN OUT SNPNT32_INSTANCE_DATA
*Instance
314 Close the SnpNt32 driver instance.
316 @param This Pointer to the SnpNt32 global data.
317 @param Instance Pointer to the instance context data.
319 @retval EFI_SUCCESS The instance is closed.
323 SnpNt32CloseInstance (
324 IN SNPNT32_GLOBAL_DATA
*This
,
325 IN OUT SNPNT32_INSTANCE_DATA
*Instance