17270962aSWarner Losh /*- 27270962aSWarner Losh * Copyright (c) 2017 Netflix, Inc. 37270962aSWarner Losh * 47270962aSWarner Losh * Redistribution and use in source and binary forms, with or without 57270962aSWarner Losh * modification, are permitted provided that the following conditions 67270962aSWarner Losh * are met: 77270962aSWarner Losh * 1. Redistributions of source code must retain the above copyright 86decf2ccSEd Maste * notice, this list of conditions and the following disclaimer. 97270962aSWarner Losh * 2. Redistributions in binary form must reproduce the above copyright 107270962aSWarner Losh * notice, this list of conditions and the following disclaimer in the 117270962aSWarner Losh * documentation and/or other materials provided with the distribution. 127270962aSWarner Losh * 136decf2ccSEd Maste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 146decf2ccSEd Maste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 156decf2ccSEd Maste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 166decf2ccSEd Maste * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 176decf2ccSEd Maste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 186decf2ccSEd Maste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 196decf2ccSEd Maste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 206decf2ccSEd Maste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 216decf2ccSEd Maste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 226decf2ccSEd Maste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 236decf2ccSEd Maste * SUCH DAMAGE. 247270962aSWarner Losh * 257270962aSWarner Losh * $FreeBSD$ 267270962aSWarner Losh */ 277270962aSWarner Losh 287270962aSWarner Losh /* 297270962aSWarner Losh * Taken from MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h 307270962aSWarner Losh */ 317270962aSWarner Losh 327270962aSWarner Losh /** @file 337270962aSWarner Losh Definition for Device Path library. 347270962aSWarner Losh 35*49951297SJose Luis Duran Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> 367270962aSWarner Losh This program and the accompanying materials 377270962aSWarner Losh are licensed and made available under the terms and conditions of the BSD License 387270962aSWarner Losh which accompanies this distribution. The full text of the license may be found at 397270962aSWarner Losh http://opensource.org/licenses/bsd-license.php 407270962aSWarner Losh 417270962aSWarner Losh THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 427270962aSWarner Losh WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 437270962aSWarner Losh 447270962aSWarner Losh **/ 457270962aSWarner Losh 467270962aSWarner Losh #ifndef _UEFI_DEVICE_PATH_LIB_H_ 477270962aSWarner Losh #define _UEFI_DEVICE_PATH_LIB_H_ 487270962aSWarner Losh #include <Uefi.h> 497270962aSWarner Losh #include <Protocol/DevicePathUtilities.h> 507270962aSWarner Losh #include <Protocol/DebugPort.h> 517270962aSWarner Losh #include <Protocol/DevicePathToText.h> 527270962aSWarner Losh #include <Protocol/DevicePathFromText.h> 537270962aSWarner Losh #include <Guid/PcAnsi.h> 547270962aSWarner Losh #include <Library/DebugLib.h> 557270962aSWarner Losh #include <Library/PrintLib.h> 567270962aSWarner Losh #include <Library/BaseLib.h> 577270962aSWarner Losh #include <Library/BaseMemoryLib.h> 587270962aSWarner Losh #include <Library/MemoryAllocationLib.h> 597270962aSWarner Losh #include <Library/UefiBootServicesTableLib.h> 607270962aSWarner Losh #include <Library/DevicePathLib.h> 617270962aSWarner Losh #include <Library/PcdLib.h> 627270962aSWarner Losh #include <IndustryStandard/Bluetooth.h> 637270962aSWarner Losh 647270962aSWarner Losh #define IS_COMMA(a) ((a) == ',') 657270962aSWarner Losh #define IS_HYPHEN(a) ((a) == '-') 667270962aSWarner Losh #define IS_DOT(a) ((a) == '.') 677270962aSWarner Losh #define IS_LEFT_PARENTH(a) ((a) == '(') 687270962aSWarner Losh #define IS_RIGHT_PARENTH(a) ((a) == ')') 697270962aSWarner Losh #define IS_SLASH(a) ((a) == '/') 707270962aSWarner Losh #define IS_NULL(a) ((a) == '\0') 717270962aSWarner Losh 727270962aSWarner Losh 737270962aSWarner Losh // 747270962aSWarner Losh // Private Data structure 757270962aSWarner Losh // 767270962aSWarner Losh typedef struct { 777270962aSWarner Losh char *Str; 787270962aSWarner Losh UINTN Count; 797270962aSWarner Losh UINTN Capacity; 807270962aSWarner Losh } POOL_PRINT; 817270962aSWarner Losh 827270962aSWarner Losh typedef 837270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 847270962aSWarner Losh (*DEVICE_PATH_FROM_TEXT) ( 857270962aSWarner Losh IN char *Str 867270962aSWarner Losh ); 877270962aSWarner Losh 887270962aSWarner Losh typedef 897270962aSWarner Losh VOID 907270962aSWarner Losh (*DEVICE_PATH_TO_TEXT) ( 917270962aSWarner Losh IN OUT POOL_PRINT *Str, 927270962aSWarner Losh IN VOID *DevicePath, 937270962aSWarner Losh IN BOOLEAN DisplayOnly, 947270962aSWarner Losh IN BOOLEAN AllowShortcuts 957270962aSWarner Losh ); 967270962aSWarner Losh 977270962aSWarner Losh typedef struct { 987270962aSWarner Losh UINT8 Type; 997270962aSWarner Losh UINT8 SubType; 1007270962aSWarner Losh DEVICE_PATH_TO_TEXT Function; 1017270962aSWarner Losh } DEVICE_PATH_TO_TEXT_TABLE; 1027270962aSWarner Losh 1037270962aSWarner Losh typedef struct { 1047270962aSWarner Losh UINT8 Type; 1057270962aSWarner Losh const char *Text; 1067270962aSWarner Losh } DEVICE_PATH_TO_TEXT_GENERIC_TABLE; 1077270962aSWarner Losh 1087270962aSWarner Losh typedef struct { 1097270962aSWarner Losh const char *DevicePathNodeText; 1107270962aSWarner Losh DEVICE_PATH_FROM_TEXT Function; 1117270962aSWarner Losh } DEVICE_PATH_FROM_TEXT_TABLE; 1127270962aSWarner Losh 1137270962aSWarner Losh typedef struct { 1147270962aSWarner Losh BOOLEAN ClassExist; 1157270962aSWarner Losh UINT8 Class; 1167270962aSWarner Losh BOOLEAN SubClassExist; 1177270962aSWarner Losh UINT8 SubClass; 1187270962aSWarner Losh } USB_CLASS_TEXT; 1197270962aSWarner Losh 1207270962aSWarner Losh #define USB_CLASS_AUDIO 1 1217270962aSWarner Losh #define USB_CLASS_CDCCONTROL 2 1227270962aSWarner Losh #define USB_CLASS_HID 3 1237270962aSWarner Losh #define USB_CLASS_IMAGE 6 1247270962aSWarner Losh #define USB_CLASS_PRINTER 7 1257270962aSWarner Losh #define USB_CLASS_MASS_STORAGE 8 1267270962aSWarner Losh #define USB_CLASS_HUB 9 1277270962aSWarner Losh #define USB_CLASS_CDCDATA 10 1287270962aSWarner Losh #define USB_CLASS_SMART_CARD 11 1297270962aSWarner Losh #define USB_CLASS_VIDEO 14 1307270962aSWarner Losh #define USB_CLASS_DIAGNOSTIC 220 1317270962aSWarner Losh #define USB_CLASS_WIRELESS 224 1327270962aSWarner Losh 1337270962aSWarner Losh #define USB_CLASS_RESERVE 254 1347270962aSWarner Losh #define USB_SUBCLASS_FW_UPDATE 1 1357270962aSWarner Losh #define USB_SUBCLASS_IRDA_BRIDGE 2 1367270962aSWarner Losh #define USB_SUBCLASS_TEST 3 1377270962aSWarner Losh 1387270962aSWarner Losh #define RFC_1700_UDP_PROTOCOL 17 1397270962aSWarner Losh #define RFC_1700_TCP_PROTOCOL 6 1407270962aSWarner Losh 1417270962aSWarner Losh #pragma pack(1) 1427270962aSWarner Losh 1437270962aSWarner Losh typedef struct { 1447270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL Header; 1457270962aSWarner Losh EFI_GUID Guid; 1467270962aSWarner Losh UINT8 VendorDefinedData[1]; 1477270962aSWarner Losh } VENDOR_DEFINED_HARDWARE_DEVICE_PATH; 1487270962aSWarner Losh 1497270962aSWarner Losh typedef struct { 1507270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL Header; 1517270962aSWarner Losh EFI_GUID Guid; 1527270962aSWarner Losh UINT8 VendorDefinedData[1]; 1537270962aSWarner Losh } VENDOR_DEFINED_MESSAGING_DEVICE_PATH; 1547270962aSWarner Losh 1557270962aSWarner Losh typedef struct { 1567270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL Header; 1577270962aSWarner Losh EFI_GUID Guid; 1587270962aSWarner Losh UINT8 VendorDefinedData[1]; 1597270962aSWarner Losh } VENDOR_DEFINED_MEDIA_DEVICE_PATH; 1607270962aSWarner Losh 1617270962aSWarner Losh typedef struct { 1627270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL Header; 1637270962aSWarner Losh UINT32 Hid; 1647270962aSWarner Losh UINT32 Uid; 1657270962aSWarner Losh UINT32 Cid; 1667270962aSWarner Losh CHAR8 HidUidCidStr[3]; 1677270962aSWarner Losh } ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR; 1687270962aSWarner Losh 1697270962aSWarner Losh typedef struct { 1707270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL Header; 1717270962aSWarner Losh UINT16 NetworkProtocol; 1727270962aSWarner Losh UINT16 LoginOption; 1737270962aSWarner Losh UINT64 Lun; 1747270962aSWarner Losh UINT16 TargetPortalGroupTag; 1757270962aSWarner Losh CHAR8 TargetName[1]; 1767270962aSWarner Losh } ISCSI_DEVICE_PATH_WITH_NAME; 1777270962aSWarner Losh 1787270962aSWarner Losh typedef struct { 1797270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL Header; 1807270962aSWarner Losh EFI_GUID Guid; 1817270962aSWarner Losh UINT8 VendorDefinedData[1]; 1827270962aSWarner Losh } VENDOR_DEVICE_PATH_WITH_DATA; 1837270962aSWarner Losh 1847270962aSWarner Losh #pragma pack() 1857270962aSWarner Losh 1867270962aSWarner Losh #ifdef FreeBSD /* Remove these on FreeBSD */ 1877270962aSWarner Losh 1887270962aSWarner Losh /** 1897270962aSWarner Losh Returns the size of a device path in bytes. 1907270962aSWarner Losh 1917270962aSWarner Losh This function returns the size, in bytes, of the device path data structure 1927270962aSWarner Losh specified by DevicePath including the end of device path node. 1937270962aSWarner Losh If DevicePath is NULL or invalid, then 0 is returned. 1947270962aSWarner Losh 1957270962aSWarner Losh @param DevicePath A pointer to a device path data structure. 1967270962aSWarner Losh 1977270962aSWarner Losh @retval 0 If DevicePath is NULL or invalid. 1987270962aSWarner Losh @retval Others The size of a device path in bytes. 1997270962aSWarner Losh 2007270962aSWarner Losh **/ 2017270962aSWarner Losh UINTN 2027270962aSWarner Losh EFIAPI 2037270962aSWarner Losh UefiDevicePathLibGetDevicePathSize ( 2047270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath 2057270962aSWarner Losh ); 2067270962aSWarner Losh 2077270962aSWarner Losh /** 2087270962aSWarner Losh Creates a new copy of an existing device path. 2097270962aSWarner Losh 2107270962aSWarner Losh This function allocates space for a new copy of the device path specified by DevicePath. 2117270962aSWarner Losh If DevicePath is NULL, then NULL is returned. If the memory is successfully 2127270962aSWarner Losh allocated, then the contents of DevicePath are copied to the newly allocated 2137270962aSWarner Losh buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned. 2147270962aSWarner Losh The memory for the new device path is allocated from EFI boot services memory. 2157270962aSWarner Losh It is the responsibility of the caller to free the memory allocated. 2167270962aSWarner Losh 2177270962aSWarner Losh @param DevicePath A pointer to a device path data structure. 2187270962aSWarner Losh 2197270962aSWarner Losh @retval NULL DevicePath is NULL or invalid. 2207270962aSWarner Losh @retval Others A pointer to the duplicated device path. 2217270962aSWarner Losh 2227270962aSWarner Losh **/ 2237270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 2247270962aSWarner Losh EFIAPI 2257270962aSWarner Losh UefiDevicePathLibDuplicateDevicePath ( 2267270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath 2277270962aSWarner Losh ); 2287270962aSWarner Losh 2297270962aSWarner Losh /** 2307270962aSWarner Losh Creates a new device path by appending a second device path to a first device path. 2317270962aSWarner Losh 2327270962aSWarner Losh This function creates a new device path by appending a copy of SecondDevicePath 2337270962aSWarner Losh to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path 2347270962aSWarner Losh device node from SecondDevicePath is retained. The newly created device path is 2357270962aSWarner Losh returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of 2367270962aSWarner Losh SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored, 2377270962aSWarner Losh and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and 2387270962aSWarner Losh SecondDevicePath are NULL, then a copy of an end-of-device-path is returned. 2397270962aSWarner Losh 2407270962aSWarner Losh If there is not enough memory for the newly allocated buffer, then NULL is returned. 2417270962aSWarner Losh The memory for the new device path is allocated from EFI boot services memory. 2427270962aSWarner Losh It is the responsibility of the caller to free the memory allocated. 2437270962aSWarner Losh 2447270962aSWarner Losh @param FirstDevicePath A pointer to a device path data structure. 2457270962aSWarner Losh @param SecondDevicePath A pointer to a device path data structure. 2467270962aSWarner Losh 2477270962aSWarner Losh @retval NULL If there is not enough memory for the newly allocated buffer. 2487270962aSWarner Losh @retval NULL If FirstDevicePath or SecondDevicePath is invalid. 2497270962aSWarner Losh @retval Others A pointer to the new device path if success. 2507270962aSWarner Losh Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL. 2517270962aSWarner Losh 2527270962aSWarner Losh **/ 2537270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 2547270962aSWarner Losh EFIAPI 2557270962aSWarner Losh UefiDevicePathLibAppendDevicePath ( 2567270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL 2577270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL 2587270962aSWarner Losh ); 2597270962aSWarner Losh 2607270962aSWarner Losh /** 2617270962aSWarner Losh Creates a new path by appending the device node to the device path. 2627270962aSWarner Losh 2637270962aSWarner Losh This function creates a new device path by appending a copy of the device node 2647270962aSWarner Losh specified by DevicePathNode to a copy of the device path specified by DevicePath 2657270962aSWarner Losh in an allocated buffer. The end-of-device-path device node is moved after the 2667270962aSWarner Losh end of the appended device node. 2677270962aSWarner Losh If DevicePathNode is NULL then a copy of DevicePath is returned. 2687270962aSWarner Losh If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device 2697270962aSWarner Losh path device node is returned. 2707270962aSWarner Losh If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path 2717270962aSWarner Losh device node is returned. 2727270962aSWarner Losh If there is not enough memory to allocate space for the new device path, then 2737270962aSWarner Losh NULL is returned. 2747270962aSWarner Losh The memory is allocated from EFI boot services memory. It is the responsibility 2757270962aSWarner Losh of the caller to free the memory allocated. 2767270962aSWarner Losh 2777270962aSWarner Losh @param DevicePath A pointer to a device path data structure. 2787270962aSWarner Losh @param DevicePathNode A pointer to a single device path node. 2797270962aSWarner Losh 2807270962aSWarner Losh @retval NULL If there is not enough memory for the new device path. 2817270962aSWarner Losh @retval Others A pointer to the new device path if success. 2827270962aSWarner Losh A copy of DevicePathNode followed by an end-of-device-path node 2837270962aSWarner Losh if both FirstDevicePath and SecondDevicePath are NULL. 2847270962aSWarner Losh A copy of an end-of-device-path node if both FirstDevicePath 2857270962aSWarner Losh and SecondDevicePath are NULL. 2867270962aSWarner Losh 2877270962aSWarner Losh **/ 2887270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 2897270962aSWarner Losh EFIAPI 2907270962aSWarner Losh UefiDevicePathLibAppendDevicePathNode ( 2917270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL 2927270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL 2937270962aSWarner Losh ); 2947270962aSWarner Losh 2957270962aSWarner Losh /** 2967270962aSWarner Losh Creates a new device path by appending the specified device path instance to the specified device 2977270962aSWarner Losh path. 2987270962aSWarner Losh 2997270962aSWarner Losh This function creates a new device path by appending a copy of the device path 3007270962aSWarner Losh instance specified by DevicePathInstance to a copy of the device path specified 3017270962aSWarner Losh by DevicePath in a allocated buffer. 3027270962aSWarner Losh The end-of-device-path device node is moved after the end of the appended device 3037270962aSWarner Losh path instance and a new end-of-device-path-instance node is inserted between. 3047270962aSWarner Losh If DevicePath is NULL, then a copy if DevicePathInstance is returned. 3057270962aSWarner Losh If DevicePathInstance is NULL, then NULL is returned. 3067270962aSWarner Losh If DevicePath or DevicePathInstance is invalid, then NULL is returned. 3077270962aSWarner Losh If there is not enough memory to allocate space for the new device path, then 3087270962aSWarner Losh NULL is returned. 3097270962aSWarner Losh The memory is allocated from EFI boot services memory. It is the responsibility 3107270962aSWarner Losh of the caller to free the memory allocated. 3117270962aSWarner Losh 3127270962aSWarner Losh @param DevicePath A pointer to a device path data structure. 3137270962aSWarner Losh @param DevicePathInstance A pointer to a device path instance. 3147270962aSWarner Losh 3157270962aSWarner Losh @return A pointer to the new device path. 3167270962aSWarner Losh 3177270962aSWarner Losh **/ 3187270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 3197270962aSWarner Losh EFIAPI 3207270962aSWarner Losh UefiDevicePathLibAppendDevicePathInstance ( 3217270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL 3227270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL 3237270962aSWarner Losh ); 3247270962aSWarner Losh 3257270962aSWarner Losh /** 3267270962aSWarner Losh Creates a copy of the current device path instance and returns a pointer to the next device path 3277270962aSWarner Losh instance. 3287270962aSWarner Losh 3297270962aSWarner Losh This function creates a copy of the current device path instance. It also updates 3307270962aSWarner Losh DevicePath to point to the next device path instance in the device path (or NULL 3317270962aSWarner Losh if no more) and updates Size to hold the size of the device path instance copy. 3327270962aSWarner Losh If DevicePath is NULL, then NULL is returned. 3337270962aSWarner Losh If DevicePath points to a invalid device path, then NULL is returned. 3347270962aSWarner Losh If there is not enough memory to allocate space for the new device path, then 3357270962aSWarner Losh NULL is returned. 3367270962aSWarner Losh The memory is allocated from EFI boot services memory. It is the responsibility 3377270962aSWarner Losh of the caller to free the memory allocated. 3387270962aSWarner Losh If Size is NULL, then ASSERT(). 3397270962aSWarner Losh 3407270962aSWarner Losh @param DevicePath On input, this holds the pointer to the current 3417270962aSWarner Losh device path instance. On output, this holds 3427270962aSWarner Losh the pointer to the next device path instance 3437270962aSWarner Losh or NULL if there are no more device path 3447270962aSWarner Losh instances in the device path pointer to a 3457270962aSWarner Losh device path data structure. 3467270962aSWarner Losh @param Size On output, this holds the size of the device 3477270962aSWarner Losh path instance, in bytes or zero, if DevicePath 3487270962aSWarner Losh is NULL. 3497270962aSWarner Losh 3507270962aSWarner Losh @return A pointer to the current device path instance. 3517270962aSWarner Losh 3527270962aSWarner Losh **/ 3537270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 3547270962aSWarner Losh EFIAPI 3557270962aSWarner Losh UefiDevicePathLibGetNextDevicePathInstance ( 3567270962aSWarner Losh IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, 3577270962aSWarner Losh OUT UINTN *Size 3587270962aSWarner Losh ); 3597270962aSWarner Losh 3607270962aSWarner Losh /** 3617270962aSWarner Losh Creates a device node. 3627270962aSWarner Losh 3637270962aSWarner Losh This function creates a new device node in a newly allocated buffer of size 3647270962aSWarner Losh NodeLength and initializes the device path node header with NodeType and NodeSubType. 3657270962aSWarner Losh The new device path node is returned. 3667270962aSWarner Losh If NodeLength is smaller than a device path header, then NULL is returned. 3677270962aSWarner Losh If there is not enough memory to allocate space for the new device path, then 3687270962aSWarner Losh NULL is returned. 3697270962aSWarner Losh The memory is allocated from EFI boot services memory. It is the responsibility 3707270962aSWarner Losh of the caller to free the memory allocated. 3717270962aSWarner Losh 3727270962aSWarner Losh @param NodeType The device node type for the new device node. 3737270962aSWarner Losh @param NodeSubType The device node sub-type for the new device node. 3747270962aSWarner Losh @param NodeLength The length of the new device node. 3757270962aSWarner Losh 3767270962aSWarner Losh @return The new device path. 3777270962aSWarner Losh 3787270962aSWarner Losh **/ 3797270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 3807270962aSWarner Losh EFIAPI 3817270962aSWarner Losh UefiDevicePathLibCreateDeviceNode ( 3827270962aSWarner Losh IN UINT8 NodeType, 3837270962aSWarner Losh IN UINT8 NodeSubType, 3847270962aSWarner Losh IN UINT16 NodeLength 3857270962aSWarner Losh ); 3867270962aSWarner Losh 3877270962aSWarner Losh /** 3887270962aSWarner Losh Determines if a device path is single or multi-instance. 3897270962aSWarner Losh 3907270962aSWarner Losh This function returns TRUE if the device path specified by DevicePath is 3917270962aSWarner Losh multi-instance. 3927270962aSWarner Losh Otherwise, FALSE is returned. 3937270962aSWarner Losh If DevicePath is NULL or invalid, then FALSE is returned. 3947270962aSWarner Losh 3957270962aSWarner Losh @param DevicePath A pointer to a device path data structure. 3967270962aSWarner Losh 3977270962aSWarner Losh @retval TRUE DevicePath is multi-instance. 3987270962aSWarner Losh @retval FALSE DevicePath is not multi-instance, or DevicePath 3997270962aSWarner Losh is NULL or invalid. 4007270962aSWarner Losh 4017270962aSWarner Losh **/ 4027270962aSWarner Losh BOOLEAN 4037270962aSWarner Losh EFIAPI 4047270962aSWarner Losh UefiDevicePathLibIsDevicePathMultiInstance ( 4057270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath 4067270962aSWarner Losh ); 4077270962aSWarner Losh 4087270962aSWarner Losh 4097270962aSWarner Losh /** 4107270962aSWarner Losh Converts a device path to its text representation. 4117270962aSWarner Losh 4127270962aSWarner Losh @param DevicePath A Pointer to the device to be converted. 4137270962aSWarner Losh @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation 4147270962aSWarner Losh of the display node is used, where applicable. If DisplayOnly 4157270962aSWarner Losh is FALSE, then the longer text representation of the display node 4167270962aSWarner Losh is used. 4177270962aSWarner Losh @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text 4187270962aSWarner Losh representation for a device node can be used, where applicable. 4197270962aSWarner Losh 4207270962aSWarner Losh @return A pointer to the allocated text representation of the device path or 4217270962aSWarner Losh NULL if DeviceNode is NULL or there was insufficient memory. 4227270962aSWarner Losh 4237270962aSWarner Losh **/ 4247270962aSWarner Losh CHAR16 * 4257270962aSWarner Losh EFIAPI 4267270962aSWarner Losh UefiDevicePathLibConvertDevicePathToText ( 4277270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, 4287270962aSWarner Losh IN BOOLEAN DisplayOnly, 4297270962aSWarner Losh IN BOOLEAN AllowShortcuts 4307270962aSWarner Losh ); 4317270962aSWarner Losh 4327270962aSWarner Losh /** 4337270962aSWarner Losh Converts a device node to its string representation. 4347270962aSWarner Losh 4357270962aSWarner Losh @param DeviceNode A Pointer to the device node to be converted. 4367270962aSWarner Losh @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation 4377270962aSWarner Losh of the display node is used, where applicable. If DisplayOnly 4387270962aSWarner Losh is FALSE, then the longer text representation of the display node 4397270962aSWarner Losh is used. 4407270962aSWarner Losh @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text 4417270962aSWarner Losh representation for a device node can be used, where applicable. 4427270962aSWarner Losh 4437270962aSWarner Losh @return A pointer to the allocated text representation of the device node or NULL if DeviceNode 4447270962aSWarner Losh is NULL or there was insufficient memory. 4457270962aSWarner Losh 4467270962aSWarner Losh **/ 4477270962aSWarner Losh CHAR16 * 4487270962aSWarner Losh EFIAPI 4497270962aSWarner Losh UefiDevicePathLibConvertDeviceNodeToText ( 4507270962aSWarner Losh IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode, 4517270962aSWarner Losh IN BOOLEAN DisplayOnly, 4527270962aSWarner Losh IN BOOLEAN AllowShortcuts 4537270962aSWarner Losh ); 4547270962aSWarner Losh 4557270962aSWarner Losh /** 4567270962aSWarner Losh Convert text to the binary representation of a device node. 4577270962aSWarner Losh 4587270962aSWarner Losh @param TextDeviceNode TextDeviceNode points to the text representation of a device 4597270962aSWarner Losh node. Conversion starts with the first character and continues 4607270962aSWarner Losh until the first non-device node character. 4617270962aSWarner Losh 4627270962aSWarner Losh @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was 4637270962aSWarner Losh insufficient memory or text unsupported. 4647270962aSWarner Losh 4657270962aSWarner Losh **/ 4667270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 4677270962aSWarner Losh EFIAPI 4687270962aSWarner Losh UefiDevicePathLibConvertTextToDeviceNode ( 4697270962aSWarner Losh IN CONST CHAR16 *TextDeviceNode 4707270962aSWarner Losh ); 4717270962aSWarner Losh 4727270962aSWarner Losh /** 4737270962aSWarner Losh Convert text to the binary representation of a device path. 4747270962aSWarner Losh 4757270962aSWarner Losh 4767270962aSWarner Losh @param TextDevicePath TextDevicePath points to the text representation of a device 4777270962aSWarner Losh path. Conversion starts with the first character and continues 4787270962aSWarner Losh until the first non-device node character. 4797270962aSWarner Losh 4807270962aSWarner Losh @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or 4817270962aSWarner Losh there was insufficient memory. 4827270962aSWarner Losh 4837270962aSWarner Losh **/ 4847270962aSWarner Losh EFI_DEVICE_PATH_PROTOCOL * 4857270962aSWarner Losh EFIAPI 4867270962aSWarner Losh UefiDevicePathLibConvertTextToDevicePath ( 4877270962aSWarner Losh IN CONST CHAR16 *TextDevicePath 4887270962aSWarner Losh ); 4897270962aSWarner Losh #else 4907270962aSWarner Losh 4917270962aSWarner Losh /* 4927270962aSWarner Losh * Small FreeBSD shim layer. Fast and lose hacks to make this code work with FreeBSD. 4937270962aSWarner Losh */ 4947270962aSWarner Losh 4957270962aSWarner Losh #include <ctype.h> 4967270962aSWarner Losh 4977270962aSWarner Losh #define _PCD_GET_MODE_32_PcdMaximumDevicePathNodeCount 1000 4987270962aSWarner Losh #define MAX_UINTN UINTPTR_MAX 4997270962aSWarner Losh 5007270962aSWarner Losh #define AllocatePool(x) malloc(x) 5017270962aSWarner Losh #define AllocateZeroPool(x) calloc(1,x) 5027270962aSWarner Losh #define AsciiStrLen(s) strlen(s) 5037270962aSWarner Losh #define CopyGuid(dst, src) memcpy(dst, src, sizeof(uuid_t)) 5047270962aSWarner Losh #define CopyMem(d, s, l) memcpy(d, s, l) 5057270962aSWarner Losh #define FreePool(x) free(x) 5067270962aSWarner Losh #define LShiftU64(x, s) ((x) << s) 5077270962aSWarner Losh #define ReadUnaligned64(x) le64dec(x) 5087270962aSWarner Losh #define ReallocatePool(old, new, ptr) realloc(ptr, new) 5098af6a2c6SWarner Losh /* 5108af6a2c6SWarner Losh * Quirky StrCmp returns 0 if equal, 1 if not. This is what the code 5118af6a2c6SWarner Losh * expects, though that expectation is likely a bug (it casts the 5128af6a2c6SWarner Losh * return value. EDK2's StrCmp returns values just like C's strcmp, 5138af6a2c6SWarner Losh * but the parse code casts this to an UINTN, which is bogus. This 5148af6a2c6SWarner Losh * definition papers over that bogusness to do the right thing. If 5158af6a2c6SWarner Losh * iSCSI protocol string processing is ever fixed, we can remove this 5168af6a2c6SWarner Losh * bletcherous kludge. 5178af6a2c6SWarner Losh */ 5188af6a2c6SWarner Losh #define StrCmp(a, b) (strcmp(a, b) != 0) 5197270962aSWarner Losh #define StrCpyS(d, l, s) strcpy(d, s) 5207270962aSWarner Losh #define StrHexToUint64(x) strtoll(x, NULL, 16) 5217270962aSWarner Losh #define StrHexToUintn(x) strtoll(x, NULL, 16) 5227270962aSWarner Losh #define StrLen(x) strlen(x) 5237270962aSWarner Losh #define StrSize(x) (strlen(x) + 1) 5247270962aSWarner Losh #define StrnCatS(d, l, s, len) strncat(d, s, len) 5257270962aSWarner Losh #define StrnCmp(a, b, n) strncmp(a, b, n) 5267270962aSWarner Losh #define StrnLenS(str, max) strlen(str) 5277270962aSWarner Losh #define Strtoi(x) strtol(x, NULL, 0) 5287270962aSWarner Losh #define Strtoi64(x, y) *(long long *)y = strtoll(x, NULL, 0) 5297270962aSWarner Losh #define SwapBytes64(u64) bswap64(u64) 5307270962aSWarner Losh #define UnicodeStrToAsciiStrS(src, dest, len) strlcpy(dest, src, len) 5317270962aSWarner Losh #define ZeroMem(p,l) memset(p, 0, l) 5327270962aSWarner Losh 5337270962aSWarner Losh #undef ASSERT 5347270962aSWarner Losh #define ASSERT(x) 5357270962aSWarner Losh 5367270962aSWarner Losh /* 5377270962aSWarner Losh * Define AllocateCopyPool and others so that we "forget" about the 5387270962aSWarner Losh * previous non-static deifnition since we want these to be static 5397270962aSWarner Losh * inlines. 5407270962aSWarner Losh */ 5417270962aSWarner Losh #define AllocateCopyPool AllocateCopyPoolFreeBSD 5427270962aSWarner Losh #define CompareGuid CompareGuidFreeBSD 5437270962aSWarner Losh #define StrHexToBytes StrHexToBytesFreeBSD 5447270962aSWarner Losh #define StrToGuid StrToGuidFreeBSD 5457270962aSWarner Losh #define WriteUnaligned64 WriteUnaligned64FreeBSD 5467270962aSWarner Losh 5477270962aSWarner Losh static inline void * 5487270962aSWarner Losh AllocateCopyPool(size_t l, const void *p) 5497270962aSWarner Losh { 5507270962aSWarner Losh void *rv; 5517270962aSWarner Losh 5527270962aSWarner Losh rv = malloc(l); 5537270962aSWarner Losh if (rv == NULL) 5547270962aSWarner Losh return NULL; 5557270962aSWarner Losh memcpy(rv, p, l); 5567270962aSWarner Losh return (rv); 5577270962aSWarner Losh } 5587270962aSWarner Losh 5597270962aSWarner Losh static inline BOOLEAN 5607270962aSWarner Losh CompareGuid (const GUID *g1, const GUID *g2) 5617270962aSWarner Losh { 5627270962aSWarner Losh uint32_t ignored_status; 5637270962aSWarner Losh 5647270962aSWarner Losh return (uuid_compare((const uuid_t *)g1, (const uuid_t *)g2, 5657270962aSWarner Losh &ignored_status) == 0); 5667270962aSWarner Losh } 5677270962aSWarner Losh 5687270962aSWarner Losh static inline int 5697270962aSWarner Losh StrHexToBytes(const char *str, size_t len, uint8_t *buf, size_t buflen) 5707270962aSWarner Losh { 5717270962aSWarner Losh size_t i; 5727270962aSWarner Losh char hex[3]; 5737270962aSWarner Losh 5747270962aSWarner Losh /* 5757270962aSWarner Losh * Sanity check preconditions. 5767270962aSWarner Losh */ 57703307d7aSWarner Losh if (buflen != len / 2 || (len % 2) == 1) 5787270962aSWarner Losh return 1; 5797270962aSWarner Losh for (i = 0; i < len; i += 2) { 5807270962aSWarner Losh if (!isxdigit(str[i]) || !isxdigit(str[i + 1])) 5817270962aSWarner Losh return 1; 5827270962aSWarner Losh hex[0] = str[i]; 5837270962aSWarner Losh hex[1] = str[i + 1]; 5847270962aSWarner Losh hex[2] = '\0'; 5857270962aSWarner Losh buf[i / 2] = strtol(hex, NULL, 16); 5867270962aSWarner Losh } 5877270962aSWarner Losh return 0; 5887270962aSWarner Losh } 5897270962aSWarner Losh 5907270962aSWarner Losh static inline void 5917270962aSWarner Losh StrToGuid(const char *str, GUID *guid) 5927270962aSWarner Losh { 5937270962aSWarner Losh uint32_t status; 5947270962aSWarner Losh 5957270962aSWarner Losh uuid_from_string(str, (uuid_t *)guid, &status); 5967270962aSWarner Losh } 5977270962aSWarner Losh 5987270962aSWarner Losh static inline void 5997270962aSWarner Losh WriteUnaligned64(void *ptr, uint64_t val) 6007270962aSWarner Losh { 6017270962aSWarner Losh memcpy(ptr, &val, sizeof(val)); 6027270962aSWarner Losh } 6037270962aSWarner Losh 6047270962aSWarner Losh /* 6057270962aSWarner Losh * Hack to allow converting %g to %s in printfs. Hack because 6067270962aSWarner Losh * it's single entry, uses a static buffer, etc. Sufficient for 6077270962aSWarner Losh * the day for this file though. IF you ever have to convert 6087270962aSWarner Losh * two %g's in one format, punt. Did I mention this was super lame. 6097270962aSWarner Losh * Not to mention it's name.... Also, the error GUID is horrific. 6107270962aSWarner Losh */ 6117270962aSWarner Losh static inline const char * 6127270962aSWarner Losh guid_str(const GUID *g) 6137270962aSWarner Losh { 6147270962aSWarner Losh static char buf[36 + 1]; 6157270962aSWarner Losh char *str = NULL; 6167270962aSWarner Losh int32_t ignored_status; 6177270962aSWarner Losh 6187270962aSWarner Losh uuid_to_string((const uuid_t *)g, &str, &ignored_status); 6197270962aSWarner Losh if (str != NULL) 6207270962aSWarner Losh strlcpy(buf, str, sizeof(buf)); 6217270962aSWarner Losh else 6227270962aSWarner Losh strlcpy(buf, "groot-cannot-decode-guid-groot-smash", 6237270962aSWarner Losh sizeof(buf)); /* ^^^^^^^ 36 characters ^^^^^^^ */ 6247270962aSWarner Losh free(str); 6257270962aSWarner Losh return buf; 6267270962aSWarner Losh } 6277270962aSWarner Losh #define G(x) guid_str((const GUID *)(const void *)x) 6287270962aSWarner Losh #endif 6297270962aSWarner Losh 6307270962aSWarner Losh #undef GLOBAL_REMOVE_IF_UNREFERENCED 6317270962aSWarner Losh #define GLOBAL_REMOVE_IF_UNREFERENCED static 6327270962aSWarner Losh 6337270962aSWarner Losh #endif 634