]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiMisc.h
... / ...
CommitLineData
1/** @file\r
2 Miscellaneous definitions for iSCSI driver.\r
3\r
4Copyright (c) 2004 - 2018, 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
18#include <Library/BaseLib.h>\r
19\r
20typedef struct _ISCSI_SESSION_CONFIG_DATA ISCSI_SESSION_CONFIG_DATA;\r
21\r
22///\r
23/// IPv4 Device Path Node Length\r
24///\r
25#define IP4_NODE_LEN_NEW_VERSIONS 27\r
26\r
27#pragma pack(1)\r
28typedef struct {\r
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
41\r
42 UINT8 IsId[6];\r
43} ISCSI_SESSION_CONFIG_NVDATA;\r
44#pragma pack()\r
45\r
46struct _ISCSI_SESSION_CONFIG_DATA {\r
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
52};\r
53\r
54/**\r
55 Calculate the prefix length of the IPv4 subnet mask.\r
56\r
57 @param[in] SubnetMask The IPv4 subnet mask.\r
58\r
59 @return The prefix length of the subnet mask.\r
60 @retval 0 Other errors as indicated.\r
61**/\r
62UINT8\r
63IScsiGetSubnetMaskPrefixLength (\r
64 IN EFI_IPv4_ADDRESS *SubnetMask\r
65 );\r
66\r
67/**\r
68 Convert the hexadecimal encoded LUN string into the 64-bit LUN.\r
69\r
70 @param[in] Str The hexadecimal encoded LUN string.\r
71 @param[out] Lun Storage to return the 64-bit LUN.\r
72\r
73 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.\r
74 @retval EFI_INVALID_PARAMETER The string is malformatted.\r
75**/\r
76EFI_STATUS\r
77IScsiAsciiStrToLun (\r
78 IN CHAR8 *Str,\r
79 OUT UINT8 *Lun\r
80 );\r
81\r
82/**\r
83 Convert the 64-bit LUN into the hexadecimal encoded LUN string.\r
84\r
85 @param[in] Lun The 64-bit LUN.\r
86 @param[out] Str The storage to return the hexadecimal encoded LUN string.\r
87**/\r
88VOID\r
89IScsiLunToUnicodeStr (\r
90 IN UINT8 *Lun,\r
91 OUT CHAR16 *Str\r
92 );\r
93\r
94/**\r
95 Convert the ASCII string into a UNICODE string.\r
96\r
97 @param[in] Source The ASCII string.\r
98 @param[out] Destination The storage to return the UNICODE string.\r
99\r
100 @return CHAR16 * Pointer to the UNICODE string.\r
101**/\r
102CHAR16 *\r
103IScsiAsciiStrToUnicodeStr (\r
104 IN CHAR8 *Source,\r
105 OUT CHAR16 *Destination\r
106 );\r
107\r
108/**\r
109 Convert the UNICODE string into an ASCII string.\r
110\r
111 @param[in] Source The UNICODE string.\r
112 @param[out] Destination The storage to return the ASCII string.\r
113\r
114 @return CHAR8 * Pointer to the ASCII string.\r
115**/\r
116CHAR8 *\r
117IScsiUnicodeStrToAsciiStr (\r
118 IN CHAR16 *Source,\r
119 OUT CHAR8 *Destination\r
120 );\r
121\r
122/**\r
123 Convert the mac address into a hexadecimal encoded "-" seperated string.\r
124\r
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
129**/\r
130VOID\r
131IScsiMacAddrToStr (\r
132 IN EFI_MAC_ADDRESS *Mac,\r
133 IN UINT32 Len,\r
134 IN UINT16 VlanId,\r
135 OUT CHAR16 *Str\r
136 );\r
137\r
138/**\r
139 Convert the decimal dotted IPv4 address into the binary IPv4 address.\r
140\r
141 @param[in] Str The UNICODE string.\r
142 @param[out] Ip The storage to return the ASCII string.\r
143\r
144 @retval EFI_SUCCESS The binary IP address is returned in Ip.\r
145 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
146**/\r
147EFI_STATUS\r
148IScsiAsciiStrToIp (\r
149 IN CHAR8 *Str,\r
150 OUT EFI_IPv4_ADDRESS *Ip\r
151 );\r
152\r
153/**\r
154 Convert the binary encoded buffer into a hexadecimal encoded string.\r
155\r
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
160\r
161 @retval EFI_SUCCESS The binary data is converted to the hexadecimal string\r
162 and the length of the string is updated.\r
163 @retval EFI_BUFFER_TOO_SMALL The string is too small.\r
164 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
165**/\r
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
174/**\r
175 Convert the hexadecimal string into a binary encoded buffer.\r
176\r
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
180\r
181 @retval EFI_SUCCESS The hexadecimal string is converted into a binary\r
182 encoded buffer.\r
183 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.\r
184**/\r
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
192/**\r
193 Generate random numbers.\r
194\r
195 @param[in, out] Rand The buffer to contain random numbers.\r
196 @param[in] RandLength The length of the Rand buffer.\r
197**/\r
198VOID\r
199IScsiGenRandom (\r
200 IN OUT UINT8 *Rand,\r
201 IN UINTN RandLength\r
202 );\r
203\r
204/**\r
205 Create the iSCSI driver data..\r
206\r
207 @param[in] Image The handle of the driver image.\r
208 @param[in] Controller The handle of the controller.\r
209\r
210 @return The iSCSI driver data created.\r
211 @retval NULL Other errors as indicated.\r
212**/\r
213ISCSI_DRIVER_DATA *\r
214IScsiCreateDriverData (\r
215 IN EFI_HANDLE Image,\r
216 IN EFI_HANDLE Controller\r
217 );\r
218\r
219/**\r
220 Clean the iSCSI driver data.\r
221\r
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
226**/\r
227EFI_STATUS\r
228IScsiCleanDriverData (\r
229 IN ISCSI_DRIVER_DATA *Private\r
230 );\r
231\r
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
236\r
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
239\r
240**/\r
241BOOLEAN\r
242IScsiDhcpIsConfigured (\r
243 IN EFI_HANDLE Controller\r
244 );\r
245\r
246/**\r
247 Get the various configuration data of this iSCSI instance.\r
248\r
249 @param[in] Private The iSCSI driver data.\r
250\r
251 @retval EFI_SUCCESS The configuration of this instance is got.\r
252 @retval EFI_ABORTED The operation was aborted.\r
253 @retval Others Other errors as indicated.\r
254**/\r
255EFI_STATUS\r
256IScsiGetConfigData (\r
257 IN ISCSI_DRIVER_DATA *Private\r
258 );\r
259\r
260/**\r
261 Get the device path of the iSCSI tcp connection and update it.\r
262\r
263 @param[in] Private The iSCSI driver data.\r
264\r
265 @return The updated device path.\r
266 @retval NULL Other errors as indicated.\r
267**/\r
268EFI_DEVICE_PATH_PROTOCOL *\r
269IScsiGetTcpConnDevicePath (\r
270 IN ISCSI_DRIVER_DATA *Private\r
271 );\r
272\r
273/**\r
274 Abort the session when the transition from BS to RT is initiated.\r
275\r
276 @param[in] Event The event signaled.\r
277 @param[in] Context The iSCSI driver data.\r
278**/\r
279VOID\r
280EFIAPI\r
281IScsiOnExitBootService (\r
282 IN EFI_EVENT Event,\r
283 IN VOID *Context\r
284 );\r
285\r
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
293 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r
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
307\r
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
316\r
317#endif\r