]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries
authorJiaxin Wu <jiaxin.wu@intel.com>
Tue, 25 Jul 2017 03:08:16 +0000 (11:08 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Mon, 14 Aug 2017 05:18:23 +0000 (13:18 +0800)
V3:
* Fix the bug in DevPathFromTextDns()

V2:
* Add no IP instance case check.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
MdePkg/Library/UefiDevicePathLib/DevicePathToText.c

index f50c11cfa2e7d593903d5ffc73108b8b5690edee..0459f0ab253cd48ec1f1b8b6bf1cd6882699ee1c 100644 (file)
@@ -2724,6 +2724,98 @@ DevPathFromTextBluetoothLE (
   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;\r
 }\r
 \r
+/**\r
+  Converts a text device path node to DNS device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created DNS device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextDns (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *DeviceNodeStr;\r
+  CHAR16            *DeviceNodeStrPtr;\r
+  UINT32            DnsServerIpCount;\r
+  UINT16            DnsDeviceNodeLength;\r
+  DNS_DEVICE_PATH   *DnsDeviceNode;\r
+  UINT32            DnsServerIpIndex;\r
+  CHAR16            *DnsServerIp;\r
+\r
+\r
+  //\r
+  // Count the DNS server address number.\r
+  //\r
+  DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);\r
+  if (DeviceNodeStr == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  DeviceNodeStrPtr = DeviceNodeStr;\r
+  \r
+  DnsServerIpCount = 0;\r
+  while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != L'\0') {\r
+    GetNextParamStr (&DeviceNodeStrPtr);\r
+    DnsServerIpCount ++; \r
+  }\r
+\r
+  FreePool (DeviceNodeStr);\r
+  DeviceNodeStr = NULL;\r
+\r
+  //\r
+  // One or more instances of the DNS server address in EFI_IP_ADDRESS, \r
+  // otherwise, NULL will be returned.\r
+  //\r
+  if (DnsServerIpCount == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Create the DNS DeviceNode.\r
+  //\r
+  DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));\r
+  DnsDeviceNode       = (DNS_DEVICE_PATH *) CreateDeviceNode (\r
+                                              MESSAGING_DEVICE_PATH,\r
+                                              MSG_DNS_DP,\r
+                                              DnsDeviceNodeLength\r
+                                              );\r
+  if (DnsDeviceNode == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Confirm the DNS server address is IPv4 or IPv6 type.\r
+  //\r
+  DeviceNodeStrPtr = TextDeviceNode;\r
+  while (!IS_NULL (*DeviceNodeStrPtr)) {\r
+    if (*DeviceNodeStrPtr == L'.') {\r
+      DnsDeviceNode->IsIPv6 = 0x00;\r
+      break;\r
+    }\r
+\r
+    if (*DeviceNodeStrPtr == L':') {\r
+      DnsDeviceNode->IsIPv6 = 0x01;\r
+      break;\r
+    }\r
+\r
+    DeviceNodeStrPtr++;\r
+  }\r
+\r
+  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {\r
+    DnsServerIp = GetNextParamStr (&TextDeviceNode);\r
+    if (DnsDeviceNode->IsIPv6 == 0x00) {\r
+      StrToIpv4Address (DnsServerIp,  NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);\r
+    } else {\r
+      StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);\r
+    }\r
+  }\r
+  \r
+  return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode;\r
+}\r
+\r
 /**\r
   Converts a text device path node to URI device path structure.\r
 \r
@@ -3397,6 +3489,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"Unit",                    DevPathFromTextUnit                    },\r
   {L"iSCSI",                   DevPathFromTextiSCSI                   },\r
   {L"Vlan",                    DevPathFromTextVlan                    },\r
+  {L"Dns",                     DevPathFromTextDns                     },\r
   {L"Uri",                     DevPathFromTextUri                     },\r
   {L"Bluetooth",               DevPathFromTextBluetooth               },\r
   {L"Wi-Fi",                   DevPathFromTextWiFi                    },\r
index b8d9491885177a1c929bd433704476696517121e..63542dba960eac8c518d183483beb1cf7338b356 100644 (file)
@@ -1696,6 +1696,51 @@ DevPathToTextBluetoothLE (
     );\r
 }\r
 \r
+/**\r
+  Converts a DNS device path structure to its string representative.\r
+\r
+  @param Str             The string representative of input device.\r
+  @param DevPath         The input device path structure.\r
+  @param DisplayOnly     If DisplayOnly is TRUE, then the shorter text representation\r
+                         of the display node is used, where applicable. If DisplayOnly\r
+                         is FALSE, then the longer text representation of the display node\r
+                         is used.\r
+  @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of text\r
+                         representation for a device node can be used, where applicable.\r
+\r
+**/\r
+VOID\r
+DevPathToTextDns (\r
+  IN OUT POOL_PRINT  *Str,\r
+  IN VOID            *DevPath,\r
+  IN BOOLEAN         DisplayOnly,\r
+  IN BOOLEAN         AllowShortcuts\r
+  )\r
+{\r
+  DNS_DEVICE_PATH  *DnsDevPath;\r
+  UINT32           DnsServerIpCount;\r
+  UINT32           DnsServerIpIndex;\r
+\r
+  DnsDevPath     = DevPath;\r
+  DnsServerIpCount = (UINT32) (DevicePathNodeLength(DnsDevPath) - sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof (DnsDevPath->IsIPv6)) / sizeof (EFI_IP_ADDRESS);\r
+\r
+  UefiDevicePathLibCatPrint (Str, L"Dns(");\r
+  \r
+  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {\r
+    if (DnsDevPath->IsIPv6 == 0x00) {\r
+      CatIPv4Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v4));\r
+    } else {\r
+      CatIPv6Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v6));\r
+    }\r
+\r
+    if (DnsServerIpIndex < DnsServerIpCount - 1) {\r
+      UefiDevicePathLibCatPrint (Str, L",");\r
+    }\r
+  }\r
+\r
+  UefiDevicePathLibCatPrint (Str, L")");\r
+}\r
+\r
 /**\r
   Converts a URI device path structure to its string representative.\r
 \r
@@ -2225,6 +2270,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLib
   {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,                    DevPathToTextVendor         },\r
   {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP,                     DevPathToTextiSCSI          },\r
   {MESSAGING_DEVICE_PATH, MSG_VLAN_DP,                      DevPathToTextVlan           },\r
+  {MESSAGING_DEVICE_PATH, MSG_DNS_DP,                       DevPathToTextDns            },\r
   {MESSAGING_DEVICE_PATH, MSG_URI_DP,                       DevPathToTextUri            },\r
   {MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP,                 DevPathToTextBluetooth      },\r
   {MESSAGING_DEVICE_PATH, MSG_WIFI_DP,                      DevPathToTextWiFi           },\r