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