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