]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
IntelFrameworkPkg FrameworkUefiLib: Use safe string functions
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / DevicePathFromText.c
index f688c1af7494ef3c5f61d6ae8526698269452795..d58f06905a21378c7ecbaf6eea6a1b4206f4d66c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathFromText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1840,6 +1840,34 @@ DevPathFromTextUfs (
   return (EFI_DEVICE_PATH_PROTOCOL *) Ufs;\r
 }\r
 \r
+/**\r
+  Converts a text device path node to SD (Secure Digital) device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created SD device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextSd (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *SlotNumberStr;\r
+  SD_DEVICE_PATH    *Sd;\r
+\r
+  SlotNumberStr = GetNextParamStr (&TextDeviceNode);\r
+  Sd            = (SD_DEVICE_PATH *) CreateDeviceNode (\r
+                                       MESSAGING_DEVICE_PATH,\r
+                                       MSG_SD_DP,\r
+                                       (UINT16) sizeof (SD_DEVICE_PATH)\r
+                                       );\r
+\r
+  Sd->SlotNumber = (UINT8) Strtoi (SlotNumberStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Sd;\r
+}\r
+\r
 /**\r
   Converts a text device path node to Debug Port device path structure.\r
 \r
@@ -2696,6 +2724,113 @@ DevPathFromTextVlan (
   return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;\r
 }\r
 \r
+/**\r
+  Converts a text device path node to Bluetooth device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Bluetooth device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextBluetooth (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                  *BluetoothStr;\r
+  CHAR16                  *Walker;\r
+  CHAR16                  *TempNumBuffer;\r
+  UINTN                   TempBufferSize;\r
+  INT32                   Index;\r
+  BLUETOOTH_DEVICE_PATH   *BluetoothDp;\r
+\r
+  BluetoothStr = GetNextParamStr (&TextDeviceNode);\r
+  BluetoothDp = (BLUETOOTH_DEVICE_PATH *) CreateDeviceNode (\r
+                                   MESSAGING_DEVICE_PATH,\r
+                                   MSG_BLUETOOTH_DP,\r
+                                   (UINT16) sizeof (BLUETOOTH_DEVICE_PATH)\r
+                                   );\r
+\r
+  Index = sizeof (BLUETOOTH_ADDRESS) - 1;\r
+  while (!IS_NULL(BluetoothStr) && Index >= 0) {\r
+    Walker = SplitStr (&BluetoothStr, L':');\r
+    TempBufferSize = StrSize (Walker) + StrLen (L"0x") * sizeof (CHAR16);\r
+    TempNumBuffer = AllocateZeroPool (TempBufferSize);\r
+    if (TempNumBuffer == NULL) {\r
+      break;\r
+    }\r
+    StrnCpy (TempNumBuffer, L"0x", TempBufferSize / sizeof (CHAR16));\r
+    StrnCat (TempNumBuffer + StrLen (L"0x"), Walker, TempBufferSize / sizeof (CHAR16) - StrLen (L"0x") );\r
+    BluetoothDp->BD_ADDR.Address[Index] = (UINT8)Strtoi (TempNumBuffer);\r
+    FreePool (TempNumBuffer);\r
+    Index--;\r
+  }\r
+  \r
+  return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothDp;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to Wi-Fi device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created Wi-Fi device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextWiFi (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16                *SSIdStr;\r
+  CHAR8                 *AsciiStr;\r
+  WIFI_DEVICE_PATH      *WiFiDp;\r
+\r
+  SSIdStr = GetNextParamStr (&TextDeviceNode);\r
+  WiFiDp  = (WIFI_DEVICE_PATH *) CreateDeviceNode (\r
+                                   MESSAGING_DEVICE_PATH,\r
+                                   MSG_WIFI_DP,\r
+                                   (UINT16) sizeof (WIFI_DEVICE_PATH)\r
+                                   );\r
+\r
+  AsciiStr = (CHAR8 *) WiFiDp->SSId;\r
+  StrToAscii (SSIdStr, &AsciiStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;\r
+}\r
+\r
+/**\r
+  Converts a text device path node to URI device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created URI device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextUri (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16           *UriStr;\r
+  UINTN            UriLength;\r
+  URI_DEVICE_PATH  *Uri;\r
+\r
+  UriStr = GetNextParamStr (&TextDeviceNode);\r
+  UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));\r
+  Uri    = (URI_DEVICE_PATH *) CreateDeviceNode (\r
+                                 MESSAGING_DEVICE_PATH,\r
+                                 MSG_URI_DP,\r
+                                 (UINT16) (sizeof (URI_DEVICE_PATH) + UriLength)\r
+                                 );\r
+\r
+  while (UriLength-- != 0) {\r
+    Uri->Uri[UriLength] = (CHAR8) UriStr[UriLength];\r
+  }\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Uri;\r
+}\r
+\r
 /**\r
   Converts a media text device path node to media device path structure.\r
 \r
@@ -3111,6 +3246,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"SasEx",                   DevPathFromTextSasEx                   },\r
   {L"NVMe",                    DevPathFromTextNVMe                    },\r
   {L"UFS",                     DevPathFromTextUfs                     },\r
+  {L"SD",                      DevPathFromTextSd                      },\r
   {L"DebugPort",               DevPathFromTextDebugPort               },\r
   {L"MAC",                     DevPathFromTextMAC                     },\r
   {L"IPv4",                    DevPathFromTextIPv4                    },\r
@@ -3136,7 +3272,9 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"Unit",                    DevPathFromTextUnit                    },\r
   {L"iSCSI",                   DevPathFromTextiSCSI                   },\r
   {L"Vlan",                    DevPathFromTextVlan                    },\r
-\r
+  {L"Uri",                     DevPathFromTextUri                     },\r
+  {L"Bluetooth",               DevPathFromTextBluetooth               },\r
+  {L"WiFi",                    DevPathFromTextWiFi                    },\r
   {L"MediaPath",               DevPathFromTextMediaPath               },\r
   {L"HD",                      DevPathFromTextHD                      },\r
   {L"CDROM",                   DevPathFromTextCDROM                   },\r