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