]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiMisc.h
CommitLineData
12618416 1/** @file\r
55a64ae0 2 Miscellaneous definitions for iSCSI driver.\r
6a690e23 3\r
d1102dba 4Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
7a444476 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
6a690e23 12\r
12618416 13**/\r
6a690e23 14\r
15#ifndef _ISCSI_MISC_H_\r
16#define _ISCSI_MISC_H_\r
17\r
52ed4ff9 18#include <Library/BaseLib.h>\r
19\r
20typedef struct _ISCSI_SESSION_CONFIG_DATA ISCSI_SESSION_CONFIG_DATA;\r
21\r
7b0b3606 22///\r
23/// IPv4 Device Path Node Length\r
24///\r
00f6c6cf 25#define IP4_NODE_LEN_NEW_VERSIONS 27\r
7b0b3606 26\r
6a690e23 27#pragma pack(1)\r
52ed4ff9 28typedef struct {\r
6a690e23 29 BOOLEAN Enabled;\r
30\r
31 BOOLEAN InitiatorInfoFromDhcp;\r
32 EFI_IPv4_ADDRESS LocalIp;\r
33 EFI_IPv4_ADDRESS SubnetMask;\r
34 EFI_IPv4_ADDRESS Gateway;\r
35\r
36 BOOLEAN TargetInfoFromDhcp;\r
37 CHAR8 TargetName[ISCSI_NAME_MAX_SIZE];\r
38 EFI_IPv4_ADDRESS TargetIp;\r
39 UINT16 TargetPort;\r
40 UINT8 BootLun[8];\r
312e3bdf 41\r
42 UINT8 IsId[6];\r
6a690e23 43} ISCSI_SESSION_CONFIG_NVDATA;\r
44#pragma pack()\r
45\r
07a7038c 46struct _ISCSI_SESSION_CONFIG_DATA {\r
6a690e23 47 ISCSI_SESSION_CONFIG_NVDATA NvData;\r
48\r
49 EFI_IPv4_ADDRESS PrimaryDns;\r
50 EFI_IPv4_ADDRESS SecondaryDns;\r
51 EFI_IPv4_ADDRESS DhcpServer;\r
07a7038c 52};\r
6a690e23 53\r
12618416 54/**\r
55 Calculate the prefix length of the IPv4 subnet mask.\r
56\r
52ed4ff9 57 @param[in] SubnetMask The IPv4 subnet mask.\r
12618416 58\r
52ed4ff9 59 @return The prefix length of the subnet mask.\r
963dbb30 60 @retval 0 Other errors as indicated.\r
12618416 61**/\r
6a690e23 62UINT8\r
63IScsiGetSubnetMaskPrefixLength (\r
64 IN EFI_IPv4_ADDRESS *SubnetMask\r
65 );\r
66\r
12618416 67/**\r
d1102dba 68 Convert the hexadecimal encoded LUN string into the 64-bit LUN.\r
12618416 69\r
52ed4ff9 70 @param[in] Str The hexadecimal encoded LUN string.\r
71 @param[out] Lun Storage to return the 64-bit LUN.\r
12618416 72\r
73 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.\r
12618416 74 @retval EFI_INVALID_PARAMETER The string is malformatted.\r
12618416 75**/\r
6a690e23 76EFI_STATUS\r
77IScsiAsciiStrToLun (\r
78 IN CHAR8 *Str,\r
79 OUT UINT8 *Lun\r
80 );\r
81\r
12618416 82/**\r
83 Convert the 64-bit LUN into the hexadecimal encoded LUN string.\r
84\r
52ed4ff9 85 @param[in] Lun The 64-bit LUN.\r
86 @param[out] Str The storage to return the hexadecimal encoded LUN string.\r
12618416 87**/\r
6a690e23 88VOID\r
89IScsiLunToUnicodeStr (\r
90 IN UINT8 *Lun,\r
52ed4ff9 91 OUT CHAR16 *Str\r
6a690e23 92 );\r
93\r
12618416 94/**\r
95 Convert the ASCII string into a UNICODE string.\r
96\r
52ed4ff9 97 @param[in] Source The ASCII string.\r
98 @param[out] Destination The storage to return the UNICODE string.\r
12618416 99\r
52ed4ff9 100 @return CHAR16 * Pointer to the UNICODE string.\r
12618416 101**/\r
102CHAR16 *\r
6a690e23 103IScsiAsciiStrToUnicodeStr (\r
104 IN CHAR8 *Source,\r
105 OUT CHAR16 *Destination\r
106 );\r
107\r
12618416 108/**\r
109 Convert the UNICODE string into an ASCII string.\r
110\r
52ed4ff9 111 @param[in] Source The UNICODE string.\r
112 @param[out] Destination The storage to return the ASCII string.\r
12618416 113\r
52ed4ff9 114 @return CHAR8 * Pointer to the ASCII string.\r
12618416 115**/\r
116CHAR8 *\r
6a690e23 117IScsiUnicodeStrToAsciiStr (\r
118 IN CHAR16 *Source,\r
119 OUT CHAR8 *Destination\r
120 );\r
121\r
12618416 122/**\r
123 Convert the mac address into a hexadecimal encoded "-" seperated string.\r
124\r
779ae357 125 @param[in] Mac The mac address.\r
126 @param[in] Len Length in bytes of the mac address.\r
127 @param[in] VlanId VLAN ID of the network device.\r
128 @param[out] Str The storage to return the mac string.\r
12618416 129**/\r
6a690e23 130VOID\r
131IScsiMacAddrToStr (\r
132 IN EFI_MAC_ADDRESS *Mac,\r
133 IN UINT32 Len,\r
779ae357 134 IN UINT16 VlanId,\r
6a690e23 135 OUT CHAR16 *Str\r
136 );\r
137\r
12618416 138/**\r
139 Convert the decimal dotted IPv4 address into the binary IPv4 address.\r
140\r
52ed4ff9 141 @param[in] Str The UNICODE string.\r
142 @param[out] Ip The storage to return the ASCII string.\r
12618416 143\r
144 @retval EFI_SUCCESS The binary IP address is returned in Ip.\r
12618416 145 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
12618416 146**/\r
6a690e23 147EFI_STATUS\r
148IScsiAsciiStrToIp (\r
149 IN CHAR8 *Str,\r
150 OUT EFI_IPv4_ADDRESS *Ip\r
151 );\r
152\r
12618416 153/**\r
154 Convert the binary encoded buffer into a hexadecimal encoded string.\r
155\r
52ed4ff9 156 @param[in] BinBuffer The buffer containing the binary data.\r
157 @param[in] BinLength Length of the binary buffer.\r
158 @param[in, out] HexStr Pointer to the string.\r
159 @param[in, out] HexLength The length of the string.\r
12618416 160\r
d1102dba 161 @retval EFI_SUCCESS The binary data is converted to the hexadecimal string\r
12618416 162 and the length of the string is updated.\r
12618416 163 @retval EFI_BUFFER_TOO_SMALL The string is too small.\r
52ed4ff9 164 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
12618416 165**/\r
6a690e23 166EFI_STATUS\r
167IScsiBinToHex (\r
168 IN UINT8 *BinBuffer,\r
169 IN UINT32 BinLength,\r
170 IN OUT CHAR8 *HexStr,\r
171 IN OUT UINT32 *HexLength\r
172 );\r
173\r
12618416 174/**\r
175 Convert the hexadecimal string into a binary encoded buffer.\r
176\r
52ed4ff9 177 @param[in, out] BinBuffer The binary buffer.\r
178 @param[in, out] BinLength Length of the binary buffer.\r
179 @param[in] HexStr The hexadecimal string.\r
12618416 180\r
181 @retval EFI_SUCCESS The hexadecimal string is converted into a binary\r
182 encoded buffer.\r
963dbb30 183 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.\r
12618416 184**/\r
6a690e23 185EFI_STATUS\r
186IScsiHexToBin (\r
187 IN OUT UINT8 *BinBuffer,\r
188 IN OUT UINT32 *BinLength,\r
189 IN CHAR8 *HexStr\r
190 );\r
191\r
12618416 192/**\r
193 Generate random numbers.\r
194\r
52ed4ff9 195 @param[in, out] Rand The buffer to contain random numbers.\r
196 @param[in] RandLength The length of the Rand buffer.\r
12618416 197**/\r
6a690e23 198VOID\r
199IScsiGenRandom (\r
200 IN OUT UINT8 *Rand,\r
201 IN UINTN RandLength\r
202 );\r
203\r
12618416 204/**\r
205 Create the iSCSI driver data..\r
206\r
52ed4ff9 207 @param[in] Image The handle of the driver image.\r
208 @param[in] Controller The handle of the controller.\r
12618416 209\r
52ed4ff9 210 @return The iSCSI driver data created.\r
963dbb30 211 @retval NULL Other errors as indicated.\r
12618416 212**/\r
213ISCSI_DRIVER_DATA *\r
6a690e23 214IScsiCreateDriverData (\r
215 IN EFI_HANDLE Image,\r
216 IN EFI_HANDLE Controller\r
217 );\r
218\r
12618416 219/**\r
220 Clean the iSCSI driver data.\r
221\r
e3761c71
ZL
222 @param[in] Private The iSCSI driver data.\r
223\r
224 @retval EFI_SUCCES The clean operation is successful.\r
225 @retval Others Other errors as indicated.\r
12618416 226**/\r
e3761c71 227EFI_STATUS\r
6a690e23 228IScsiCleanDriverData (\r
229 IN ISCSI_DRIVER_DATA *Private\r
230 );\r
231\r
05a30011
WJ
232/**\r
233 Check wheather the Controller is configured to use DHCP protocol.\r
234\r
235 @param[in] Controller The handle of the controller.\r
d1102dba 236\r
05a30011
WJ
237 @retval TRUE The handle of the controller need the Dhcp protocol.\r
238 @retval FALSE The handle of the controller does not need the Dhcp protocol.\r
d1102dba 239\r
05a30011
WJ
240**/\r
241BOOLEAN\r
242IScsiDhcpIsConfigured (\r
243 IN EFI_HANDLE Controller\r
244 );\r
245\r
12618416 246/**\r
12618416 247 Get the various configuration data of this iSCSI instance.\r
248\r
52ed4ff9 249 @param[in] Private The iSCSI driver data.\r
12618416 250\r
251 @retval EFI_SUCCESS The configuration of this instance is got.\r
52ed4ff9 252 @retval EFI_ABORTED The operation was aborted.\r
963dbb30 253 @retval Others Other errors as indicated.\r
12618416 254**/\r
6a690e23 255EFI_STATUS\r
256IScsiGetConfigData (\r
257 IN ISCSI_DRIVER_DATA *Private\r
258 );\r
259\r
12618416 260/**\r
261 Get the device path of the iSCSI tcp connection and update it.\r
262\r
52ed4ff9 263 @param[in] Private The iSCSI driver data.\r
12618416 264\r
52ed4ff9 265 @return The updated device path.\r
963dbb30 266 @retval NULL Other errors as indicated.\r
12618416 267**/\r
52ed4ff9 268EFI_DEVICE_PATH_PROTOCOL *\r
6a690e23 269IScsiGetTcpConnDevicePath (\r
270 IN ISCSI_DRIVER_DATA *Private\r
271 );\r
272\r
12618416 273/**\r
274 Abort the session when the transition from BS to RT is initiated.\r
275\r
52ed4ff9 276 @param[in] Event The event signaled.\r
277 @param[in] Context The iSCSI driver data.\r
12618416 278**/\r
6a690e23 279VOID\r
280EFIAPI\r
281IScsiOnExitBootService (\r
282 IN EFI_EVENT Event,\r
283 IN VOID *Context\r
284 );\r
285\r
18b24f92
FS
286/**\r
287 Tests whether a controller handle is being managed by IScsi driver.\r
288\r
289 This function tests whether the driver specified by DriverBindingHandle is\r
290 currently managing the controller specified by ControllerHandle. This test\r
291 is performed by evaluating if the the protocol specified by ProtocolGuid is\r
292 present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
d1102dba 293 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r
18b24f92
FS
294 If ProtocolGuid is NULL, then ASSERT().\r
295\r
296 @param ControllerHandle A handle for a controller to test.\r
297 @param DriverBindingHandle Specifies the driver binding handle for the\r
298 driver.\r
299 @param ProtocolGuid Specifies the protocol that the driver specified\r
300 by DriverBindingHandle opens in its Start()\r
301 function.\r
302\r
303 @retval EFI_SUCCESS ControllerHandle is managed by the driver\r
304 specified by DriverBindingHandle.\r
305 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r
306 specified by DriverBindingHandle.\r
52ed4ff9 307\r
18b24f92
FS
308**/\r
309EFI_STATUS\r
310EFIAPI\r
311IScsiTestManagedDevice (\r
312 IN EFI_HANDLE ControllerHandle,\r
313 IN EFI_HANDLE DriverBindingHandle,\r
314 IN EFI_GUID *ProtocolGuid\r
315 );\r
6a690e23 316\r
317#endif\r