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