On Mon, Dec 20, 2010 at 7:51 PM, Lucas De Marchi
<lucas.demarchi(a)profusion.mobi> wrote:
When SIM is locked, huawei modem does not send any notification
about
SIM state change because it does not differentiate 'invalid' from
'locked'.
In order to be able to unlock the sim, this patch forces a notification
of a valid state after a timeout.
---
plugins/huawei.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/plugins/huawei.c b/plugins/huawei.c
index bff1343..7934956 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -56,6 +56,7 @@
#include <drivers/atmodem/vendor.h>
static const char *none_prefix[] = { NULL };
+static const char *cpin_prefix[] = { "+CPIN:", NULL };
static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
static const char *ussdmode_prefix[] = { "^USSDMODE:", NULL };
static const char *cvoice_prefix[] = { "^CVOICE:", NULL };
@@ -226,6 +227,41 @@ static gboolean notify_sim_state(struct ofono_modem *modem,
return FALSE;
}
+static void cpin_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct ofono_modem *modem = user_data;
+ const char *value;
+ GAtResultIter iter;
+
+ if (!ok)
+ return;
+
+ g_at_result_iter_init(&iter, result);
+
+ if (!g_at_result_iter_next(&iter, "+CPIN:"))
+ return;
+
+ if (!g_at_result_iter_next_unquoted_string(&iter, &value))
+ return;
+
+ /* Force notification of SIM ready because it's in a locked state */
+ if (g_str_has_prefix(value, "SIM"))
+ notify_sim_state(modem, HUAWEI_SIM_STATE_VALID);
+}
As I talked to Denis through IRC, this can be simplified. We can cheat
here, not doing all this parsing and only relying on "ok" value. I
tested it with Huawei E220. I'll send another patch.
Lucas De Marchi