]>
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 | |
a2d59ef2 | 49 | UINT16 ConnectTimeout; ///< timout 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 | |
107 | Convert the mac address into a hexadecimal encoded "-" seperated string.\r | |
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 | |
153 | @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r | |
154 | \r | |
155 | **/\r | |
156 | EFI_STATUS\r | |
157 | IScsiBinToHex (\r | |
158 | IN UINT8 *BinBuffer,\r | |
159 | IN UINT32 BinLength,\r | |
160 | IN OUT CHAR8 *HexStr,\r | |
161 | IN OUT UINT32 *HexLength\r | |
162 | );\r | |
163 | \r | |
164 | /**\r | |
165 | Convert the hexadecimal string into a binary encoded buffer.\r | |
166 | \r | |
167 | @param[in, out] BinBuffer The binary buffer.\r | |
168 | @param[in, out] BinLength Length of the binary buffer.\r | |
169 | @param[in] HexStr The hexadecimal string.\r | |
170 | \r | |
171 | @retval EFI_SUCCESS The hexadecimal string is converted into a binary\r | |
172 | encoded buffer.\r | |
173 | @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.\r | |
174 | \r | |
175 | **/\r | |
176 | EFI_STATUS\r | |
177 | IScsiHexToBin (\r | |
178 | IN OUT UINT8 *BinBuffer,\r | |
179 | IN OUT UINT32 *BinLength,\r | |
180 | IN CHAR8 *HexStr\r | |
181 | );\r | |
182 | \r | |
183 | \r | |
184 | /**\r | |
185 | Convert the decimal-constant string or hex-constant string into a numerical value.\r | |
186 | \r | |
187 | @param[in] Str String in decimal or hex.\r | |
188 | \r | |
189 | @return The numerical value.\r | |
190 | \r | |
191 | **/\r | |
192 | UINTN\r | |
193 | IScsiNetNtoi (\r | |
194 | IN CHAR8 *Str\r | |
195 | );\r | |
196 | \r | |
197 | /**\r | |
198 | Generate random numbers.\r | |
199 | \r | |
200 | @param[in, out] Rand The buffer to contain random numbers.\r | |
201 | @param[in] RandLength The length of the Rand buffer.\r | |
202 | \r | |
203 | **/\r | |
204 | VOID\r | |
205 | IScsiGenRandom (\r | |
206 | IN OUT UINT8 *Rand,\r | |
207 | IN UINTN RandLength\r | |
208 | );\r | |
209 | \r | |
210 | /**\r | |
211 | Record the NIC information in a global structure.\r | |
212 | \r | |
213 | @param[in] Controller The handle of the controller.\r | |
6b08dd6e | 214 | @param[in] Image Handle of the image.\r |
4c5a5e0c | 215 | \r |
216 | @retval EFI_SUCCESS The operation is completed.\r | |
217 | @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this\r | |
218 | operation.\r | |
219 | \r | |
220 | **/\r | |
221 | EFI_STATUS\r | |
222 | IScsiAddNic (\r | |
6b08dd6e JW |
223 | IN EFI_HANDLE Controller,\r |
224 | IN EFI_HANDLE Image\r | |
4c5a5e0c | 225 | );\r |
226 | \r | |
227 | /**\r | |
228 | Delete the recorded NIC information from a global structure. Also delete corresponding\r | |
229 | attempts.\r | |
230 | \r | |
231 | @param[in] Controller The handle of the controller.\r | |
232 | \r | |
233 | @retval EFI_SUCCESS The operation completed.\r | |
234 | @retval EFI_NOT_FOUND The NIC information to be deleted is not recorded.\r | |
235 | \r | |
236 | **/\r | |
237 | EFI_STATUS\r | |
238 | IScsiRemoveNic (\r | |
239 | IN EFI_HANDLE Controller\r | |
240 | );\r | |
241 | \r | |
8d1f5e04 ZL |
242 | /**\r |
243 | Create and initialize the Attempts.\r | |
244 | \r | |
245 | @param[in] AttemptNum The number of Attempts will be created.\r | |
246 | \r | |
247 | @retval EFI_SUCCESS The Attempts have been created successfully.\r | |
248 | @retval Others Failed to create the Attempt.\r | |
249 | \r | |
250 | **/\r | |
251 | EFI_STATUS\r | |
252 | IScsiCreateAttempts (\r | |
253 | IN UINTN AttemptNum\r | |
254 | );\r | |
255 | \r | |
256 | /**\r | |
257 | Create the iSCSI configuration Keywords for each attempt.\r | |
258 | \r | |
259 | @param[in] KeywordNum The number Sets of Keywords will be created.\r | |
260 | \r | |
261 | @retval EFI_SUCCESS The operation is completed.\r | |
262 | @retval Others Failed to create the Keywords.\r | |
263 | \r | |
264 | **/\r | |
265 | EFI_STATUS\r | |
266 | IScsiCreateKeywords (\r | |
267 | IN UINTN KeywordNum\r | |
268 | );\r | |
269 | \r | |
270 | /**\r | |
271 | \r | |
272 | Free the attempt configure data variable.\r | |
273 | \r | |
274 | **/\r | |
275 | VOID\r | |
276 | IScsiCleanAttemptVariable (\r | |
277 | IN VOID\r | |
278 | );\r | |
279 | \r | |
4c5a5e0c | 280 | /**\r |
281 | Get the recorded NIC information from a global structure by the Index.\r | |
282 | \r | |
283 | @param[in] NicIndex The index indicates the position of NIC info.\r | |
284 | \r | |
285 | @return Pointer to the NIC info or NULL if not found.\r | |
286 | \r | |
287 | **/\r | |
288 | ISCSI_NIC_INFO *\r | |
289 | IScsiGetNicInfoByIndex (\r | |
290 | IN UINT8 NicIndex\r | |
291 | );\r | |
292 | \r | |
293 | \r | |
294 | /**\r | |
59c0c1cb | 295 | Get the NIC's PCI location and return it according to the composited\r |
4c5a5e0c | 296 | format defined in iSCSI Boot Firmware Table.\r |
297 | \r | |
298 | @param[in] Controller The handle of the controller.\r | |
299 | @param[out] Bus The bus number.\r | |
300 | @param[out] Device The device number.\r | |
301 | @param[out] Function The function number.\r | |
302 | \r | |
303 | @return The composited representation of the NIC PCI location.\r | |
304 | \r | |
305 | **/\r | |
306 | UINT16\r | |
307 | IScsiGetNICPciLocation (\r | |
308 | IN EFI_HANDLE Controller,\r | |
309 | OUT UINTN *Bus,\r | |
310 | OUT UINTN *Device,\r | |
311 | OUT UINTN *Function\r | |
312 | );\r | |
313 | \r | |
314 | /**\r | |
315 | Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r | |
316 | buffer, and the size of the buffer. If failure, return NULL.\r | |
317 | \r | |
318 | @param[in] Name String part of EFI variable name.\r | |
319 | @param[in] VendorGuid GUID part of EFI variable name.\r | |
320 | @param[out] VariableSize Returns the size of the EFI variable that was read.\r | |
321 | \r | |
322 | @return Dynamically allocated memory that contains a copy of the EFI variable.\r | |
323 | @return Caller is responsible freeing the buffer.\r | |
324 | @retval NULL Variable was not read.\r | |
325 | \r | |
326 | **/\r | |
327 | VOID *\r | |
328 | IScsiGetVariableAndSize (\r | |
329 | IN CHAR16 *Name,\r | |
330 | IN EFI_GUID *VendorGuid,\r | |
331 | OUT UINTN *VariableSize\r | |
332 | );\r | |
333 | \r | |
334 | /**\r | |
335 | Create the iSCSI driver data.\r | |
336 | \r | |
337 | @param[in] Image The handle of the driver image.\r | |
338 | @param[in] Controller The handle of the controller.\r | |
339 | \r | |
340 | @return The iSCSI driver data created.\r | |
341 | @retval NULL Other errors as indicated.\r | |
342 | \r | |
343 | **/\r | |
344 | ISCSI_DRIVER_DATA *\r | |
345 | IScsiCreateDriverData (\r | |
346 | IN EFI_HANDLE Image,\r | |
347 | IN EFI_HANDLE Controller\r | |
348 | );\r | |
349 | \r | |
350 | /**\r | |
351 | Clean the iSCSI driver data.\r | |
352 | \r | |
e590d29f ZL |
353 | @param[in] Private The iSCSI driver data.\r |
354 | \r | |
355 | @retval EFI_SUCCES The clean operation is successful.\r | |
356 | @retval Others Other errors as indicated.\r | |
4c5a5e0c | 357 | \r |
358 | **/\r | |
e590d29f | 359 | EFI_STATUS\r |
4c5a5e0c | 360 | IScsiCleanDriverData (\r |
361 | IN ISCSI_DRIVER_DATA *Private\r | |
362 | );\r | |
363 | \r | |
b7cc5bf1 WJ |
364 | /**\r |
365 | Check wheather the Controller handle is configured to use DHCP protocol.\r | |
366 | \r | |
367 | @param[in] Controller The handle of the controller.\r | |
368 | @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r | |
f75a7f56 | 369 | \r |
b7cc5bf1 WJ |
370 | @retval TRUE The handle of the controller need the Dhcp protocol.\r |
371 | @retval FALSE The handle of the controller does not need the Dhcp protocol.\r | |
f75a7f56 | 372 | \r |
b7cc5bf1 WJ |
373 | **/\r |
374 | BOOLEAN\r | |
375 | IScsiDhcpIsConfigured (\r | |
376 | IN EFI_HANDLE Controller,\r | |
377 | IN UINT8 IpVersion\r | |
378 | );\r | |
379 | \r | |
eabc6e59 ZL |
380 | /**\r |
381 | Check wheather the Controller handle is configured to use DNS protocol.\r | |
382 | \r | |
383 | @param[in] Controller The handle of the controller.\r | |
f75a7f56 | 384 | \r |
eabc6e59 ZL |
385 | @retval TRUE The handle of the controller need the DNS protocol.\r |
386 | @retval FALSE The handle of the controller does not need the DNS protocol.\r | |
f75a7f56 | 387 | \r |
eabc6e59 ZL |
388 | **/\r |
389 | BOOLEAN\r | |
390 | IScsiDnsIsConfigured (\r | |
391 | IN EFI_HANDLE Controller\r | |
392 | );\r | |
393 | \r | |
4c5a5e0c | 394 | /**\r |
395 | Get the various configuration data of this iSCSI instance.\r | |
396 | \r | |
397 | @param[in] Private The iSCSI driver data.\r | |
398 | \r | |
399 | @retval EFI_SUCCESS Obtained the configuration of this instance.\r | |
400 | @retval EFI_ABORTED The operation was aborted.\r | |
401 | @retval Others Other errors as indicated.\r | |
402 | \r | |
403 | **/\r | |
404 | EFI_STATUS\r | |
405 | IScsiGetConfigData (\r | |
406 | IN ISCSI_DRIVER_DATA *Private\r | |
407 | );\r | |
408 | \r | |
409 | /**\r | |
410 | Get the device path of the iSCSI tcp connection and update it.\r | |
411 | \r | |
412 | @param[in] Session The iSCSI session data.\r | |
413 | \r | |
414 | @return The updated device path.\r | |
415 | @retval NULL Other errors as indicated.\r | |
416 | \r | |
417 | **/\r | |
418 | EFI_DEVICE_PATH_PROTOCOL *\r | |
419 | IScsiGetTcpConnDevicePath (\r | |
420 | IN ISCSI_SESSION *Session\r | |
421 | );\r | |
422 | \r | |
423 | /**\r | |
424 | Abort the session when the transition from BS to RT is initiated.\r | |
425 | \r | |
426 | @param[in] Event The event signaled.\r | |
427 | @param[in] Context The iSCSI driver data.\r | |
428 | \r | |
429 | **/\r | |
430 | VOID\r | |
431 | EFIAPI\r | |
432 | IScsiOnExitBootService (\r | |
433 | IN EFI_EVENT Event,\r | |
434 | IN VOID *Context\r | |
435 | );\r | |
436 | \r | |
18b24f92 FS |
437 | /**\r |
438 | Tests whether a controller handle is being managed by IScsi driver.\r | |
439 | \r | |
440 | This function tests whether the driver specified by DriverBindingHandle is\r | |
441 | currently managing the controller specified by ControllerHandle. This test\r | |
442 | is performed by evaluating if the the protocol specified by ProtocolGuid is\r | |
443 | present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r | |
f75a7f56 | 444 | Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r |
18b24f92 FS |
445 | If ProtocolGuid is NULL, then ASSERT().\r |
446 | \r | |
447 | @param ControllerHandle A handle for a controller to test.\r | |
448 | @param DriverBindingHandle Specifies the driver binding handle for the\r | |
449 | driver.\r | |
450 | @param ProtocolGuid Specifies the protocol that the driver specified\r | |
451 | by DriverBindingHandle opens in its Start()\r | |
452 | function.\r | |
453 | \r | |
454 | @retval EFI_SUCCESS ControllerHandle is managed by the driver\r | |
455 | specified by DriverBindingHandle.\r | |
456 | @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r | |
457 | specified by DriverBindingHandle.\r | |
458 | \r | |
459 | **/\r | |
460 | EFI_STATUS\r | |
461 | EFIAPI\r | |
462 | IScsiTestManagedDevice (\r | |
463 | IN EFI_HANDLE ControllerHandle,\r | |
464 | IN EFI_HANDLE DriverBindingHandle,\r | |
465 | IN EFI_GUID *ProtocolGuid\r | |
466 | );\r | |
4c5a5e0c | 467 | #endif\r |