From 6d83fbdf00e7c29529baeaf65768eee8327ee88d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 25 May 2012 10:41:10 +0200 Subject: icera: Query initial state of SIM init status --- plugins/icera.c | 65 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'plugins/icera.c') diff --git a/plugins/icera.c b/plugins/icera.c index 7eb8b5d0..53fdf449 100644 --- a/plugins/icera.c +++ b/plugins/icera.c @@ -47,6 +47,7 @@ #include static const char *none_prefix[] = { NULL }; +static const char *siminit_prefix[] = { "%ISIMINIT:", NULL }; struct icera_data { GAtChat *chat; @@ -131,6 +132,30 @@ static GAtChat *open_device(struct ofono_modem *modem, return chat; } +static void icera_set_sim_state(struct icera_data *data, int state) +{ + DBG("state %d", state); + + switch (state) { + case 1: + if (data->have_sim == FALSE) { + ofono_sim_inserted_notify(data->sim, TRUE); + data->have_sim = TRUE; + } + break; + case 0: + case 2: + if (data->have_sim == TRUE) { + ofono_sim_inserted_notify(data->sim, FALSE); + data->have_sim = FALSE; + } + break; + default: + ofono_warn("Unknown SIM state %d received", state); + break; + } +} + static void siminit_notify(GAtResult *result, gpointer user_data) { struct ofono_modem *modem = user_data; @@ -149,19 +174,30 @@ static void siminit_notify(GAtResult *result, gpointer user_data) if (!g_at_result_iter_next_number(&iter, &state)) return; - DBG("state %d", state); + icera_set_sim_state(data, state); +} - if (state == 1) { - if (data->have_sim == FALSE) { - ofono_sim_inserted_notify(data->sim, TRUE); - data->have_sim = TRUE; - } - } else { - if (data->have_sim == TRUE) { - ofono_sim_inserted_notify(data->sim, FALSE); - data->have_sim = FALSE; - } - } +static void siminit_query(gboolean ok, GAtResult *result, gpointer user_data) +{ + struct ofono_modem *modem = user_data; + struct icera_data *data = ofono_modem_get_data(modem); + GAtResultIter iter; + int state; + + DBG(""); + + if (!ok) + return; + + g_at_result_iter_init(&iter, result); + + if (!g_at_result_iter_next(&iter, "%ISIMINIT:")) + return; + + if (!g_at_result_iter_next_number(&iter, &state)) + return; + + icera_set_sim_state(data, state); } static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) @@ -190,10 +226,13 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) /* register for SIM init notifications */ g_at_chat_register(data->chat, "%ISIMINIT:", siminit_notify, - FALSE, modem, NULL); + FALSE, modem, NULL); g_at_chat_send(data->chat, "AT%ISIMINIT=1", none_prefix, NULL, NULL, NULL); + g_at_chat_send(data->chat, "AT%ISIMINIT", siminit_prefix, + siminit_query, modem, NULL); + g_at_chat_send(data->chat, "AT*TSIMINS=1", none_prefix, NULL, NULL, NULL); } -- cgit v1.2.3