]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/IScsiDxe/IScsiMisc.h
NetworkPkg:Add scriptable configuration to iSCSI driver by leveraging x-UEFI.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiMisc.h
1 /** @file
2 Miscellaneous definitions for iSCSI driver.
3
4 Copyright (c) 2004 - 2017, 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
221 @retval EFI_SUCCESS The operation is completed.
222 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
223 operation.
224
225 **/
226 EFI_STATUS
227 IScsiAddNic (
228 IN EFI_HANDLE Controller
229 );
230
231 /**
232 Delete the recorded NIC information from a global structure. Also delete corresponding
233 attempts.
234
235 @param[in] Controller The handle of the controller.
236
237 @retval EFI_SUCCESS The operation completed.
238 @retval EFI_NOT_FOUND The NIC information to be deleted is not recorded.
239
240 **/
241 EFI_STATUS
242 IScsiRemoveNic (
243 IN EFI_HANDLE Controller
244 );
245
246 /**
247 Create and initialize the Attempts.
248
249 @param[in] AttemptNum The number of Attempts will be created.
250
251 @retval EFI_SUCCESS The Attempts have been created successfully.
252 @retval Others Failed to create the Attempt.
253
254 **/
255 EFI_STATUS
256 IScsiCreateAttempts (
257 IN UINTN AttemptNum
258 );
259
260 /**
261 Create the iSCSI configuration Keywords for each attempt.
262
263 @param[in] KeywordNum The number Sets of Keywords will be created.
264
265 @retval EFI_SUCCESS The operation is completed.
266 @retval Others Failed to create the Keywords.
267
268 **/
269 EFI_STATUS
270 IScsiCreateKeywords (
271 IN UINTN KeywordNum
272 );
273
274 /**
275
276 Free the attempt configure data variable.
277
278 **/
279 VOID
280 IScsiCleanAttemptVariable (
281 IN VOID
282 );
283
284 /**
285 Get the recorded NIC information from a global structure by the Index.
286
287 @param[in] NicIndex The index indicates the position of NIC info.
288
289 @return Pointer to the NIC info or NULL if not found.
290
291 **/
292 ISCSI_NIC_INFO *
293 IScsiGetNicInfoByIndex (
294 IN UINT8 NicIndex
295 );
296
297
298 /**
299 Get the NIC's PCI location and return it according to the composited
300 format defined in iSCSI Boot Firmware Table.
301
302 @param[in] Controller The handle of the controller.
303 @param[out] Bus The bus number.
304 @param[out] Device The device number.
305 @param[out] Function The function number.
306
307 @return The composited representation of the NIC PCI location.
308
309 **/
310 UINT16
311 IScsiGetNICPciLocation (
312 IN EFI_HANDLE Controller,
313 OUT UINTN *Bus,
314 OUT UINTN *Device,
315 OUT UINTN *Function
316 );
317
318 /**
319 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
320 buffer, and the size of the buffer. If failure, return NULL.
321
322 @param[in] Name String part of EFI variable name.
323 @param[in] VendorGuid GUID part of EFI variable name.
324 @param[out] VariableSize Returns the size of the EFI variable that was read.
325
326 @return Dynamically allocated memory that contains a copy of the EFI variable.
327 @return Caller is responsible freeing the buffer.
328 @retval NULL Variable was not read.
329
330 **/
331 VOID *
332 IScsiGetVariableAndSize (
333 IN CHAR16 *Name,
334 IN EFI_GUID *VendorGuid,
335 OUT UINTN *VariableSize
336 );
337
338 /**
339 Create the iSCSI driver data.
340
341 @param[in] Image The handle of the driver image.
342 @param[in] Controller The handle of the controller.
343
344 @return The iSCSI driver data created.
345 @retval NULL Other errors as indicated.
346
347 **/
348 ISCSI_DRIVER_DATA *
349 IScsiCreateDriverData (
350 IN EFI_HANDLE Image,
351 IN EFI_HANDLE Controller
352 );
353
354 /**
355 Clean the iSCSI driver data.
356
357 @param[in] Private The iSCSI driver data.
358
359 @retval EFI_SUCCES The clean operation is successful.
360 @retval Others Other errors as indicated.
361
362 **/
363 EFI_STATUS
364 IScsiCleanDriverData (
365 IN ISCSI_DRIVER_DATA *Private
366 );
367
368 /**
369 Check wheather the Controller handle is configured to use DHCP protocol.
370
371 @param[in] Controller The handle of the controller.
372 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
373
374 @retval TRUE The handle of the controller need the Dhcp protocol.
375 @retval FALSE The handle of the controller does not need the Dhcp protocol.
376
377 **/
378 BOOLEAN
379 IScsiDhcpIsConfigured (
380 IN EFI_HANDLE Controller,
381 IN UINT8 IpVersion
382 );
383
384 /**
385 Check wheather the Controller handle is configured to use DNS protocol.
386
387 @param[in] Controller The handle of the controller.
388
389 @retval TRUE The handle of the controller need the DNS protocol.
390 @retval FALSE The handle of the controller does not need the DNS protocol.
391
392 **/
393 BOOLEAN
394 IScsiDnsIsConfigured (
395 IN EFI_HANDLE Controller
396 );
397
398 /**
399 Get the various configuration data of this iSCSI instance.
400
401 @param[in] Private The iSCSI driver data.
402
403 @retval EFI_SUCCESS Obtained the configuration of this instance.
404 @retval EFI_ABORTED The operation was aborted.
405 @retval Others Other errors as indicated.
406
407 **/
408 EFI_STATUS
409 IScsiGetConfigData (
410 IN ISCSI_DRIVER_DATA *Private
411 );
412
413 /**
414 Get the device path of the iSCSI tcp connection and update it.
415
416 @param[in] Session The iSCSI session data.
417
418 @return The updated device path.
419 @retval NULL Other errors as indicated.
420
421 **/
422 EFI_DEVICE_PATH_PROTOCOL *
423 IScsiGetTcpConnDevicePath (
424 IN ISCSI_SESSION *Session
425 );
426
427 /**
428 Abort the session when the transition from BS to RT is initiated.
429
430 @param[in] Event The event signaled.
431 @param[in] Context The iSCSI driver data.
432
433 **/
434 VOID
435 EFIAPI
436 IScsiOnExitBootService (
437 IN EFI_EVENT Event,
438 IN VOID *Context
439 );
440
441 /**
442 Tests whether a controller handle is being managed by IScsi driver.
443
444 This function tests whether the driver specified by DriverBindingHandle is
445 currently managing the controller specified by ControllerHandle. This test
446 is performed by evaluating if the the protocol specified by ProtocolGuid is
447 present on ControllerHandle and is was opened by DriverBindingHandle and Nic
448 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.
449 If ProtocolGuid is NULL, then ASSERT().
450
451 @param ControllerHandle A handle for a controller to test.
452 @param DriverBindingHandle Specifies the driver binding handle for the
453 driver.
454 @param ProtocolGuid Specifies the protocol that the driver specified
455 by DriverBindingHandle opens in its Start()
456 function.
457
458 @retval EFI_SUCCESS ControllerHandle is managed by the driver
459 specified by DriverBindingHandle.
460 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver
461 specified by DriverBindingHandle.
462
463 **/
464 EFI_STATUS
465 EFIAPI
466 IScsiTestManagedDevice (
467 IN EFI_HANDLE ControllerHandle,
468 IN EFI_HANDLE DriverBindingHandle,
469 IN EFI_GUID *ProtocolGuid
470 );
471 #endif