]>
Commit | Line | Data |
---|---|---|
7dbc50bd YZ |
1 | /** @file\r |
2 | Definition for Device Path library.\r | |
3 | \r | |
4 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r | |
2e351cbe | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
7dbc50bd YZ |
6 | \r |
7 | **/\r | |
8 | #ifndef _UEFI_DEVICE_PATH_LIB_H_\r | |
9 | #define _UEFI_DEVICE_PATH_LIB_H_\r | |
10 | \r | |
11 | #include <stdio.h>\r | |
12 | #include <stdlib.h>\r | |
13 | #include <string.h>\r | |
14 | #include <ctype.h>\r | |
15 | #include <assert.h>\r | |
16 | #ifdef __GNUC__\r | |
17 | #include <unistd.h>\r | |
18 | #else\r | |
19 | #include <direct.h>\r | |
20 | #endif\r | |
21 | #include <Common/UefiBaseTypes.h>\r | |
22 | #include <Protocol/DevicePath.h>\r | |
23 | #include <Protocol/DevicePathUtilities.h>\r | |
24 | #include "CommonLib.h"\r | |
25 | #include "EfiUtilityMsgs.h"\r | |
26 | \r | |
27 | #define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r | |
28 | #define MAX_DEVICE_PATH_NODE_COUNT 1024\r | |
29 | #define SIZE_64KB 0x00010000\r | |
30 | \r | |
31 | //\r | |
32 | // Private Data structure\r | |
33 | //\r | |
34 | typedef\r | |
35 | EFI_DEVICE_PATH_PROTOCOL *\r | |
36 | (*DEVICE_PATH_FROM_TEXT) (\r | |
37 | IN CHAR16 *Str\r | |
38 | );\r | |
39 | \r | |
40 | typedef struct {\r | |
41 | CHAR16 *Str;\r | |
42 | UINTN Count;\r | |
43 | UINTN Capacity;\r | |
44 | } POOL_PRINT;\r | |
45 | \r | |
46 | \r | |
47 | typedef struct {\r | |
48 | CHAR16 *DevicePathNodeText;\r | |
49 | DEVICE_PATH_FROM_TEXT Function;\r | |
50 | } DEVICE_PATH_FROM_TEXT_TABLE;\r | |
51 | \r | |
52 | typedef struct {\r | |
53 | BOOLEAN ClassExist;\r | |
54 | UINT8 Class;\r | |
55 | BOOLEAN SubClassExist;\r | |
56 | UINT8 SubClass;\r | |
57 | } USB_CLASS_TEXT;\r | |
58 | \r | |
59 | #define USB_CLASS_AUDIO 1\r | |
60 | #define USB_CLASS_CDCCONTROL 2\r | |
61 | #define USB_CLASS_HID 3\r | |
62 | #define USB_CLASS_IMAGE 6\r | |
63 | #define USB_CLASS_PRINTER 7\r | |
64 | #define USB_CLASS_MASS_STORAGE 8\r | |
65 | #define USB_CLASS_HUB 9\r | |
66 | #define USB_CLASS_CDCDATA 10\r | |
67 | #define USB_CLASS_SMART_CARD 11\r | |
68 | #define USB_CLASS_VIDEO 14\r | |
69 | #define USB_CLASS_DIAGNOSTIC 220\r | |
70 | #define USB_CLASS_WIRELESS 224\r | |
71 | \r | |
72 | #define USB_CLASS_RESERVE 254\r | |
73 | #define USB_SUBCLASS_FW_UPDATE 1\r | |
74 | #define USB_SUBCLASS_IRDA_BRIDGE 2\r | |
75 | #define USB_SUBCLASS_TEST 3\r | |
76 | \r | |
77 | #define RFC_1700_UDP_PROTOCOL 17\r | |
78 | #define RFC_1700_TCP_PROTOCOL 6\r | |
79 | \r | |
80 | #pragma pack(1)\r | |
81 | \r | |
82 | typedef struct {\r | |
83 | EFI_DEVICE_PATH_PROTOCOL Header;\r | |
84 | EFI_GUID Guid;\r | |
85 | UINT8 VendorDefinedData[1];\r | |
86 | } VENDOR_DEFINED_HARDWARE_DEVICE_PATH;\r | |
87 | \r | |
88 | typedef struct {\r | |
89 | EFI_DEVICE_PATH_PROTOCOL Header;\r | |
90 | EFI_GUID Guid;\r | |
91 | UINT8 VendorDefinedData[1];\r | |
92 | } VENDOR_DEFINED_MESSAGING_DEVICE_PATH;\r | |
93 | \r | |
94 | typedef struct {\r | |
95 | EFI_DEVICE_PATH_PROTOCOL Header;\r | |
96 | EFI_GUID Guid;\r | |
97 | UINT8 VendorDefinedData[1];\r | |
98 | } VENDOR_DEFINED_MEDIA_DEVICE_PATH;\r | |
99 | \r | |
100 | typedef struct {\r | |
101 | EFI_DEVICE_PATH_PROTOCOL Header;\r | |
102 | UINT32 Hid;\r | |
103 | UINT32 Uid;\r | |
104 | UINT32 Cid;\r | |
105 | CHAR8 HidUidCidStr[3];\r | |
106 | } ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR;\r | |
107 | \r | |
108 | typedef struct {\r | |
109 | EFI_DEVICE_PATH_PROTOCOL Header;\r | |
110 | UINT16 NetworkProtocol;\r | |
111 | UINT16 LoginOption;\r | |
112 | UINT64 Lun;\r | |
113 | UINT16 TargetPortalGroupTag;\r | |
114 | CHAR8 TargetName[1];\r | |
115 | } ISCSI_DEVICE_PATH_WITH_NAME;\r | |
116 | \r | |
117 | typedef struct {\r | |
118 | EFI_DEVICE_PATH_PROTOCOL Header;\r | |
119 | EFI_GUID Guid;\r | |
120 | UINT8 VendorDefinedData[1];\r | |
121 | } VENDOR_DEVICE_PATH_WITH_DATA;\r | |
122 | \r | |
123 | #pragma pack()\r | |
124 | \r | |
125 | /**\r | |
126 | Returns the size of a device path in bytes.\r | |
127 | \r | |
128 | This function returns the size, in bytes, of the device path data structure\r | |
129 | specified by DevicePath including the end of device path node.\r | |
130 | If DevicePath is NULL or invalid, then 0 is returned.\r | |
131 | \r | |
132 | @param DevicePath A pointer to a device path data structure.\r | |
133 | \r | |
134 | @retval 0 If DevicePath is NULL or invalid.\r | |
135 | @retval Others The size of a device path in bytes.\r | |
136 | \r | |
137 | **/\r | |
138 | UINTN\r | |
139 | UefiDevicePathLibGetDevicePathSize (\r | |
140 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
141 | );\r | |
142 | \r | |
143 | /**\r | |
144 | Creates a new copy of an existing device path.\r | |
145 | \r | |
146 | This function allocates space for a new copy of the device path specified by DevicePath.\r | |
147 | If DevicePath is NULL, then NULL is returned. If the memory is successfully\r | |
148 | allocated, then the contents of DevicePath are copied to the newly allocated\r | |
149 | buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.\r | |
150 | The memory for the new device path is allocated from EFI boot services memory.\r | |
151 | It is the responsibility of the caller to free the memory allocated.\r | |
152 | \r | |
153 | @param DevicePath A pointer to a device path data structure.\r | |
154 | \r | |
155 | @retval NULL DevicePath is NULL or invalid.\r | |
156 | @retval Others A pointer to the duplicated device path.\r | |
157 | \r | |
158 | **/\r | |
159 | EFI_DEVICE_PATH_PROTOCOL *\r | |
160 | UefiDevicePathLibDuplicateDevicePath (\r | |
161 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
162 | );\r | |
163 | \r | |
164 | /**\r | |
165 | Creates a new device path by appending a second device path to a first device path.\r | |
166 | \r | |
167 | This function creates a new device path by appending a copy of SecondDevicePath\r | |
168 | to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path\r | |
169 | device node from SecondDevicePath is retained. The newly created device path is\r | |
170 | returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r | |
171 | SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,\r | |
172 | and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r | |
173 | SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r | |
174 | \r | |
175 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r | |
176 | The memory for the new device path is allocated from EFI boot services memory.\r | |
177 | It is the responsibility of the caller to free the memory allocated.\r | |
178 | \r | |
179 | @param FirstDevicePath A pointer to a device path data structure.\r | |
180 | @param SecondDevicePath A pointer to a device path data structure.\r | |
181 | \r | |
182 | @retval NULL If there is not enough memory for the newly allocated buffer.\r | |
183 | @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r | |
184 | @retval Others A pointer to the new device path if success.\r | |
185 | Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r | |
186 | \r | |
187 | **/\r | |
188 | EFI_DEVICE_PATH_PROTOCOL *\r | |
189 | UefiDevicePathLibAppendDevicePath (\r | |
190 | CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
191 | CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
192 | );\r | |
193 | \r | |
194 | /**\r | |
195 | Creates a new path by appending the device node to the device path.\r | |
196 | \r | |
197 | This function creates a new device path by appending a copy of the device node\r | |
198 | specified by DevicePathNode to a copy of the device path specified by DevicePath\r | |
199 | in an allocated buffer. The end-of-device-path device node is moved after the\r | |
200 | end of the appended device node.\r | |
201 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r | |
202 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r | |
203 | path device node is returned.\r | |
204 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r | |
205 | device node is returned.\r | |
206 | If there is not enough memory to allocate space for the new device path, then\r | |
207 | NULL is returned.\r | |
208 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
209 | of the caller to free the memory allocated.\r | |
210 | \r | |
211 | @param DevicePath A pointer to a device path data structure.\r | |
212 | @param DevicePathNode A pointer to a single device path node.\r | |
213 | \r | |
214 | @retval NULL If there is not enough memory for the new device path.\r | |
215 | @retval Others A pointer to the new device path if success.\r | |
216 | A copy of DevicePathNode followed by an end-of-device-path node\r | |
217 | if both FirstDevicePath and SecondDevicePath are NULL.\r | |
218 | A copy of an end-of-device-path node if both FirstDevicePath\r | |
219 | and SecondDevicePath are NULL.\r | |
220 | \r | |
221 | **/\r | |
222 | EFI_DEVICE_PATH_PROTOCOL *\r | |
223 | UefiDevicePathLibAppendDevicePathNode (\r | |
224 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
225 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
226 | );\r | |
227 | \r | |
228 | /**\r | |
229 | Creates a new device path by appending the specified device path instance to the specified device\r | |
230 | path.\r | |
231 | \r | |
232 | This function creates a new device path by appending a copy of the device path\r | |
233 | instance specified by DevicePathInstance to a copy of the device path specified\r | |
234 | by DevicePath in a allocated buffer.\r | |
235 | The end-of-device-path device node is moved after the end of the appended device\r | |
236 | path instance and a new end-of-device-path-instance node is inserted between.\r | |
237 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
238 | If DevicePathInstance is NULL, then NULL is returned.\r | |
239 | If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r | |
240 | If there is not enough memory to allocate space for the new device path, then\r | |
241 | NULL is returned.\r | |
242 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
243 | of the caller to free the memory allocated.\r | |
244 | \r | |
245 | @param DevicePath A pointer to a device path data structure.\r | |
246 | @param DevicePathInstance A pointer to a device path instance.\r | |
247 | \r | |
248 | @return A pointer to the new device path.\r | |
249 | \r | |
250 | **/\r | |
251 | EFI_DEVICE_PATH_PROTOCOL *\r | |
252 | UefiDevicePathLibAppendDevicePathInstance (\r | |
253 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
254 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
255 | );\r | |
256 | \r | |
257 | /**\r | |
258 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
259 | instance.\r | |
260 | \r | |
261 | This function creates a copy of the current device path instance. It also updates\r | |
262 | DevicePath to point to the next device path instance in the device path (or NULL\r | |
263 | if no more) and updates Size to hold the size of the device path instance copy.\r | |
264 | If DevicePath is NULL, then NULL is returned.\r | |
265 | If DevicePath points to a invalid device path, then NULL is returned.\r | |
266 | If there is not enough memory to allocate space for the new device path, then\r | |
267 | NULL is returned.\r | |
268 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
269 | of the caller to free the memory allocated.\r | |
270 | If Size is NULL, then ASSERT().\r | |
271 | \r | |
272 | @param DevicePath On input, this holds the pointer to the current\r | |
273 | device path instance. On output, this holds\r | |
274 | the pointer to the next device path instance\r | |
275 | or NULL if there are no more device path\r | |
276 | instances in the device path pointer to a\r | |
277 | device path data structure.\r | |
278 | @param Size On output, this holds the size of the device\r | |
279 | path instance, in bytes or zero, if DevicePath\r | |
280 | is NULL.\r | |
281 | \r | |
282 | @return A pointer to the current device path instance.\r | |
283 | \r | |
284 | **/\r | |
285 | EFI_DEVICE_PATH_PROTOCOL *\r | |
286 | UefiDevicePathLibGetNextDevicePathInstance (\r | |
287 | EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
288 | UINTN *Size\r | |
289 | );\r | |
290 | \r | |
291 | /**\r | |
292 | Creates a device node.\r | |
293 | \r | |
294 | This function creates a new device node in a newly allocated buffer of size\r | |
295 | NodeLength and initializes the device path node header with NodeType and NodeSubType.\r | |
296 | The new device path node is returned.\r | |
297 | If NodeLength is smaller than a device path header, then NULL is returned.\r | |
298 | If there is not enough memory to allocate space for the new device path, then\r | |
299 | NULL is returned.\r | |
300 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
301 | of the caller to free the memory allocated.\r | |
302 | \r | |
303 | @param NodeType The device node type for the new device node.\r | |
304 | @param NodeSubType The device node sub-type for the new device node.\r | |
305 | @param NodeLength The length of the new device node.\r | |
306 | \r | |
307 | @return The new device path.\r | |
308 | \r | |
309 | **/\r | |
310 | EFI_DEVICE_PATH_PROTOCOL *\r | |
311 | UefiDevicePathLibCreateDeviceNode (\r | |
312 | UINT8 NodeType,\r | |
313 | UINT8 NodeSubType,\r | |
314 | UINT16 NodeLength\r | |
315 | );\r | |
316 | \r | |
317 | /**\r | |
318 | Determines if a device path is single or multi-instance.\r | |
319 | \r | |
320 | This function returns TRUE if the device path specified by DevicePath is\r | |
321 | multi-instance.\r | |
322 | Otherwise, FALSE is returned.\r | |
323 | If DevicePath is NULL or invalid, then FALSE is returned.\r | |
324 | \r | |
325 | @param DevicePath A pointer to a device path data structure.\r | |
326 | \r | |
327 | @retval TRUE DevicePath is multi-instance.\r | |
328 | @retval FALSE DevicePath is not multi-instance, or DevicePath\r | |
329 | is NULL or invalid.\r | |
330 | \r | |
331 | **/\r | |
332 | BOOLEAN\r | |
333 | UefiDevicePathLibIsDevicePathMultiInstance (\r | |
334 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
335 | );\r | |
336 | \r | |
337 | /**\r | |
338 | Convert text to the binary representation of a device node.\r | |
339 | \r | |
340 | @param TextDeviceNode TextDeviceNode points to the text representation of a device\r | |
341 | node. Conversion starts with the first character and continues\r | |
342 | until the first non-device node character.\r | |
343 | \r | |
344 | @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r | |
345 | insufficient memory or text unsupported.\r | |
346 | \r | |
347 | **/\r | |
348 | EFI_DEVICE_PATH_PROTOCOL *\r | |
349 | UefiDevicePathLibConvertTextToDeviceNode (\r | |
350 | CONST CHAR16 *TextDeviceNode\r | |
351 | );\r | |
352 | \r | |
353 | /**\r | |
354 | Convert text to the binary representation of a device path.\r | |
355 | \r | |
356 | \r | |
357 | @param TextDevicePath TextDevicePath points to the text representation of a device\r | |
358 | path. Conversion starts with the first character and continues\r | |
359 | until the first non-device node character.\r | |
360 | \r | |
361 | @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r | |
362 | there was insufficient memory.\r | |
363 | \r | |
364 | **/\r | |
365 | EFI_DEVICE_PATH_PROTOCOL *\r | |
366 | UefiDevicePathLibConvertTextToDevicePath (\r | |
367 | CONST CHAR16 *TextDevicePath\r | |
368 | );\r | |
369 | \r | |
370 | EFI_DEVICE_PATH_PROTOCOL *\r | |
7dbc50bd YZ |
371 | CreateDeviceNode (\r |
372 | UINT8 NodeType,\r | |
373 | UINT8 NodeSubType,\r | |
374 | UINT16 NodeLength\r | |
375 | );\r | |
376 | \r | |
377 | BOOLEAN\r | |
378 | IsDevicePathMultiInstance (\r | |
379 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
380 | );\r | |
381 | \r | |
382 | EFI_DEVICE_PATH_PROTOCOL *\r | |
383 | GetNextDevicePathInstance (\r | |
384 | EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
385 | UINTN *Size\r | |
386 | );\r | |
387 | \r | |
388 | EFI_DEVICE_PATH_PROTOCOL *\r | |
389 | AppendDevicePathInstance (\r | |
390 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
391 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
392 | );\r | |
393 | \r | |
394 | EFI_DEVICE_PATH_PROTOCOL *\r | |
395 | AppendDevicePathNode (\r | |
396 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
397 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
398 | );\r | |
399 | EFI_DEVICE_PATH_PROTOCOL *\r | |
400 | AppendDevicePath (\r | |
401 | CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
402 | CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
403 | );\r | |
404 | \r | |
405 | EFI_DEVICE_PATH_PROTOCOL *\r | |
406 | DuplicateDevicePath (\r | |
407 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
408 | );\r | |
409 | \r | |
410 | UINTN\r | |
411 | GetDevicePathSize (\r | |
412 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
413 | );\r | |
414 | \r | |
415 | CHAR16 *\r | |
416 | ConvertDeviceNodeToText (\r | |
417 | CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r | |
418 | BOOLEAN DisplayOnly,\r | |
419 | BOOLEAN AllowShortcuts\r | |
420 | );\r | |
421 | \r | |
422 | CHAR16 *\r | |
423 | ConvertDevicePathToText (\r | |
424 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
425 | BOOLEAN DisplayOnly,\r | |
426 | BOOLEAN AllowShortcuts\r | |
427 | );\r | |
428 | \r | |
429 | EFI_DEVICE_PATH_PROTOCOL *\r | |
430 | ConvertTextToDeviceNode (\r | |
431 | CONST CHAR16 *TextDeviceNode\r | |
432 | );\r | |
433 | \r | |
434 | EFI_DEVICE_PATH_PROTOCOL *\r | |
435 | ConvertTextToDevicePath (\r | |
436 | CONST CHAR16 *TextDevicePath\r | |
437 | );\r | |
438 | \r | |
439 | #endif\r |