netreg: Add telit version for ciev notification
authorChristopher Vogl <christopher.vogl@hale.at>
Thu, 6 Sep 2012 09:49:17 +0000 (11:49 +0200)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 12 Sep 2012 04:16:32 +0000 (23:16 -0500)
drivers/atmodem/network-registration.c

index 7160679..509a47a 100644 (file)
@@ -759,6 +759,37 @@ static void ciev_notify(GAtResult *result, gpointer user_data)
        ofono_netreg_strength_notify(netreg, strength);
 }
 
+static void telit_ciev_notify(GAtResult *result, gpointer user_data)
+{
+       struct ofono_netreg *netreg = user_data;
+       struct netreg_data *nd = ofono_netreg_get_data(netreg);
+       const char *signal_identifier = "rssi";
+       const char *ind_str;
+       int strength;
+       GAtResultIter iter;
+
+       g_at_result_iter_init(&iter, result);
+
+       if (!g_at_result_iter_next(&iter, "+CIEV:"))
+               return;
+
+       if (!g_at_result_iter_next_unquoted_string(&iter, &ind_str))
+               return;
+
+       if (!g_str_equal(signal_identifier, ind_str))
+               return;
+
+       if (!g_at_result_iter_next_number(&iter, &strength))
+               return;
+
+       if (strength == nd->signal_invalid)
+               strength = -1;
+       else
+               strength = (strength * 100) / (nd->signal_max - nd->signal_min);
+
+       ofono_netreg_strength_notify(netreg, strength);
+}
+
 static void ctzv_notify(GAtResult *result, gpointer user_data)
 {
        struct ofono_netreg *netreg = user_data;
@@ -1618,6 +1649,19 @@ static void cind_support_cb(gboolean ok, GAtResult *result, gpointer user_data)
                                at_cmer_query_cb, netreg, NULL);
        g_at_chat_register(nd->chat, "+CIEV:",
                                ciev_notify, FALSE, netreg, NULL);
+
+       /*
+        * Telit uses strings instead of numbers to identify indicators
+        * in a +CIEV URC.
+        * Handle them in a separate function to keep the code clean.
+        */
+       if (nd->vendor == OFONO_VENDOR_TELIT)
+               g_at_chat_register(nd->chat, "+CIEV:",
+                               telit_ciev_notify, FALSE, netreg, NULL);
+       else
+               g_at_chat_register(nd->chat, "+CIEV:",
+                               ciev_notify, FALSE, netreg, NULL);
+
        g_at_chat_register(nd->chat, "+CREG:",
                                creg_notify, FALSE, netreg, NULL);