UefiDevicePathLib.h 15 KB

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