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