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