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