[PATCH] huawei: handle optional 0x prefix on hex numbers in ^DHCP response

Ben Chan benchan at chromium.org
Fri Jan 26 22:25:56 UTC 2018


On Huawei ME936, the hex numbers in the response to AT^DHCP contain the 0x prefix, e.g.

  AT^DHCP?

  ^DHCP: 0xda7d0e0a,0xff000000,0xdb7d0e0a,0xdb7d0e0a,0x01261aac,0x00000000,100000000,50000000

This patch updates mm_huawei_parse_dhcp_response() to handle the
optional 0x prefix.
---
 plugins/huawei/mm-modem-helpers-huawei.c         | 2 +-
 plugins/huawei/tests/test-modem-helpers-huawei.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c
index fde1c791..e92552ed 100644
--- a/plugins/huawei/mm-modem-helpers-huawei.c
+++ b/plugins/huawei/mm-modem-helpers-huawei.c
@@ -230,7 +230,7 @@ mm_huawei_parse_dhcp_response (const char *reply,
      * actually 10.10.1.1.
      */
 
-    r = g_regex_new ("\\^DHCP:\\s*([0-9a-fA-F]+),([0-9a-fA-F]+),([0-9a-fA-F]+),([0-9a-fA-F]+),([0-9a-fA-F]+),([0-9a-fA-F]+),.*$", 0, 0, NULL);
+    r = g_regex_new ("\\^DHCP:\\s*(?:0[xX])?([0-9a-fA-F]+),(?:0[xX])?([0-9a-fA-F]+),(?:0[xX])?([0-9a-fA-F]+),(?:0[xX])?([0-9a-fA-F]+),(?:0[xX])?([0-9a-fA-F]+),(?:0[xX])?([0-9a-fA-F]+),.*$", 0, 0, NULL);
     g_assert (r != NULL);
 
     matched = g_regex_match_full (r, reply, -1, 0, 0, &match_info, &match_error);
diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c
index 46c90f44..70c40db2 100644
--- a/plugins/huawei/tests/test-modem-helpers-huawei.c
+++ b/plugins/huawei/tests/test-modem-helpers-huawei.c
@@ -154,10 +154,16 @@ typedef struct {
 static const DhcpTest dhcp_tests[] = {
     { "^DHCP:a3ec5c64,f8ffffff,a1ec5c64,a1ec5c64,2200b10a,74bba80a,236800,236800\r\n",
       "100.92.236.163", 29, "100.92.236.161", "10.177.0.34", "10.168.187.116" },
+    { "^DHCP:0xa3ec5c64,0xf8ffffff,0xa1ec5c64,0xa1ec5c64,0x2200b10a,0x74bba80a,236800,236800\r\n",
+      "100.92.236.163", 29, "100.92.236.161", "10.177.0.34", "10.168.187.116" },
     { "^DHCP: 1010A0A,FCFFFFFF,2010A0A,2010A0A,0,0,150000000,150000000\r\n",
       "10.10.1.1", 30, "10.10.1.2", "0.0.0.0", "0.0.0.0" },
     { "^DHCP: CCDB080A,F8FFFFFF,C9DB080A,C9DB080A,E67B59C0,E77B59C0,85600,85600\r\n",
       "10.8.219.204", 29, "10.8.219.201", "192.89.123.230", "192.89.123.231" },
+    { "^DHCP: 0xCCDB080A,0xF8FFFFFF,0xC9DB080A,0xC9DB080A,0xE67B59C0,0xE77B59C0,85600,85600\r\n",
+      "10.8.219.204", 29, "10.8.219.201", "192.89.123.230", "192.89.123.231" },
+    { "^DHCP: 0XCCDB080A,0XF8FFFFFF,0XC9DB080A,0XC9DB080A,0XE67B59C0,0XE77B59C0,85600,85600\r\n",
+      "10.8.219.204", 29, "10.8.219.201", "192.89.123.230", "192.89.123.231" },
     { NULL }
 };
 
-- 
2.16.0.rc1.238.g530d649a79-goog



More information about the ModemManager-devel mailing list