From 55209a77c1d327465f4004fef6916a7de4138981 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 22 Jan 2011 13:02:35 +0100 Subject: gobi: Check for SIM status first before enabling SIM card --- plugins/gobi.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'plugins/gobi.c') diff --git a/plugins/gobi.c b/plugins/gobi.c index 750d93bd..2745cc0b 100644 --- a/plugins/gobi.c +++ b/plugins/gobi.c @@ -50,6 +50,8 @@ static const char *none_prefix[] = { NULL }; struct gobi_data { GAtChat *chat; + struct ofono_sim *sim; + gboolean have_sim; }; static void gobi_debug(const char *str, void *user_data) @@ -117,13 +119,57 @@ static GAtChat *open_device(struct ofono_modem *modem, return chat; } +static void simstat_notify(GAtResult *result, gpointer user_data) +{ + struct ofono_modem *modem = user_data; + struct gobi_data *data = ofono_modem_get_data(modem); + + GAtResultIter iter; + const char *state; + + if (data->sim == NULL) + return; + + g_at_result_iter_init(&iter, result); + + if (!g_at_result_iter_next(&iter, "$QCSIMSTAT:")) + return; + + if (!g_at_result_iter_skip_next(&iter)) + return; + + if (!g_at_result_iter_next_unquoted_string(&iter, &state)) + return; + + DBG("state %s", state); + + if (g_str_equal(state, "SIM INIT COMPLETED") == TRUE) { + if (data->have_sim == FALSE) { + ofono_sim_inserted_notify(data->sim, TRUE); + data->have_sim = TRUE; + } + } +} + static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) { struct ofono_modem *modem = user_data; + struct gobi_data *data = ofono_modem_get_data(modem); DBG(""); + data->have_sim = FALSE; + ofono_modem_set_powered(modem, ok); + + g_at_chat_register(data->chat, "$QCSIMSTAT:", simstat_notify, + FALSE, modem, NULL); + + g_at_chat_send(data->chat, "AT$QCSIMSTAT=1", none_prefix, + NULL, NULL, NULL); + + g_at_chat_send(data->chat, "AT$QCSIMSTAT?", none_prefix, + NULL, NULL, NULL); } static int gobi_enable(struct ofono_modem *modem) @@ -213,15 +259,11 @@ error: static void gobi_pre_sim(struct ofono_modem *modem) { struct gobi_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, 0, "atmodem", data->chat); - - if (sim) - ofono_sim_inserted_notify(sim, TRUE); + data->sim = ofono_sim_create(modem, 0, "atmodem", data->chat); } static void gobi_post_sim(struct ofono_modem *modem) -- cgit v1.2.3