• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Miscellaneous definitions for iSCSI driver.
3 
4 Copyright (c) 2004 - 2015, 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 #include <Library/BaseLib.h>
19 
20 typedef struct _ISCSI_SESSION_CONFIG_DATA ISCSI_SESSION_CONFIG_DATA;
21 
22 ///
23 /// IPv4 Device Path Node Length
24 ///
25 #define IP4_NODE_LEN_NEW_VERSIONS    27
26 
27 #pragma pack(1)
28 typedef struct {
29   BOOLEAN           Enabled;
30 
31   BOOLEAN           InitiatorInfoFromDhcp;
32   EFI_IPv4_ADDRESS  LocalIp;
33   EFI_IPv4_ADDRESS  SubnetMask;
34   EFI_IPv4_ADDRESS  Gateway;
35 
36   BOOLEAN           TargetInfoFromDhcp;
37   CHAR8             TargetName[ISCSI_NAME_MAX_SIZE];
38   EFI_IPv4_ADDRESS  TargetIp;
39   UINT16            TargetPort;
40   UINT8             BootLun[8];
41 
42   UINT8             IsId[6];
43 } ISCSI_SESSION_CONFIG_NVDATA;
44 #pragma pack()
45 
46 struct _ISCSI_SESSION_CONFIG_DATA {
47   ISCSI_SESSION_CONFIG_NVDATA NvData;
48 
49   EFI_IPv4_ADDRESS            PrimaryDns;
50   EFI_IPv4_ADDRESS            SecondaryDns;
51   EFI_IPv4_ADDRESS            DhcpServer;
52 };
53 
54 /**
55   Calculate the prefix length of the IPv4 subnet mask.
56 
57   @param[in]  SubnetMask The IPv4 subnet mask.
58 
59   @return The prefix length of the subnet mask.
60   @retval 0 Other errors as indicated.
61 **/
62 UINT8
63 IScsiGetSubnetMaskPrefixLength (
64   IN EFI_IPv4_ADDRESS  *SubnetMask
65   );
66 
67 /**
68   Convert the hexadecimal encoded LUN string into the 64-bit LUN.
69 
70   @param[in]   Str             The hexadecimal encoded LUN string.
71   @param[out]  Lun             Storage to return the 64-bit LUN.
72 
73   @retval EFI_SUCCESS           The 64-bit LUN is stored in Lun.
74   @retval EFI_INVALID_PARAMETER The string is malformatted.
75 **/
76 EFI_STATUS
77 IScsiAsciiStrToLun (
78   IN  CHAR8  *Str,
79   OUT UINT8  *Lun
80   );
81 
82 /**
83   Convert the 64-bit LUN into the hexadecimal encoded LUN string.
84 
85   @param[in]   Lun The 64-bit LUN.
86   @param[out]  Str The storage to return the hexadecimal encoded LUN string.
87 **/
88 VOID
89 IScsiLunToUnicodeStr (
90   IN UINT8    *Lun,
91   OUT CHAR16  *Str
92   );
93 
94 /**
95   Convert the ASCII string into a UNICODE string.
96 
97   @param[in]   Source      The ASCII string.
98   @param[out]  Destination The storage to return the UNICODE string.
99 
100   @return CHAR16 *         Pointer to the UNICODE string.
101 **/
102 CHAR16 *
103 IScsiAsciiStrToUnicodeStr (
104   IN  CHAR8   *Source,
105   OUT CHAR16  *Destination
106   );
107 
108 /**
109   Convert the UNICODE string into an ASCII string.
110 
111   @param[in]  Source       The UNICODE string.
112   @param[out] Destination  The storage to return the ASCII string.
113 
114   @return CHAR8 *          Pointer to the ASCII string.
115 **/
116 CHAR8 *
117 IScsiUnicodeStrToAsciiStr (
118   IN  CHAR16  *Source,
119   OUT CHAR8   *Destination
120   );
121 
122 /**
123   Convert the mac address into a hexadecimal encoded "-" seperated string.
124 
125   @param[in]  Mac     The mac address.
126   @param[in]  Len     Length in bytes of the mac address.
127   @param[in]  VlanId  VLAN ID of the network device.
128   @param[out] Str     The storage to return the mac string.
129 **/
130 VOID
131 IScsiMacAddrToStr (
132   IN  EFI_MAC_ADDRESS  *Mac,
133   IN  UINT32           Len,
134   IN  UINT16           VlanId,
135   OUT CHAR16           *Str
136   );
137 
138 /**
139   Convert the decimal dotted IPv4 address into the binary IPv4 address.
140 
141   @param[in]   Str             The UNICODE string.
142   @param[out]  Ip              The storage to return the ASCII string.
143 
144   @retval EFI_SUCCESS           The binary IP address is returned in Ip.
145   @retval EFI_INVALID_PARAMETER The IP string is malformatted.
146 **/
147 EFI_STATUS
148 IScsiAsciiStrToIp (
149   IN  CHAR8             *Str,
150   OUT EFI_IPv4_ADDRESS  *Ip
151   );
152 
153 /**
154   Convert the binary encoded buffer into a hexadecimal encoded string.
155 
156   @param[in]       BinBuffer   The buffer containing the binary data.
157   @param[in]       BinLength   Length of the binary buffer.
158   @param[in, out]  HexStr      Pointer to the string.
159   @param[in, out]  HexLength   The length of the string.
160 
161   @retval EFI_SUCCESS          The binary data is converted to the hexadecimal string
162                                and the length of the string is updated.
163   @retval EFI_BUFFER_TOO_SMALL The string is too small.
164   @retval EFI_INVALID_PARAMETER The IP string is malformatted.
165 **/
166 EFI_STATUS
167 IScsiBinToHex (
168   IN     UINT8  *BinBuffer,
169   IN     UINT32 BinLength,
170   IN OUT CHAR8  *HexStr,
171   IN OUT UINT32 *HexLength
172   );
173 
174 /**
175   Convert the hexadecimal string into a binary encoded buffer.
176 
177   @param[in, out]  BinBuffer   The binary buffer.
178   @param[in, out]  BinLength   Length of the binary buffer.
179   @param[in]       HexStr      The hexadecimal string.
180 
181   @retval EFI_SUCCESS          The hexadecimal string is converted into a binary
182                                encoded buffer.
183   @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the converted data.
184 **/
185 EFI_STATUS
186 IScsiHexToBin (
187   IN OUT UINT8  *BinBuffer,
188   IN OUT UINT32 *BinLength,
189   IN     CHAR8  *HexStr
190   );
191 
192 /**
193   Generate random numbers.
194 
195   @param[in, out]  Rand       The buffer to contain random numbers.
196   @param[in]       RandLength The length of the Rand buffer.
197 **/
198 VOID
199 IScsiGenRandom (
200   IN OUT UINT8  *Rand,
201   IN     UINTN  RandLength
202   );
203 
204 /**
205   Create the iSCSI driver data..
206 
207   @param[in] Image      The handle of the driver image.
208   @param[in] Controller The handle of the controller.
209 
210   @return The iSCSI driver data created.
211   @retval NULL Other errors as indicated.
212 **/
213 ISCSI_DRIVER_DATA *
214 IScsiCreateDriverData (
215   IN EFI_HANDLE  Image,
216   IN EFI_HANDLE  Controller
217   );
218 
219 /**
220   Clean the iSCSI driver data.
221 
222   @param[in]  Private The iSCSI driver data.
223 **/
224 VOID
225 IScsiCleanDriverData (
226   IN ISCSI_DRIVER_DATA  *Private
227   );
228 
229 /**
230   Check wheather the Controller is configured to use DHCP protocol.
231 
232   @param[in]  Controller           The handle of the controller.
233 
234   @retval TRUE                     The handle of the controller need the Dhcp protocol.
235   @retval FALSE                    The handle of the controller does not need the Dhcp protocol.
236 
237 **/
238 BOOLEAN
239 IScsiDhcpIsConfigured (
240   IN EFI_HANDLE  Controller
241   );
242 
243 /**
244   Get the various configuration data of this iSCSI instance.
245 
246   @param[in]  Private   The iSCSI driver data.
247 
248   @retval EFI_SUCCESS   The configuration of this instance is got.
249   @retval EFI_ABORTED   The operation was aborted.
250   @retval Others        Other errors as indicated.
251 **/
252 EFI_STATUS
253 IScsiGetConfigData (
254   IN ISCSI_DRIVER_DATA  *Private
255   );
256 
257 /**
258   Get the device path of the iSCSI tcp connection and update it.
259 
260   @param[in]  Private The iSCSI driver data.
261 
262   @return The updated device path.
263   @retval NULL Other errors as indicated.
264 **/
265 EFI_DEVICE_PATH_PROTOCOL *
266 IScsiGetTcpConnDevicePath (
267   IN ISCSI_DRIVER_DATA  *Private
268   );
269 
270 /**
271   Abort the session when the transition from BS to RT is initiated.
272 
273   @param[in]   Event  The event signaled.
274   @param[in]  Context The iSCSI driver data.
275 **/
276 VOID
277 EFIAPI
278 IScsiOnExitBootService (
279   IN EFI_EVENT  Event,
280   IN VOID       *Context
281   );
282 
283 /**
284   Tests whether a controller handle is being managed by IScsi driver.
285 
286   This function tests whether the driver specified by DriverBindingHandle is
287   currently managing the controller specified by ControllerHandle.  This test
288   is performed by evaluating if the the protocol specified by ProtocolGuid is
289   present on ControllerHandle and is was opened by DriverBindingHandle and Nic
290   Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.
291   If ProtocolGuid is NULL, then ASSERT().
292 
293   @param  ControllerHandle     A handle for a controller to test.
294   @param  DriverBindingHandle  Specifies the driver binding handle for the
295                                driver.
296   @param  ProtocolGuid         Specifies the protocol that the driver specified
297                                by DriverBindingHandle opens in its Start()
298                                function.
299 
300   @retval EFI_SUCCESS          ControllerHandle is managed by the driver
301                                specified by DriverBindingHandle.
302   @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver
303                                specified by DriverBindingHandle.
304 
305 **/
306 EFI_STATUS
307 EFIAPI
308 IScsiTestManagedDevice (
309   IN  EFI_HANDLE       ControllerHandle,
310   IN  EFI_HANDLE       DriverBindingHandle,
311   IN  EFI_GUID         *ProtocolGuid
312   );
313 
314 #endif
315