public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] BaseTools: Add Dns and BluetoothLE DevicePath
@ 2018-08-06  7:37 Feng, YunhuaX
  2018-08-08  3:37 ` Zhu, Yonghong
  0 siblings, 1 reply; 2+ messages in thread
From: Feng, YunhuaX @ 2018-08-06  7:37 UTC (permalink / raw)
  To: edk2-devel@lists.01.org; +Cc: Zhu, Yonghong, Gao, Liming

Add Dns and BluetoothLE for support DevicePath

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/C/DevicePath/DevicePathFromText.c | 127 +++++++++++++++++++++
 1 file changed, 127 insertions(+)

diff --git a/BaseTools/Source/C/DevicePath/DevicePathFromText.c b/BaseTools/Source/C/DevicePath/DevicePathFromText.c
index bfd91d23b5..bb74e2e170 100644
--- a/BaseTools/Source/C/DevicePath/DevicePathFromText.c
+++ b/BaseTools/Source/C/DevicePath/DevicePathFromText.c
@@ -2537,10 +2537,135 @@ DevPathFromTextWiFi (
 
   return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;
 }
 
 /**
+  Converts a text device path node to Bluetooth LE device path structure.
+
+  @param TextDeviceNode  The input Text device path node.
+
+  @return A pointer to the newly-created Bluetooth LE device path structure.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+DevPathFromTextBluetoothLE (
+  IN CHAR16 *TextDeviceNode
+  )
+{
+  CHAR16                     *BluetoothLeAddrStr;
+  CHAR16                     *BluetoothLeAddrTypeStr;
+  BLUETOOTH_LE_DEVICE_PATH   *BluetoothLeDp;
+
+  BluetoothLeAddrStr     = GetNextParamStr (&TextDeviceNode);
+  BluetoothLeAddrTypeStr = GetNextParamStr (&TextDeviceNode);
+  BluetoothLeDp = (BLUETOOTH_LE_DEVICE_PATH *) CreateDeviceNode (
+                                                 MESSAGING_DEVICE_PATH,
+                                                 MSG_BLUETOOTH_LE_DP,
+                                                 (UINT16) sizeof (BLUETOOTH_LE_DEVICE_PATH)
+                                                 );
+
+  BluetoothLeDp->Address.Type = (UINT8) Strtoi (BluetoothLeAddrTypeStr);
+  StrHexToBytes (
+    BluetoothLeAddrStr, sizeof (BluetoothLeDp->Address.Address) * 2,
+    BluetoothLeDp->Address.Address, sizeof (BluetoothLeDp->Address.Address)
+    );
+  return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;
+}
+
+/**
+  Converts a text device path node to DNS device path structure.
+
+  @param TextDeviceNode  The input Text device path node.
+
+  @return A pointer to the newly-created DNS device path structure.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+DevPathFromTextDns (
+  IN CHAR16 *TextDeviceNode
+  )
+{
+  CHAR16            *DeviceNodeStr;
+  CHAR16            *DeviceNodeStrPtr;
+  UINT32            DnsServerIpCount;
+  UINT16            DnsDeviceNodeLength;
+  DNS_DEVICE_PATH   *DnsDeviceNode;
+  UINT32            DnsServerIpIndex;
+  CHAR16            *DnsServerIp;
+
+
+  //
+  // Count the DNS server address number.
+  //
+  DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
+  if (DeviceNodeStr == NULL) {
+    return NULL;
+  }
+
+  DeviceNodeStrPtr = DeviceNodeStr;
+
+  DnsServerIpCount = 0;
+  while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != L'\0') {
+    GetNextParamStr (&DeviceNodeStrPtr);
+    DnsServerIpCount ++;
+  }
+
+  free (DeviceNodeStr);
+  DeviceNodeStr = NULL;
+
+  //
+  // One or more instances of the DNS server address in EFI_IP_ADDRESS,
+  // otherwise, NULL will be returned.
+  //
+  if (DnsServerIpCount == 0) {
+    return NULL;
+  }
+
+  //
+  // Create the DNS DeviceNode.
+  //
+  DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
+  DnsDeviceNode       = (DNS_DEVICE_PATH *) CreateDeviceNode (
+                                              MESSAGING_DEVICE_PATH,
+                                              MSG_DNS_DP,
+                                              DnsDeviceNodeLength
+                                              );
+  if (DnsDeviceNode == NULL) {
+    return NULL;
+  }
+
+  //
+  // Confirm the DNS server address is IPv4 or IPv6 type.
+  //
+  DeviceNodeStrPtr = TextDeviceNode;
+  while (!IS_NULL (*DeviceNodeStrPtr)) {
+    if (*DeviceNodeStrPtr == L'.') {
+      DnsDeviceNode->IsIPv6 = 0x00;
+      break;
+    }
+
+    if (*DeviceNodeStrPtr == L':') {
+      DnsDeviceNode->IsIPv6 = 0x01;
+      break;
+    }
+
+    DeviceNodeStrPtr++;
+  }
+
+  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {
+    DnsServerIp = GetNextParamStr (&TextDeviceNode);
+    if (DnsDeviceNode->IsIPv6 == 0x00) {
+      StrToIpv4Address (DnsServerIp,  NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
+    } else {
+      StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
+    }
+  }
+
+  return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode;
+}
+
+/**
   Converts a text device path node to URI device path structure.
 
   @param TextDeviceNode  The input Text device path node.
 
   @return A pointer to the newly-created URI device path structure.
@@ -3209,13 +3334,15 @@ DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
   {L"UsbTestAndMeasurement",   DevPathFromTextUsbTestAndMeasurement   },
   {L"UsbWwid",                 DevPathFromTextUsbWwid                 },
   {L"Unit",                    DevPathFromTextUnit                    },
   {L"iSCSI",                   DevPathFromTextiSCSI                   },
   {L"Vlan",                    DevPathFromTextVlan                    },
+  {L"Dns",                     DevPathFromTextDns                     },
   {L"Uri",                     DevPathFromTextUri                     },
   {L"Bluetooth",               DevPathFromTextBluetooth               },
   {L"Wi-Fi",                   DevPathFromTextWiFi                    },
+  {L"BluetoothLE",             DevPathFromTextBluetoothLE             },
   {L"MediaPath",               DevPathFromTextMediaPath               },
   {L"HD",                      DevPathFromTextHD                      },
   {L"CDROM",                   DevPathFromTextCDROM                   },
   {L"VenMedia",                DevPathFromTextVenMedia                },
   {L"Media",                   DevPathFromTextMedia                   },
-- 
2.12.2.windows.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] BaseTools: Add Dns and BluetoothLE DevicePath
  2018-08-06  7:37 [PATCH] BaseTools: Add Dns and BluetoothLE DevicePath Feng, YunhuaX
@ 2018-08-08  3:37 ` Zhu, Yonghong
  0 siblings, 0 replies; 2+ messages in thread
