1 /** @file 2 3 Copyright (c) 2006 - 2016, 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 8 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. 11 12 Module Name: 13 14 SnpNt32.h 15 16 Abstract: 17 18 -**/ 19 20 #ifndef _SNP_NT32_H_ 21 #define _SNP_NT32_H_ 22 23 #include <Uefi.h> 24 25 #include <Protocol/SimpleNetwork.h> 26 #include <Protocol/DevicePath.h> 27 #include <Protocol/WinNtThunk.h> 28 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> 37 38 typedef struct _SNPNT32_GLOBAL_DATA SNPNT32_GLOBAL_DATA; 39 typedef struct _SNPNT32_INSTANCE_DATA SNPNT32_INSTANCE_DATA; 40 41 #define NETWORK_LIBRARY_NAME_U L"SnpNt32Io.dll" 42 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" 48 49 #pragma pack(1) 50 typedef struct _NT_NET_INTERFACE_INFO { 51 UINT32 InterfaceIndex; 52 EFI_MAC_ADDRESS MacAddr; 53 } NT_NET_INTERFACE_INFO; 54 #pragma pack() 55 56 #define NET_ETHER_HEADER_SIZE 14 57 58 #define MAX_INTERFACE_INFO_NUMBER 16 59 #define MAX_FILE_NAME_LENGTH 280 60 61 #define SNP_MAX_TX_BUFFER_NUM 65536 62 #define SNP_TX_BUFFER_INCREASEMENT 32 63 64 65 66 67 // 68 // Functions in Net Library 69 // 70 typedef 71 INT32 72 (*NT_NET_INITIALIZE) ( 73 IN OUT UINT32 *InterfaceCount, 74 IN OUT NT_NET_INTERFACE_INFO * InterfaceInfoBuffer 75 ); 76 77 typedef 78 INT32 79 (*NT_NET_FINALIZE) ( 80 VOID 81 ); 82 83 typedef 84 INT32 85 (*NT_NET_SET_RECEIVE_FILTER) ( 86 IN UINT32 Index, 87 IN UINT32 EnableFilter, 88 IN UINT32 MCastFilterCnt, 89 IN EFI_MAC_ADDRESS * MCastFilter 90 ); 91 92 typedef 93 INT32 94 (*NT_NET_RECEIVE) ( 95 IN UINT32 Index, 96 IN OUT UINT32 *BufferSize, 97 OUT VOID *Buffer 98 ); 99 100 typedef 101 INT32 102 (*NT_NET_TRANSMIT) ( 103 IN UINT32 Index, 104 IN UINT32 HeaderSize, 105 IN UINT32 BufferSize, 106 IN VOID *Buffer, 107 IN EFI_MAC_ADDRESS * SrcAddr, 108 IN EFI_MAC_ADDRESS * DestAddr, 109 IN UINT16 *Protocol 110 ); 111 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; 119 120 // 121 // Private functions 122 // 123 typedef 124 EFI_STATUS 125 (*SNPNT32_INITIALIZE_GLOBAL_DATA) ( 126 IN SNPNT32_GLOBAL_DATA * This 127 ); 128 129 typedef 130 EFI_STATUS 131 (*SNPNT32_INITIALIZE_INSTANCE_DATA) ( 132 IN SNPNT32_GLOBAL_DATA * This, 133 IN SNPNT32_INSTANCE_DATA * Instance 134 ); 135 136 typedef 137 EFI_STATUS 138 (*SNPNT32_CLOSE_INSTANCE) ( 139 IN SNPNT32_GLOBAL_DATA * This, 140 IN SNPNT32_INSTANCE_DATA * Instance 141 ); 142 143 // 144 // Global data for this driver 145 // 146 #define SNP_NT32_DRIVER_SIGNATURE SIGNATURE_32 ('W', 'S', 'N', 'P') 147 148 struct _SNPNT32_GLOBAL_DATA { 149 UINT32 Signature; 150 151 // 152 // List for all the fake SNP instance 153 // 154 LIST_ENTRY InstanceList; 155 156 EFI_WIN_NT_THUNK_PROTOCOL *WinNtThunk; 157 HMODULE NetworkLibraryHandle; 158 159 NT_NET_UTILITY_TABLE NtNetUtilityTable; 160 161 EFI_LOCK Lock; 162 163 // 164 // Array of the recycled transmit buffer address. 165 // 166 UINT64 *RecycledTxBuf; 167 168 // 169 // Current number of recycled buffer pointers in RecycledTxBuf. 170 // 171 UINT32 RecycledTxBufCount; 172 173 // The maximum number of recycled buffer pointers in RecycledTxBuf. 174 // 175 UINT32 MaxRecycledTxBuf; 176 177 // 178 // Private functions 179 // 180 SNPNT32_INITIALIZE_GLOBAL_DATA InitializeGlobalData; 181 SNPNT32_INITIALIZE_INSTANCE_DATA InitializeInstanceData; 182 SNPNT32_CLOSE_INSTANCE CloseInstance; 183 }; 184 185 // 186 // Instance data for each fake SNP instance 187 // 188 #define SNP_NT32_INSTANCE_SIGNATURE SIGNATURE_32 ('w', 'S', 'N', 'P') 189 190 struct _SNPNT32_INSTANCE_DATA { 191 UINT32 Signature; 192 193 // 194 // List entry use for linking with other instance 195 // 196 LIST_ENTRY Entry; 197 198 SNPNT32_GLOBAL_DATA *GlobalData; 199 200 EFI_HANDLE DeviceHandle; 201 EFI_DEVICE_PATH_PROTOCOL *DevicePath; 202 203 EFI_SIMPLE_NETWORK_PROTOCOL Snp; 204 EFI_SIMPLE_NETWORK_MODE Mode; 205 206 NT_NET_INTERFACE_INFO InterfaceInfo; 207 208 // 209 // Private functions 210 // 211 }; 212 213 #define SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS(a) \ 214 CR ( \ 215 a, \ 216 SNPNT32_INSTANCE_DATA, \ 217 Snp, \ 218 SNP_NT32_INSTANCE_SIGNATURE \ 219 ) 220 221 extern EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding; 222 extern EFI_COMPONENT_NAME_PROTOCOL gSnpNt32DriverComponentName; 223 extern EFI_COMPONENT_NAME2_PROTOCOL gSnpNt32DriverComponentName2; 224 225 /** 226 Test to see if this driver supports ControllerHandle. This service 227 is called by the EFI boot service ConnectController(). In 228 order to make drivers as small as possible, there are a few calling 229 restrictions for this service. ConnectController() must 230 follow these calling restrictions. If any other agent wishes to call 231 Supported() it must also follow these calling restrictions. 232 233 @param This Protocol instance pointer. 234 @param ControllerHandle Handle of device to test 235 @param RemainingDevicePath Optional parameter use to pick a specific child 236 device to start. 237 238 @retval EFI_SUCCESS This driver supports this device 239 @retval EFI_UNSUPPORTED This driver does not support this device 240 241 **/ 242 EFI_STATUS 243 EFIAPI 244 SnpNt32DriverBindingSupported ( 245 IN EFI_DRIVER_BINDING_PROTOCOL * This, 246 IN EFI_HANDLE ControllerHandle, 247 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL 248 ); 249 250 /** 251 Start this driver on ControllerHandle. This service is called by the 252 EFI boot service ConnectController(). In order to make 253 drivers as small as possible, there are a few calling restrictions for 254 this service. ConnectController() must follow these 255 calling restrictions. If any other agent wishes to call Start() it 256 must also follow these calling restrictions. 257 258 @param This Protocol instance pointer. 259 @param ControllerHandle Handle of device to bind driver to 260 @param RemainingDevicePath Optional parameter use to pick a specific child 261 device to start. 262 263 @retval EFI_SUCCESS Always succeeds. 264 265 **/ 266 EFI_STATUS 267 EFIAPI 268 SnpNt32DriverBindingStart ( 269 IN EFI_DRIVER_BINDING_PROTOCOL * This, 270 IN EFI_HANDLE ControllerHandle, 271 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL 272 ); 273 274 /** 275 Stop this driver on ControllerHandle. This service is called by the 276 EFI boot service DisconnectController(). In order to 277 make drivers as small as possible, there are a few calling 278 restrictions for this service. DisconnectController() 279 must follow these calling restrictions. If any other agent wishes 280 to call Stop() it must also follow these calling restrictions. 281 282 @param This Protocol instance pointer. 283 @param ControllerHandle Handle of device to stop driver on 284 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of 285 children is zero stop the entire bus driver. 286 @param ChildHandleBuffer List of Child Handles to Stop. 287 288 @retval EFI_SUCCESS Always succeeds. 289 290 **/ 291 EFI_STATUS 292 EFIAPI 293 SnpNt32DriverBindingStop ( 294 IN EFI_DRIVER_BINDING_PROTOCOL *This, 295 IN EFI_HANDLE ControllerHandle, 296 IN UINTN NumberOfChildren, 297 IN EFI_HANDLE *ChildHandleBuffer 298 ); 299 300 /** 301 Initialize the driver's global data. 302 303 @param This Pointer to the global context data. 304 305 @retval EFI_SUCCESS The global data is initialized. 306 @retval EFI_NOT_FOUND The required DLL is not found. 307 @retval EFI_DEVICE_ERROR Error initialize network utility library. 308 @retval EFI_OUT_OF_RESOURCES Out of resource. 309 @retval other Other errors. 310 311 **/ 312 EFI_STATUS 313 SnpNt32InitializeGlobalData ( 314 IN OUT SNPNT32_GLOBAL_DATA *This 315 ); 316 317 /** 318 Initialize the snpnt32 driver instance. 319 320 @param This Pointer to the SnpNt32 global data. 321 @param Instance Pointer to the instance context data. 322 323 @retval EFI_SUCCESS The driver instance is initialized. 324 @retval other Initialization errors. 325 326 **/ 327 EFI_STATUS 328 SnpNt32InitializeInstanceData ( 329 IN SNPNT32_GLOBAL_DATA *This, 330 IN OUT SNPNT32_INSTANCE_DATA *Instance 331 ); 332 333 /** 334 Close the SnpNt32 driver instance. 335 336 @param This Pointer to the SnpNt32 global data. 337 @param Instance Pointer to the instance context data. 338 339 @retval EFI_SUCCESS The instance is closed. 340 341 **/ 342 EFI_STATUS 343 SnpNt32CloseInstance ( 344 IN SNPNT32_GLOBAL_DATA *This, 345 IN OUT SNPNT32_INSTANCE_DATA *Instance 346 ); 347 348 #endif 349