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