From: Zhu, Yonghong @ 2018-08-08  3:37 UTC (permalink / raw)
  To: Feng, YunhuaX, edk2-devel@lists.01.org; +Cc: Gao, Liming, Zhu, Yonghong

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Feng, YunhuaX 
Sent: Monday, August 06, 2018 3:37 PM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [PATCH] BaseTools: Add Dns and BluetoothLE DevicePath

Add Dns and BluetoothLE for support DevicePath

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/C/DevicePath/DevicePathFromText.c | 127 +++++++++++++++++++++
 1 file changed, 127 insertions(+)

diff --git a/BaseTools/Source/C/DevicePath/DevicePathFromText.c b/BaseTools/Source/C/DevicePath/DevicePathFromText.c
index bfd91d23b5..bb74e2e170 100644
--- a/BaseTools/Source/C/DevicePath/DevicePathFromText.c
+++ b/BaseTools/Source/C/DevicePath/DevicePathFromText.c
@@ -2537,10 +2537,135 @@ DevPathFromTextWiFi (
 
   return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;  }
 
 /**
+  Converts a text device path node to Bluetooth LE device path structure.
+
+  @param TextDeviceNode  The input Text device path node.
+
+  @return A pointer to the newly-created Bluetooth LE device path structure.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+DevPathFromTextBluetoothLE (
+  IN CHAR16 *TextDeviceNode
+  )
+{
+  CHAR16                     *BluetoothLeAddrStr;
+  CHAR16                     *BluetoothLeAddrTypeStr;
+  BLUETOOTH_LE_DEVICE_PATH   *BluetoothLeDp;
+
+  BluetoothLeAddrStr     = GetNextParamStr (&TextDeviceNode);
+  BluetoothLeAddrTypeStr = GetNextParamStr (&TextDeviceNode);  
+ BluetoothLeDp = (BLUETOOTH_LE_DEVICE_PATH *) CreateDeviceNode (
+                                                 MESSAGING_DEVICE_PATH,
+                                                 MSG_BLUETOOTH_LE_DP,
+                                                 (UINT16) sizeof (BLUETOOTH_LE_DEVICE_PATH)
+                                                 );
+
+  BluetoothLeDp->Address.Type = (UINT8) Strtoi 
+(BluetoothLeAddrTypeStr);
+  StrHexToBytes (
+    BluetoothLeAddrStr, sizeof (BluetoothLeDp->Address.Address) * 2,
+    BluetoothLeDp->Address.Address, sizeof (BluetoothLeDp->Address.Address)
+    );
+  return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp; }
+
+/**
+  Converts a text device path node to DNS device path structure.
+
+  @param TextDeviceNode  The input Text device path node.
+
+  @return A pointer to the newly-created DNS device path structure.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+DevPathFromTextDns (
+  IN CHAR16 *TextDeviceNode
+  )
+{
+  CHAR16            *DeviceNodeStr;
+  CHAR16            *DeviceNodeStrPtr;
+  UINT32            DnsServerIpCount;
+  UINT16            DnsDeviceNodeLength;
+  DNS_DEVICE_PATH   *DnsDeviceNode;
+  UINT32            DnsServerIpIndex;
+  CHAR16            *DnsServerIp;
+
+
+  //
+  // Count the DNS server address number.
+  //
+  DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);  if 
+ (DeviceNodeStr == NULL) {
+    return NULL;
+  }
+
+  DeviceNodeStrPtr = DeviceNodeStr;
+
+  DnsServerIpCount = 0;
+  while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != L'\0') {
+    GetNextParamStr (&DeviceNodeStrPtr);
+    DnsServerIpCount ++;
+  }
+
+  free (DeviceNodeStr);
+  DeviceNodeStr = NULL;
+
+  //
+  // One or more instances of the DNS server address in EFI_IP_ADDRESS,  
+ // otherwise, NULL will be returned.
+  //
+  if (DnsServerIpCount == 0) {
+    return NULL;
+  }
+
+  //
+  // Create the DNS DeviceNode.
+  //
+  DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
+  DnsDeviceNode       = (DNS_DEVICE_PATH *) CreateDeviceNode (
+                                              MESSAGING_DEVICE_PATH,
+                                              MSG_DNS_DP,
+                                              DnsDeviceNodeLength
+                                              );  if (DnsDeviceNode == 
+ NULL) {
+    return NULL;
+  }
+
+  //
+  // Confirm the DNS server address is IPv4 or IPv6 type.
+  //
+  DeviceNodeStrPtr = TextDeviceNode;
+  while (!IS_NULL (*DeviceNodeStrPtr)) {
+    if (*DeviceNodeStrPtr == L'.') {
+      DnsDeviceNode->IsIPv6 = 0x00;
+      break;
+    }
+
+    if (*DeviceNodeStrPtr == L':') {
+      DnsDeviceNode->IsIPv6 = 0x01;
+      break;
+    }
+
+    DeviceNodeStrPtr++;
+  }
+
+  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {
+    DnsServerIp = GetNextParamStr (&TextDeviceNode);
+    if (DnsDeviceNode->IsIPv6 == 0x00) {
+      StrToIpv4Address (DnsServerIp,  NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
+    } else {
+      StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
+    }
+  }
+
+  return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode; }
+
+/**
   Converts a text device path node to URI device path structure.
 
   @param TextDeviceNode  The input Text device path node.
 
   @return A pointer to the newly-created URI device path structure.
@@ -3209,13 +3334,15 @@ DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
   {L"UsbTestAndMeasurement",   DevPathFromTextUsbTestAndMeasurement   },
   {L"UsbWwid",                 DevPathFromTextUsbWwid                 },
   {L"Unit",                    DevPathFromTextUnit                    },
   {L"iSCSI",                   DevPathFromTextiSCSI                   },
   {L"Vlan",                    DevPathFromTextVlan                    },
+  {L"Dns",                     DevPathFromTextDns                     },
   {L"Uri",                     DevPathFromTextUri                     },
   {L"Bluetooth",               DevPathFromTextBluetooth               },
   {L"Wi-Fi",                   DevPathFromTextWiFi                    },
+  {L"BluetoothLE",             DevPathFromTextBluetoothLE             },
   {L"MediaPath",               DevPathFromTextMediaPath               },
   {L"HD",                      DevPathFromTextHD                      },
   {L"CDROM",                   DevPathFromTextCDROM                   },
   {L"VenMedia",                DevPathFromTextVenMedia                },
   {L"Media",                   DevPathFromTextMedia                   },
--
2.12.2.windows.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-08  3:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-06  7:37 [PATCH] BaseTools: Add Dns and BluetoothLE DevicePath Feng, YunhuaX
2018-08-08  3:37 ` Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox