2 Miscellaneous definitions for iSCSI driver.
4 Copyright (c) 2004 - 2018, 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
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.
15 #ifndef _ISCSI_MISC_H_
16 #define _ISCSI_MISC_H_
18 typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA
;
21 /// IPv4 Device Path Node Length
23 #define IP4_NODE_LEN_NEW_VERSIONS 27
26 /// IPv6 Device Path Node Length
28 #define IP6_NODE_LEN_OLD_VERSIONS 43
29 #define IP6_NODE_LEN_NEW_VERSIONS 60
32 /// The ignored field StaticIpAddress's offset in old IPv6 Device Path
34 #define IP6_OLD_IPADDRESS_OFFSET 42
38 typedef struct _ISCSI_SESSION_CONFIG_NVDATA
{
43 EFI_IP_ADDRESS LocalIp
;
44 EFI_IPv4_ADDRESS SubnetMask
;
45 EFI_IP_ADDRESS Gateway
;
47 BOOLEAN InitiatorInfoFromDhcp
;
48 BOOLEAN TargetInfoFromDhcp
;
50 CHAR8 TargetName
[ISCSI_NAME_MAX_SIZE
];
51 EFI_IP_ADDRESS TargetIp
;
55 UINT16 ConnectTimeout
; ///< timout value in milliseconds.
56 UINT8 ConnectRetryCount
;
60 UINT16 OriginalTargetPort
; // The port of proxy/virtual target.
61 EFI_IP_ADDRESS OriginalTargetIp
; // The address of proxy/virtual target.
63 BOOLEAN DnsMode
; // Flag indicate whether the Target address is expressed as URL format.
64 CHAR8 TargetUrl
[ISCSI_TARGET_URI_MAX_SIZE
];
66 } ISCSI_SESSION_CONFIG_NVDATA
;
70 Calculate the prefix length of the IPv4 subnet mask.
72 @param[in] SubnetMask The IPv4 subnet mask.
74 @return The prefix length of the subnet mask.
75 @retval 0 Other errors as indicated.
79 IScsiGetSubnetMaskPrefixLength (
80 IN EFI_IPv4_ADDRESS
*SubnetMask
84 Convert the hexadecimal encoded LUN string into the 64-bit LUN.
86 @param[in] Str The hexadecimal encoded LUN string.
87 @param[out] Lun Storage to return the 64-bit LUN.
89 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.
90 @retval EFI_INVALID_PARAMETER The string is malformatted.
100 Convert the 64-bit LUN into the hexadecimal encoded LUN string.
102 @param[in] Lun The 64-bit LUN.
103 @param[out] String The storage to return the hexadecimal encoded LUN string.
107 IScsiLunToUnicodeStr (
113 Convert the mac address into a hexadecimal encoded "-" seperated string.
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.
123 IN EFI_MAC_ADDRESS
*Mac
,
130 Convert the formatted IP address into the binary IP address.
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.
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
145 OUT EFI_IP_ADDRESS
*Ip
149 Convert the binary encoded buffer into a hexadecimal encoded string.
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.
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.
166 IN OUT CHAR8
*HexStr
,
167 IN OUT UINT32
*HexLength
171 Convert the hexadecimal string into a binary encoded buffer.
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.
177 @retval EFI_SUCCESS The hexadecimal string is converted into a binary
179 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.
184 IN OUT UINT8
*BinBuffer
,
185 IN OUT UINT32
*BinLength
,
191 Convert the decimal-constant string or hex-constant string into a numerical value.
193 @param[in] Str String in decimal or hex.
195 @return The numerical value.
204 Generate random numbers.
206 @param[in, out] Rand The buffer to contain random numbers.
207 @param[in] RandLength The length of the Rand buffer.
217 Record the NIC information in a global structure.
219 @param[in] Controller The handle of the controller.
220 @param[in] Image Handle of the image.
222 @retval EFI_SUCCESS The operation is completed.
223 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
229 IN EFI_HANDLE Controller
,
234 Delete the recorded NIC information from a global structure. Also delete corresponding
237 @param[in] Controller The handle of the controller.
239 @retval EFI_SUCCESS The operation completed.
240 @retval EFI_NOT_FOUND The NIC information to be deleted is not recorded.
245 IN EFI_HANDLE Controller
249 Create and initialize the Attempts.
251 @param[in] AttemptNum The number of Attempts will be created.
253 @retval EFI_SUCCESS The Attempts have been created successfully.
254 @retval Others Failed to create the Attempt.
258 IScsiCreateAttempts (
263 Create the iSCSI configuration Keywords for each attempt.
265 @param[in] KeywordNum The number Sets of Keywords will be created.
267 @retval EFI_SUCCESS The operation is completed.
268 @retval Others Failed to create the Keywords.
272 IScsiCreateKeywords (
278 Free the attempt configure data variable.
282 IScsiCleanAttemptVariable (
287 Get the recorded NIC information from a global structure by the Index.
289 @param[in] NicIndex The index indicates the position of NIC info.
291 @return Pointer to the NIC info or NULL if not found.
295 IScsiGetNicInfoByIndex (
301 Get the NIC's PCI location and return it according to the composited
302 format defined in iSCSI Boot Firmware Table.
304 @param[in] Controller The handle of the controller.
305 @param[out] Bus The bus number.
306 @param[out] Device The device number.
307 @param[out] Function The function number.
309 @return The composited representation of the NIC PCI location.
313 IScsiGetNICPciLocation (
314 IN EFI_HANDLE Controller
,
321 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
322 buffer, and the size of the buffer. If failure, return NULL.
324 @param[in] Name String part of EFI variable name.
325 @param[in] VendorGuid GUID part of EFI variable name.
326 @param[out] VariableSize Returns the size of the EFI variable that was read.
328 @return Dynamically allocated memory that contains a copy of the EFI variable.
329 @return Caller is responsible freeing the buffer.
330 @retval NULL Variable was not read.
334 IScsiGetVariableAndSize (
336 IN EFI_GUID
*VendorGuid
,
337 OUT UINTN
*VariableSize
341 Create the iSCSI driver data.
343 @param[in] Image The handle of the driver image.
344 @param[in] Controller The handle of the controller.
346 @return The iSCSI driver data created.
347 @retval NULL Other errors as indicated.
351 IScsiCreateDriverData (
353 IN EFI_HANDLE Controller
357 Clean the iSCSI driver data.
359 @param[in] Private The iSCSI driver data.
361 @retval EFI_SUCCES The clean operation is successful.
362 @retval Others Other errors as indicated.
366 IScsiCleanDriverData (
367 IN ISCSI_DRIVER_DATA
*Private
371 Check wheather the Controller handle is configured to use DHCP protocol.
373 @param[in] Controller The handle of the controller.
374 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
376 @retval TRUE The handle of the controller need the Dhcp protocol.
377 @retval FALSE The handle of the controller does not need the Dhcp protocol.
381 IScsiDhcpIsConfigured (
382 IN EFI_HANDLE Controller
,
387 Check wheather the Controller handle is configured to use DNS protocol.
389 @param[in] Controller The handle of the controller.
391 @retval TRUE The handle of the controller need the DNS protocol.
392 @retval FALSE The handle of the controller does not need the DNS protocol.
396 IScsiDnsIsConfigured (
397 IN EFI_HANDLE Controller
401 Get the various configuration data of this iSCSI instance.
403 @param[in] Private The iSCSI driver data.
405 @retval EFI_SUCCESS Obtained the configuration of this instance.
406 @retval EFI_ABORTED The operation was aborted.
407 @retval Others Other errors as indicated.
412 IN ISCSI_DRIVER_DATA
*Private
416 Get the device path of the iSCSI tcp connection and update it.
418 @param[in] Session The iSCSI session data.
420 @return The updated device path.
421 @retval NULL Other errors as indicated.
424 EFI_DEVICE_PATH_PROTOCOL
*
425 IScsiGetTcpConnDevicePath (
426 IN ISCSI_SESSION
*Session
430 Abort the session when the transition from BS to RT is initiated.
432 @param[in] Event The event signaled.
433 @param[in] Context The iSCSI driver data.
438 IScsiOnExitBootService (
444 Tests whether a controller handle is being managed by IScsi driver.
446 This function tests whether the driver specified by DriverBindingHandle is
447 currently managing the controller specified by ControllerHandle. This test
448 is performed by evaluating if the the protocol specified by ProtocolGuid is
449 present on ControllerHandle and is was opened by DriverBindingHandle and Nic
450 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.
451 If ProtocolGuid is NULL, then ASSERT().
453 @param ControllerHandle A handle for a controller to test.
454 @param DriverBindingHandle Specifies the driver binding handle for the
456 @param ProtocolGuid Specifies the protocol that the driver specified
457 by DriverBindingHandle opens in its Start()
460 @retval EFI_SUCCESS ControllerHandle is managed by the driver
461 specified by DriverBindingHandle.
462 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver
463 specified by DriverBindingHandle.
468 IScsiTestManagedDevice (
469 IN EFI_HANDLE ControllerHandle
,
470 IN EFI_HANDLE DriverBindingHandle
,
471 IN EFI_GUID
*ProtocolGuid