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