]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/IScsiDxe/IScsiMisc.h
NetworkPkg: fix an error lead building crash
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiMisc.h
CommitLineData
4c5a5e0c 1/** @file\r
2 Miscellaneous definitions for iSCSI driver.\r
3\r
42f0586d 4Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
4c5a5e0c 5This program and the accompanying materials\r
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
12\r
13**/\r
14\r
15#ifndef _ISCSI_MISC_H_\r
16#define _ISCSI_MISC_H_\r
17\r
18typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA;\r
19\r
42f0586d 20///\r
21/// IPv4 Device Path Node Length\r
22///\r
23#define IPv4_NODE_LEN_NEW_VERSIONS 27\r
24\r
25///\r
26/// IPv6 Device Path Node Length\r
27///\r
28#define IPv6_NODE_LEN_OLD_VERSIONS 43\r
29#define IPv6_NODE_LEN_NEW_VERSIONS 60\r
30\r
31///\r
32/// The ignored field StaticIpAddress's offset in old IPv6 Device Path\r
33///\r
84134928 34#define IPv6_OLD_IPADDRESS_OFFSET 42\r
42f0586d 35\r
4c5a5e0c 36#pragma pack(1)\r
37typedef struct _ISCSI_SESSION_CONFIG_NVDATA {\r
38 UINT16 TargetPort;\r
39 UINT8 Enabled;\r
40 UINT8 IpMode;\r
41\r
75dce340 42 EFI_IP_ADDRESS LocalIp;\r
4c5a5e0c 43 EFI_IPv4_ADDRESS SubnetMask;\r
75dce340 44 EFI_IP_ADDRESS Gateway;\r
4c5a5e0c 45\r
46 BOOLEAN InitiatorInfoFromDhcp;\r
47 BOOLEAN TargetInfoFromDhcp;\r
48 CHAR8 TargetName[ISCSI_NAME_MAX_SIZE];\r
49 EFI_IP_ADDRESS TargetIp;\r
75dce340 50 UINT8 PrefixLength;\r
4c5a5e0c 51 UINT8 BootLun[8];\r
52\r
53 UINT16 ConnectTimeout; ///< timout value in milliseconds\r
54 UINT8 ConnectRetryCount;\r
55 UINT8 IsId[6];\r
56} ISCSI_SESSION_CONFIG_NVDATA;\r
57#pragma pack()\r
58\r
59/**\r
60 Calculate the prefix length of the IPv4 subnet mask.\r
61\r
62 @param[in] SubnetMask The IPv4 subnet mask.\r
63\r
64 @return The prefix length of the subnet mask.\r
65 @retval 0 Other errors as indicated.\r
66\r
67**/\r
68UINT8\r
69IScsiGetSubnetMaskPrefixLength (\r
70 IN EFI_IPv4_ADDRESS *SubnetMask\r
71 );\r
72\r
73/**\r
74 Convert the hexadecimal encoded LUN string into the 64-bit LUN. \r
75\r
76 @param[in] Str The hexadecimal encoded LUN string.\r
77 @param[out] Lun Storage to return the 64-bit LUN.\r
78\r
79 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.\r
80 @retval EFI_INVALID_PARAMETER The string is malformatted.\r
81\r
82**/\r
83EFI_STATUS\r
84IScsiAsciiStrToLun (\r
85 IN CHAR8 *Str,\r
86 OUT UINT8 *Lun\r
87 );\r
88\r
89/**\r
90 Convert the 64-bit LUN into the hexadecimal encoded LUN string.\r
91\r
92 @param[in] Lun The 64-bit LUN.\r
93 @param[out] String The storage to return the hexadecimal encoded LUN string.\r
94\r
95**/\r
96VOID\r
97IScsiLunToUnicodeStr (\r
98 IN UINT8 *Lun,\r
99 OUT CHAR16 *String\r
100 );\r
101\r
102/**\r
103 Convert the mac address into a hexadecimal encoded "-" seperated string.\r
104\r
105 @param[in] Mac The mac address.\r
106 @param[in] Len Length in bytes of the mac address.\r
107 @param[in] VlanId VLAN ID of the network device.\r
108 @param[out] Str The storage to return the mac string.\r
109\r
110**/\r
111VOID\r
112IScsiMacAddrToStr (\r
113 IN EFI_MAC_ADDRESS *Mac,\r
114 IN UINT32 Len,\r
115 IN UINT16 VlanId,\r
116 OUT CHAR16 *Str\r
117 );\r
118\r
119/**\r
120 Convert the formatted IP address into the binary IP address.\r
121\r
122 @param[in] Str The UNICODE string.\r
123 @param[in] IpMode Indicates whether the IP address is v4 or v6.\r
124 @param[out] Ip The storage to return the ASCII string.\r
125\r
126 @retval EFI_SUCCESS The binary IP address is returned in Ip.\r
127 @retval EFI_INVALID_PARAMETER The IP string is malformatted or IpMode is\r
128 invalid.\r
129\r
130**/\r
131EFI_STATUS\r
132IScsiAsciiStrToIp (\r
133 IN CHAR8 *Str,\r
134 IN UINT8 IpMode,\r
135 OUT EFI_IP_ADDRESS *Ip\r
136 );\r
137\r
138/**\r
139 Convert the binary encoded buffer into a hexadecimal encoded string.\r
140\r
141 @param[in] BinBuffer The buffer containing the binary data.\r
142 @param[in] BinLength Length of the binary buffer.\r
143 @param[in, out] HexStr Pointer to the string.\r
144 @param[in, out] HexLength The length of the string.\r
145\r
146 @retval EFI_SUCCESS The binary data is converted to the hexadecimal string \r
147 and the length of the string is updated.\r
148 @retval EFI_BUFFER_TOO_SMALL The string is too small.\r
149 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
150\r
151**/\r
152EFI_STATUS\r
153IScsiBinToHex (\r
154 IN UINT8 *BinBuffer,\r
155 IN UINT32 BinLength,\r
156 IN OUT CHAR8 *HexStr,\r
157 IN OUT UINT32 *HexLength\r
158 );\r
159\r
160/**\r
161 Convert the hexadecimal string into a binary encoded buffer.\r
162\r
163 @param[in, out] BinBuffer The binary buffer.\r
164 @param[in, out] BinLength Length of the binary buffer.\r
165 @param[in] HexStr The hexadecimal string.\r
166\r
167 @retval EFI_SUCCESS The hexadecimal string is converted into a binary\r
168 encoded buffer.\r
169 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.\r
170\r
171**/\r
172EFI_STATUS\r
173IScsiHexToBin (\r
174 IN OUT UINT8 *BinBuffer,\r
175 IN OUT UINT32 *BinLength,\r
176 IN CHAR8 *HexStr\r
177 );\r
178\r
179\r
180/**\r
181 Convert the decimal-constant string or hex-constant string into a numerical value.\r
182\r
183 @param[in] Str String in decimal or hex.\r
184\r
185 @return The numerical value.\r
186\r
187**/\r
188UINTN\r
189IScsiNetNtoi (\r
190 IN CHAR8 *Str\r
191 );\r
192\r
193/**\r
194 Generate random numbers.\r
195\r
196 @param[in, out] Rand The buffer to contain random numbers.\r
197 @param[in] RandLength The length of the Rand buffer.\r
198\r
199**/\r
200VOID\r
201IScsiGenRandom (\r
202 IN OUT UINT8 *Rand,\r
203 IN UINTN RandLength\r
204 );\r
205\r
206/**\r
207 Record the NIC information in a global structure.\r
208\r
209 @param[in] Controller The handle of the controller.\r
210\r
211 @retval EFI_SUCCESS The operation is completed.\r
212 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this\r
213 operation.\r
214\r
215**/\r
216EFI_STATUS\r
217IScsiAddNic (\r
218 IN EFI_HANDLE Controller\r
219 );\r
220\r
221/**\r
222 Delete the recorded NIC information from a global structure. Also delete corresponding\r
223 attempts.\r
224\r
225 @param[in] Controller The handle of the controller.\r
226\r
227 @retval EFI_SUCCESS The operation completed.\r
228 @retval EFI_NOT_FOUND The NIC information to be deleted is not recorded.\r
229\r
230**/\r
231EFI_STATUS\r
232IScsiRemoveNic (\r
233 IN EFI_HANDLE Controller\r
234 );\r
235\r
236/**\r
237 Get the recorded NIC information from a global structure by the Index.\r
238\r
239 @param[in] NicIndex The index indicates the position of NIC info.\r
240\r
241 @return Pointer to the NIC info or NULL if not found.\r
242\r
243**/\r
244ISCSI_NIC_INFO *\r
245IScsiGetNicInfoByIndex (\r
246 IN UINT8 NicIndex\r
247 );\r
248\r
249\r
250/**\r
251 Get the NIC's PCI location and return it accroding to the composited\r
252 format defined in iSCSI Boot Firmware Table.\r
253\r
254 @param[in] Controller The handle of the controller.\r
255 @param[out] Bus The bus number.\r
256 @param[out] Device The device number.\r
257 @param[out] Function The function number.\r
258\r
259 @return The composited representation of the NIC PCI location.\r
260\r
261**/\r
262UINT16\r
263IScsiGetNICPciLocation (\r
264 IN EFI_HANDLE Controller,\r
265 OUT UINTN *Bus,\r
266 OUT UINTN *Device,\r
267 OUT UINTN *Function\r
268 );\r
269\r
270/**\r
271 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r
272 buffer, and the size of the buffer. If failure, return NULL.\r
273\r
274 @param[in] Name String part of EFI variable name.\r
275 @param[in] VendorGuid GUID part of EFI variable name.\r
276 @param[out] VariableSize Returns the size of the EFI variable that was read.\r
277\r
278 @return Dynamically allocated memory that contains a copy of the EFI variable.\r
279 @return Caller is responsible freeing the buffer.\r
280 @retval NULL Variable was not read.\r
281\r
282**/\r
283VOID *\r
284IScsiGetVariableAndSize (\r
285 IN CHAR16 *Name,\r
286 IN EFI_GUID *VendorGuid,\r
287 OUT UINTN *VariableSize\r
288 );\r
289\r
290/**\r
291 Create the iSCSI driver data.\r
292\r
293 @param[in] Image The handle of the driver image.\r
294 @param[in] Controller The handle of the controller.\r
295\r
296 @return The iSCSI driver data created.\r
297 @retval NULL Other errors as indicated.\r
298\r
299**/\r
300ISCSI_DRIVER_DATA *\r
301IScsiCreateDriverData (\r
302 IN EFI_HANDLE Image,\r
303 IN EFI_HANDLE Controller\r
304 );\r
305\r
306/**\r
307 Clean the iSCSI driver data.\r
308\r
309 @param[in] Private The iSCSI driver data.\r
310\r
311**/\r
312VOID\r
313IScsiCleanDriverData (\r
314 IN ISCSI_DRIVER_DATA *Private\r
315 );\r
316\r
b7cc5bf1
WJ
317/**\r
318 Check wheather the Controller handle is configured to use DHCP protocol.\r
319\r
320 @param[in] Controller The handle of the controller.\r
321 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r
322 \r
323 @retval TRUE The handle of the controller need the Dhcp protocol.\r
324 @retval FALSE The handle of the controller does not need the Dhcp protocol.\r
325 \r
326**/\r
327BOOLEAN\r
328IScsiDhcpIsConfigured (\r
329 IN EFI_HANDLE Controller,\r
330 IN UINT8 IpVersion\r
331 );\r
332\r
4c5a5e0c 333/**\r
334 Get the various configuration data of this iSCSI instance.\r
335\r
336 @param[in] Private The iSCSI driver data.\r
337\r
338 @retval EFI_SUCCESS Obtained the configuration of this instance.\r
339 @retval EFI_ABORTED The operation was aborted.\r
340 @retval Others Other errors as indicated.\r
341\r
342**/\r
343EFI_STATUS\r
344IScsiGetConfigData (\r
345 IN ISCSI_DRIVER_DATA *Private\r
346 );\r
347\r
348/**\r
349 Get the device path of the iSCSI tcp connection and update it.\r
350\r
351 @param[in] Session The iSCSI session data.\r
352\r
353 @return The updated device path.\r
354 @retval NULL Other errors as indicated.\r
355\r
356**/\r
357EFI_DEVICE_PATH_PROTOCOL *\r
358IScsiGetTcpConnDevicePath (\r
359 IN ISCSI_SESSION *Session\r
360 );\r
361\r
362/**\r
363 Abort the session when the transition from BS to RT is initiated.\r
364\r
365 @param[in] Event The event signaled.\r
366 @param[in] Context The iSCSI driver data.\r
367\r
368**/\r
369VOID\r
370EFIAPI\r
371IScsiOnExitBootService (\r
372 IN EFI_EVENT Event,\r
373 IN VOID *Context\r
374 );\r
375\r
18b24f92
FS
376/**\r
377 Tests whether a controller handle is being managed by IScsi driver.\r
378\r
379 This function tests whether the driver specified by DriverBindingHandle is\r
380 currently managing the controller specified by ControllerHandle. This test\r
381 is performed by evaluating if the the protocol specified by ProtocolGuid is\r
382 present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
383 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
384 If ProtocolGuid is NULL, then ASSERT().\r
385\r
386 @param ControllerHandle A handle for a controller to test.\r
387 @param DriverBindingHandle Specifies the driver binding handle for the\r
388 driver.\r
389 @param ProtocolGuid Specifies the protocol that the driver specified\r
390 by DriverBindingHandle opens in its Start()\r
391 function.\r
392\r
393 @retval EFI_SUCCESS ControllerHandle is managed by the driver\r
394 specified by DriverBindingHandle.\r
395 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r
396 specified by DriverBindingHandle.\r
397\r
398**/\r
399EFI_STATUS\r
400EFIAPI\r
401IScsiTestManagedDevice (\r
402 IN EFI_HANDLE ControllerHandle,\r
403 IN EFI_HANDLE DriverBindingHandle,\r
404 IN EFI_GUID *ProtocolGuid\r
405 );\r
4c5a5e0c 406#endif\r