[MM] [PATCH] modem-helpers: handle the case when operator name is "Unknown"



Some modems report "Unknown" as the operator name when failed to obtain
the actual value:

    --> 'AT+COPS=3,0;+COPS?<CR>'
    <-- '<CR><LF>+COPS: 0,0,"Unknown",0<CR><LF><CR><LF>OK<CR><LF>'

This patch prevents "Unknown" from being treated as a valid operator name.
---
 src/mm-modem-helpers.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index db0bfbd..9aa360d 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -1456,6 +1456,8 @@ mm_3gpp_parse_operator (const gchar *reply,
     }
 
     if (operator) {
+        gchar *casefolded_operator;
+
         /* Some modems (Option & HSO) return the operator name as a hexadecimal
          * string of the bytes of the operator name as encoded by the current
          * character set.
@@ -1468,8 +1470,18 @@ mm_3gpp_parse_operator (const gchar *reply,
          */
         if (!g_utf8_validate (operator, -1, NULL)) {
             g_free (operator);
+            return NULL;
+        }
+
+        /* Some modems (Novatel LTE) return the operator name as "Unknown" when
+         * it fails to obtain the operator name. Return NULL in such case.
+         */
+        casefolded_operator = g_utf8_casefold (operator, -1);
+        if (g_utf8_collate (casefolded_operator, "unknown") == 0) {
+            g_free (operator);
             operator = NULL;
         }
+        g_free (casefolded_operator);
     }
 
     return operator;
-- 
1.7.7.3



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]