---
Hi, 

This patch enables ste modem to handle hotswap situation. 

Br, 
Jussi

 plugins/ste.c |  109 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 80 insertions(+), 29 deletions(-)

diff --git a/plugins/ste.c b/plugins/ste.c
index 85d2d51..e183073 100644
--- a/plugins/ste.c
+++ b/plugins/ste.c
@@ -66,15 +66,23 @@
 
 #define NUM_CHAT       1
 
-static const char *cpin_prefix[] = { "+CPIN:", NULL };
-
 static char *chat_prefixes[NUM_CHAT] = { "Default: " };
 
 struct ste_data {
        GAtChat *chat;
-       guint cpin_poll_source;
-       guint cpin_poll_count;
        gboolean have_sim;
+       struct ofono_sim *sim;
+};
+
+enum ste_sim_state {
+       SIM_STATE_NULL = 0,
+       SIM_STATE_AWAITING_APP,
+       SIM_STATE_BLOCKED,
+       SIM_STATE_BLOCKED_FOREVER,
+       SIM_STATE_WAIT_FOR_PIN,
+       SIM_STATE_ACTIVE,
+       SIM_STATE_TERMINATING,
+       SIM_STATE_POWER_OFF
 };
 
 static int ste_probe(struct ofono_modem *modem)
@@ -102,9 +110,6 @@ static void ste_remove(struct ofono_modem *modem)
 
        g_at_chat_unref(data->chat);
 
-       if (data->cpin_poll_source > 0)
-               g_source_remove(data->cpin_poll_source);
-
        g_free(data);
 }
 
@@ -115,28 +120,58 @@ static void ste_debug(const char *str, void *user_data)
        ofono_info("%s%s", prefix, str);
 }
 
-static gboolean init_simpin_check(gpointer user_data);
+static void handle_sim_status(int status, struct ofono_modem *modem)
+{
+       struct ste_data *data = ofono_modem_get_data(modem);
+       DBG("SIM status:%d\n", status);
+
+       switch (status) {
+       case SIM_STATE_WAIT_FOR_PIN:
+       case SIM_STATE_ACTIVE:
+
+               if (data->sim)
+                       ofono_sim_inserted_notify(data->sim, TRUE);
+
+               data->have_sim = TRUE;
+               break;
+       case SIM_STATE_POWER_OFF:
+               if (data->sim)
+                       ofono_sim_inserted_notify(data->sim, FALSE);
+               break;
+       case SIM_STATE_NULL:
+       case SIM_STATE_AWAITING_APP:
+       case SIM_STATE_BLOCKED:
+       case SIM_STATE_BLOCKED_FOREVER:
+       case SIM_STATE_TERMINATING:
+               break;
+       }
+}
 
 static void simpin_check(gboolean ok, GAtResult *result, gpointer user_data)
 {
        struct ofono_modem *modem = user_data;
-       struct ste_data *data = ofono_modem_get_data(modem);
+       int simnr, status;
+       GAtResultIter iter;
 
-       /* Modem returns +CME ERROR: 10 if SIM is not ready. */
-       if (!ok && result->final_or_pdu &&
-                       !strcmp(result->final_or_pdu, "+CME ERROR: 10") &&
-                       data->cpin_poll_count++ < 5) {
-               data->cpin_poll_source =
-                       g_timeout_add_seconds(1, init_simpin_check, modem);
-               return;
-       }
+       DBG("ok:%d", ok);
 
-       data->cpin_poll_count = 0;
+       if (!ok)
+               return;
 
-       /* Modem returns ERROR if there is no SIM in slot. */
-       data->have_sim = ok;
+       g_at_result_iter_init(&iter, result);
 
        ofono_modem_set_powered(modem, TRUE);
+
+       if (!g_at_result_iter_next(&iter, "*ESIMSR:"))
+               return;
+
+       if (!g_at_result_iter_next_number(&iter, &simnr))
+               return;
+
+       if (!g_at_result_iter_next_number(&iter, &status))
+               return;
+
+       handle_sim_status(status, modem);
 }
 
 static gboolean init_simpin_check(gpointer user_data)
@@ -144,10 +179,9 @@ static gboolean init_simpin_check(gpointer user_data)
        struct ofono_modem *modem = user_data;
        struct ste_data *data = ofono_modem_get_data(modem);
 
-       data->cpin_poll_source = 0;
-
-       g_at_chat_send(data->chat, "AT+CPIN?", cpin_prefix,
-                       simpin_check, modem, NULL);
+       g_at_chat_send(data->chat, "AT*ESIMSR=1;*ESIMSR?", NULL,
+                       simpin_check,
+                       modem, NULL);
 
        return FALSE;
 }
@@ -234,6 +268,23 @@ static GIOChannel *ste_create_channel(struct ofono_modem 
*modem)
        return channel;
 }
 
+static void esimsr_notify(GAtResult *result, gpointer user_data)
+{
+       struct ofono_modem *modem = user_data;
+       int status;
+       GAtResultIter iter;
+       DBG("");
+
+       g_at_result_iter_init(&iter, result);
+       if (!g_at_result_iter_next(&iter, "*ESIMSR:"))
+               return;
+
+       if (!g_at_result_iter_next_number(&iter, &status))
+               return;
+
+       handle_sim_status(status, modem);
+}
+
 static int ste_enable(struct ofono_modem *modem)
 {
        struct ste_data *data = ofono_modem_get_data(modem);
@@ -265,6 +316,9 @@ static int ste_enable(struct ofono_modem *modem)
 
        g_at_chat_send(data->chat, "AT+CFUN=4", NULL, cfun_enable, modem, NULL);
 
+       g_at_chat_register(data->chat, "*ESIMSR:", esimsr_notify,
+                       FALSE, modem, NULL);
+
        return -EINPROGRESS;
 }
 
@@ -335,16 +389,13 @@ error:
 static void ste_pre_sim(struct ofono_modem *modem)
 {
        struct ste_data *data = ofono_modem_get_data(modem);
-       struct ofono_sim *sim;
 
        DBG("%p", modem);
 
        ofono_devinfo_create(modem, 0, "atmodem", data->chat);
-       sim = ofono_sim_create(modem, OFONO_VENDOR_MBM, "atmodem", data->chat);
+       data->sim = ofono_sim_create(modem, OFONO_VENDOR_MBM, "atmodem",
+                       data->chat);
        ofono_voicecall_create(modem, 0, "stemodem", data->chat);
-
-       if (sim)
-               ofono_sim_inserted_notify(sim, TRUE);
 }
 
 static void ste_post_sim(struct ofono_modem *modem)
-- 
1.7.1

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to