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