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