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