]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / DevicePathFromText.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