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