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