]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/IScsiDxe/IScsiMisc.h
CryptoPkg/OpensslLib: introduce OpensslLibCrypto instance
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiMisc.h
CommitLineData
4c5a5e0c 1/** @file\r
2 Miscellaneous definitions for iSCSI driver.\r
3\r
eabc6e59 4Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
4c5a5e0c 5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _ISCSI_MISC_H_\r
16#define _ISCSI_MISC_H_\r
17\r
18typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA;\r
19\r
42f0586d 20///\r
21/// IPv4 Device Path Node Length\r
22///\r
5ae7578a 23#define IP4_NODE_LEN_NEW_VERSIONS 27\r
42f0586d 24\r
25///\r
26/// IPv6 Device Path Node Length\r
27///\r
5ae7578a 28#define IP6_NODE_LEN_OLD_VERSIONS 43\r
29#define IP6_NODE_LEN_NEW_VERSIONS 60\r
42f0586d 30\r
31///\r
32/// The ignored field StaticIpAddress's offset in old IPv6 Device Path\r
33///\r
5ae7578a 34#define IP6_OLD_IPADDRESS_OFFSET 42\r
42f0586d 35\r
eabc6e59 36\r
4c5a5e0c 37#pragma pack(1)\r
38typedef struct _ISCSI_SESSION_CONFIG_NVDATA {\r
39 UINT16 TargetPort;\r
40 UINT8 Enabled;\r
41 UINT8 IpMode;\r
42\r
75dce340 43 EFI_IP_ADDRESS LocalIp;\r
4c5a5e0c 44 EFI_IPv4_ADDRESS SubnetMask;\r
75dce340 45 EFI_IP_ADDRESS Gateway;\r
4c5a5e0c 46\r
47 BOOLEAN InitiatorInfoFromDhcp;\r
48 BOOLEAN TargetInfoFromDhcp;\r
eabc6e59 49\r
4c5a5e0c 50 CHAR8 TargetName[ISCSI_NAME_MAX_SIZE];\r
51 EFI_IP_ADDRESS TargetIp;\r
75dce340 52 UINT8 PrefixLength;\r
4c5a5e0c 53 UINT8 BootLun[8];\r
54\r
a2d59ef2 55 UINT16 ConnectTimeout; ///< timout value in milliseconds.\r
4c5a5e0c 56 UINT8 ConnectRetryCount;\r
57 UINT8 IsId[6];\r
a2d59ef2
YT
58\r
59 BOOLEAN RedirectFlag;\r
60 UINT16 OriginalTargetPort; // The port of proxy/virtual target.\r
61 EFI_IP_ADDRESS OriginalTargetIp; // The address of proxy/virtual target.\r
eabc6e59
ZL
62\r
63 BOOLEAN DnsMode; // Flag indicate whether the Target address is expressed as URL format.\r
64 CHAR8 TargetUrl[ISCSI_TARGET_URI_MAX_SIZE];\r
a2d59ef2 65 \r
4c5a5e0c 66} ISCSI_SESSION_CONFIG_NVDATA;\r
67#pragma pack()\r
68\r
69/**\r
70 Calculate the prefix length of the IPv4 subnet mask.\r
71\r
72 @param[in] SubnetMask The IPv4 subnet mask.\r
73\r
74 @return The prefix length of the subnet mask.\r
75 @retval 0 Other errors as indicated.\r
76\r
77**/\r
78UINT8\r
79IScsiGetSubnetMaskPrefixLength (\r
80 IN EFI_IPv4_ADDRESS *SubnetMask\r
81 );\r
82\r
83/**\r
84 Convert the hexadecimal encoded LUN string into the 64-bit LUN. \r
85\r
86 @param[in] Str The hexadecimal encoded LUN string.\r
87 @param[out] Lun Storage to return the 64-bit LUN.\r
88\r
89 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.\r
90 @retval EFI_INVALID_PARAMETER The string is malformatted.\r
91\r
92**/\r
93EFI_STATUS\r
94IScsiAsciiStrToLun (\r
95 IN CHAR8 *Str,\r
96 OUT UINT8 *Lun\r
97 );\r
98\r
99/**\r
100 Convert the 64-bit LUN into the hexadecimal encoded LUN string.\r
101\r
102 @param[in] Lun The 64-bit LUN.\r
103 @param[out] String The storage to return the hexadecimal encoded LUN string.\r
104\r
105**/\r
106VOID\r
107IScsiLunToUnicodeStr (\r
108 IN UINT8 *Lun,\r
109 OUT CHAR16 *String\r
110 );\r
111\r
112/**\r
113 Convert the mac address into a hexadecimal encoded "-" seperated string.\r
114\r
115 @param[in] Mac The mac address.\r
116 @param[in] Len Length in bytes of the mac address.\r
117 @param[in] VlanId VLAN ID of the network device.\r
118 @param[out] Str The storage to return the mac string.\r
119\r
120**/\r
121VOID\r
122IScsiMacAddrToStr (\r
123 IN EFI_MAC_ADDRESS *Mac,\r
124 IN UINT32 Len,\r
125 IN UINT16 VlanId,\r
126 OUT CHAR16 *Str\r
127 );\r
128\r
129/**\r
130 Convert the formatted IP address into the binary IP address.\r
131\r
132 @param[in] Str The UNICODE string.\r
133 @param[in] IpMode Indicates whether the IP address is v4 or v6.\r
134 @param[out] Ip The storage to return the ASCII string.\r
135\r
136 @retval EFI_SUCCESS The binary IP address is returned in Ip.\r
137 @retval EFI_INVALID_PARAMETER The IP string is malformatted or IpMode is\r
138 invalid.\r
139\r
140**/\r
141EFI_STATUS\r
142IScsiAsciiStrToIp (\r
143 IN CHAR8 *Str,\r
144 IN UINT8 IpMode,\r
145 OUT EFI_IP_ADDRESS *Ip\r
146 );\r
147\r
148/**\r
149 Convert the binary encoded buffer into a hexadecimal encoded string.\r
150\r
151 @param[in] BinBuffer The buffer containing the binary data.\r
152 @param[in] BinLength Length of the binary buffer.\r
153 @param[in, out] HexStr Pointer to the string.\r
154 @param[in, out] HexLength The length of the string.\r
155\r
156 @retval EFI_SUCCESS The binary data is converted to the hexadecimal string \r
157 and the length of the string is updated.\r
158 @retval EFI_BUFFER_TOO_SMALL The string is too small.\r
159 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
160\r
161**/\r
162EFI_STATUS\r
163IScsiBinToHex (\r
164 IN UINT8 *BinBuffer,\r
165 IN UINT32 BinLength,\r
166 IN OUT CHAR8 *HexStr,\r
167 IN OUT UINT32 *HexLength\r
168 );\r
169\r
170/**\r
171 Convert the hexadecimal string into a binary encoded buffer.\r
172\r
173 @param[in, out] BinBuffer The binary buffer.\r
174 @param[in, out] BinLength Length of the binary buffer.\r
175 @param[in] HexStr The hexadecimal string.\r
176\r
177 @retval EFI_SUCCESS The hexadecimal string is converted into a binary\r
178 encoded buffer.\r
179 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.\r
180\r
181**/\r
182EFI_STATUS\r
183IScsiHexToBin (\r
184 IN OUT UINT8 *BinBuffer,\r
185 IN OUT UINT32 *BinLength,\r
186 IN CHAR8 *HexStr\r
187 );\r
188\r
189\r
190/**\r
191 Convert the decimal-constant string or hex-constant string into a numerical value.\r
192\r
193 @param[in] Str String in decimal or hex.\r
194\r
195 @return The numerical value.\r
196\r
197**/\r
198UINTN\r
199IScsiNetNtoi (\r
200 IN CHAR8 *Str\r
201 );\r
202\r
203/**\r
204 Generate random numbers.\r
205\r
206 @param[in, out] Rand The buffer to contain random numbers.\r
207 @param[in] RandLength The length of the Rand buffer.\r
208\r
209**/\r
210VOID\r
211IScsiGenRandom (\r
212 IN OUT UINT8 *Rand,\r
213 IN UINTN RandLength\r
214 );\r
215\r
216/**\r
217 Record the NIC information in a global structure.\r
218\r
219 @param[in] Controller The handle of the controller.\r
220\r
221 @retval EFI_SUCCESS The operation is completed.\r
222 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this\r
223 operation.\r
224\r
225**/\r
226EFI_STATUS\r
227IScsiAddNic (\r
228 IN EFI_HANDLE Controller\r
229 );\r
230\r
231/**\r
232 Delete the recorded NIC information from a global structure. Also delete corresponding\r
233 attempts.\r
234\r
235 @param[in] Controller The handle of the controller.\r
236\r
237 @retval EFI_SUCCESS The operation completed.\r
238 @retval EFI_NOT_FOUND The NIC information to be deleted is not recorded.\r
239\r
240**/\r
241EFI_STATUS\r
242IScsiRemoveNic (\r
243 IN EFI_HANDLE Controller\r
244 );\r
245\r
8d1f5e04
ZL
246/**\r
247 Create and initialize the Attempts.\r
248\r
249 @param[in] AttemptNum The number of Attempts will be created.\r
250\r
251 @retval EFI_SUCCESS The Attempts have been created successfully.\r
252 @retval Others Failed to create the Attempt.\r
253\r
254**/\r
255EFI_STATUS\r
256IScsiCreateAttempts (\r
257 IN UINTN AttemptNum\r
258 );\r
259\r
260/**\r
261 Create the iSCSI configuration Keywords for each attempt.\r
262\r
263 @param[in] KeywordNum The number Sets of Keywords will be created.\r
264\r
265 @retval EFI_SUCCESS The operation is completed.\r
266 @retval Others Failed to create the Keywords.\r
267\r
268**/\r
269EFI_STATUS\r
270IScsiCreateKeywords (\r
271 IN UINTN KeywordNum\r
272 );\r
273\r
274/**\r
275\r
276 Free the attempt configure data variable.\r
277\r
278**/\r
279VOID\r
280IScsiCleanAttemptVariable (\r
281 IN VOID\r
282 );\r
283\r
4c5a5e0c 284/**\r
285 Get the recorded NIC information from a global structure by the Index.\r
286\r
287 @param[in] NicIndex The index indicates the position of NIC info.\r
288\r
289 @return Pointer to the NIC info or NULL if not found.\r
290\r
291**/\r
292ISCSI_NIC_INFO *\r
293IScsiGetNicInfoByIndex (\r
294 IN UINT8 NicIndex\r
295 );\r
296\r
297\r
298/**\r
59c0c1cb 299 Get the NIC's PCI location and return it according to the composited\r
4c5a5e0c 300 format defined in iSCSI Boot Firmware Table.\r
301\r
302 @param[in] Controller The handle of the controller.\r
303 @param[out] Bus The bus number.\r
304 @param[out] Device The device number.\r
305 @param[out] Function The function number.\r
306\r
307 @return The composited representation of the NIC PCI location.\r
308\r
309**/\r
310UINT16\r
311IScsiGetNICPciLocation (\r
312 IN EFI_HANDLE Controller,\r
313 OUT UINTN *Bus,\r
314 OUT UINTN *Device,\r
315 OUT UINTN *Function\r
316 );\r
317\r
318/**\r
319 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r
320 buffer, and the size of the buffer. If failure, return NULL.\r
321\r
322 @param[in] Name String part of EFI variable name.\r
323 @param[in] VendorGuid GUID part of EFI variable name.\r
324 @param[out] VariableSize Returns the size of the EFI variable that was read.\r
325\r
326 @return Dynamically allocated memory that contains a copy of the EFI variable.\r
327 @return Caller is responsible freeing the buffer.\r
328 @retval NULL Variable was not read.\r
329\r
330**/\r
331VOID *\r
332IScsiGetVariableAndSize (\r
333 IN CHAR16 *Name,\r
334 IN EFI_GUID *VendorGuid,\r
335 OUT UINTN *VariableSize\r
336 );\r
337\r
338/**\r
339 Create the iSCSI driver data.\r
340\r
341 @param[in] Image The handle of the driver image.\r
342 @param[in] Controller The handle of the controller.\r
343\r
344 @return The iSCSI driver data created.\r
345 @retval NULL Other errors as indicated.\r
346\r
347**/\r
348ISCSI_DRIVER_DATA *\r
349IScsiCreateDriverData (\r
350 IN EFI_HANDLE Image,\r
351 IN EFI_HANDLE Controller\r
352 );\r
353\r
354/**\r
355 Clean the iSCSI driver data.\r
356\r
e590d29f
ZL
357 @param[in] Private The iSCSI driver data.\r
358\r
359 @retval EFI_SUCCES The clean operation is successful.\r
360 @retval Others Other errors as indicated.\r
4c5a5e0c 361\r
362**/\r
e590d29f 363EFI_STATUS\r
4c5a5e0c 364IScsiCleanDriverData (\r
365 IN ISCSI_DRIVER_DATA *Private\r
366 );\r
367\r
b7cc5bf1
WJ
368/**\r
369 Check wheather the Controller handle is configured to use DHCP protocol.\r
370\r
371 @param[in] Controller The handle of the controller.\r
372 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
373 \r
374 @retval TRUE The handle of the controller need the Dhcp protocol.\r
375 @retval FALSE The handle of the controller does not need the Dhcp protocol.\r
376 \r
377**/\r
378BOOLEAN\r
379IScsiDhcpIsConfigured (\r
380 IN EFI_HANDLE Controller,\r
381 IN UINT8 IpVersion\r
382 );\r
383\r
eabc6e59
ZL
384/**\r
385 Check wheather the Controller handle is configured to use DNS protocol.\r
386\r
387 @param[in] Controller The handle of the controller.\r
388 \r
389 @retval TRUE The handle of the controller need the DNS protocol.\r
390 @retval FALSE The handle of the controller does not need the DNS protocol.\r
391 \r
392**/\r
393BOOLEAN\r
394IScsiDnsIsConfigured (\r
395 IN EFI_HANDLE Controller\r
396 );\r
397\r
4c5a5e0c 398/**\r
399 Get the various configuration data of this iSCSI instance.\r
400\r
401 @param[in] Private The iSCSI driver data.\r
402\r
403 @retval EFI_SUCCESS Obtained the configuration of this instance.\r
404 @retval EFI_ABORTED The operation was aborted.\r
405 @retval Others Other errors as indicated.\r
406\r
407**/\r
408EFI_STATUS\r
409IScsiGetConfigData (\r
410 IN ISCSI_DRIVER_DATA *Private\r
411 );\r
412\r
413/**\r
414 Get the device path of the iSCSI tcp connection and update it.\r
415\r
416 @param[in] Session The iSCSI session data.\r
417\r
418 @return The updated device path.\r
419 @retval NULL Other errors as indicated.\r
420\r
421**/\r
422EFI_DEVICE_PATH_PROTOCOL *\r
423IScsiGetTcpConnDevicePath (\r
424 IN ISCSI_SESSION *Session\r
425 );\r
426\r
427/**\r
428 Abort the session when the transition from BS to RT is initiated.\r
429\r
430 @param[in] Event The event signaled.\r
431 @param[in] Context The iSCSI driver data.\r
432\r
433**/\r
434VOID\r
435EFIAPI\r
436IScsiOnExitBootService (\r
437 IN EFI_EVENT Event,\r
438 IN VOID *Context\r
439 );\r
440\r
18b24f92
FS
441/**\r
442 Tests whether a controller handle is being managed by IScsi driver.\r
443\r
444 This function tests whether the driver specified by DriverBindingHandle is\r
445 currently managing the controller specified by ControllerHandle. This test\r
446 is performed by evaluating if the the protocol specified by ProtocolGuid is\r
447 present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
448 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
449 If ProtocolGuid is NULL, then ASSERT().\r
450\r
451 @param ControllerHandle A handle for a controller to test.\r
452 @param DriverBindingHandle Specifies the driver binding handle for the\r
453 driver.\r
454 @param ProtocolGuid Specifies the protocol that the driver specified\r
455 by DriverBindingHandle opens in its Start()\r
456 function.\r
457\r
458 @retval EFI_SUCCESS ControllerHandle is managed by the driver\r
459 specified by DriverBindingHandle.\r
460 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r
461 specified by DriverBindingHandle.\r
462\r
463**/\r
464EFI_STATUS\r
465EFIAPI\r
466IScsiTestManagedDevice (\r
467 IN EFI_HANDLE ControllerHandle,\r
468 IN EFI_HANDLE DriverBindingHandle,\r
469 IN EFI_GUID *ProtocolGuid\r
470 );\r
4c5a5e0c 471#endif\r