]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h
MdeModulePkg DxeCore: Enhance MemoryAttributesTable installation
[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
7b0b3606 4Copyright (c) 2004 - 2015, 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
68 Convert the hexadecimal encoded LUN string into the 64-bit LUN. \r
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
52ed4ff9 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
52ed4ff9 222 @param[in] Private The iSCSI driver data.\r
12618416 223**/\r
6a690e23 224VOID\r
225IScsiCleanDriverData (\r
226 IN ISCSI_DRIVER_DATA *Private\r
227 );\r
228\r
05a30011
WJ
229/**\r
230 Check wheather the Controller is configured to use DHCP protocol.\r
231\r
232 @param[in] Controller The handle of the controller.\r
233 \r
234 @retval TRUE The handle of the controller need the Dhcp protocol.\r
235 @retval FALSE The handle of the controller does not need the Dhcp protocol.\r
236 \r
237**/\r
238BOOLEAN\r
239IScsiDhcpIsConfigured (\r
240 IN EFI_HANDLE Controller\r
241 );\r
242\r
12618416 243/**\r
12618416 244 Get the various configuration data of this iSCSI instance.\r
245\r
52ed4ff9 246 @param[in] Private The iSCSI driver data.\r
12618416 247\r
248 @retval EFI_SUCCESS The configuration of this instance is got.\r
52ed4ff9 249 @retval EFI_ABORTED The operation was aborted.\r
963dbb30 250 @retval Others Other errors as indicated.\r
12618416 251**/\r
6a690e23 252EFI_STATUS\r
253IScsiGetConfigData (\r
254 IN ISCSI_DRIVER_DATA *Private\r
255 );\r
256\r
12618416 257/**\r
258 Get the device path of the iSCSI tcp connection and update it.\r
259\r
52ed4ff9 260 @param[in] Private The iSCSI driver data.\r
12618416 261\r
52ed4ff9 262 @return The updated device path.\r
963dbb30 263 @retval NULL Other errors as indicated.\r
12618416 264**/\r
52ed4ff9 265EFI_DEVICE_PATH_PROTOCOL *\r
6a690e23 266IScsiGetTcpConnDevicePath (\r
267 IN ISCSI_DRIVER_DATA *Private\r
268 );\r
269\r
12618416 270/**\r
271 Abort the session when the transition from BS to RT is initiated.\r
272\r
52ed4ff9 273 @param[in] Event The event signaled.\r
274 @param[in] Context The iSCSI driver data.\r
12618416 275**/\r
6a690e23 276VOID\r
277EFIAPI\r
278IScsiOnExitBootService (\r
279 IN EFI_EVENT Event,\r
280 IN VOID *Context\r
281 );\r
282\r
18b24f92
FS
283/**\r
284 Tests whether a controller handle is being managed by IScsi driver.\r
285\r
286 This function tests whether the driver specified by DriverBindingHandle is\r
287 currently managing the controller specified by ControllerHandle. This test\r
288 is performed by evaluating if the the protocol specified by ProtocolGuid is\r
289 present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
290 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
291 If ProtocolGuid is NULL, then ASSERT().\r
292\r
293 @param ControllerHandle A handle for a controller to test.\r
294 @param DriverBindingHandle Specifies the driver binding handle for the\r
295 driver.\r
296 @param ProtocolGuid Specifies the protocol that the driver specified\r
297 by DriverBindingHandle opens in its Start()\r
298 function.\r
299\r
300 @retval EFI_SUCCESS ControllerHandle is managed by the driver\r
301 specified by DriverBindingHandle.\r
302 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r
303 specified by DriverBindingHandle.\r
52ed4ff9 304\r
18b24f92
FS
305**/\r
306EFI_STATUS\r
307EFIAPI\r
308IScsiTestManagedDevice (\r
309 IN EFI_HANDLE ControllerHandle,\r
310 IN EFI_HANDLE DriverBindingHandle,\r
311 IN EFI_GUID *ProtocolGuid\r
312 );\r
6a690e23 313\r
314#endif\r