diff options
author | Andrzej Zaborowski <andrew.zaborowski@intel.com> | 2009-09-24 00:33:28 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-09-23 14:27:52 -0500 |
commit | 2a02f45c79c3bc078e3c8442f358416adc9b79b5 (patch) | |
tree | a435525102a4fbda734ba7038fb2a7a1adf18687 /drivers | |
parent | c98e99aef27c47355219cec72a99885c679e60d1 (diff) | |
download | ofono-2a02f45c79c3bc078e3c8442f358416adc9b79b5.tar.bz2 |
Add plugin interface for getting PIN lock state.
It may be useful to have the information of whether card is currently
locked and emit events when this changes but if we want to have it as a
property, we would need properties for all types of locks and it wouldn't
be all that useful.
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/atmodem/sim.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c index b7d83684..d04b736c 100644 --- a/drivers/atmodem/sim.c +++ b/drivers/atmodem/sim.c @@ -634,6 +634,66 @@ error: CALLBACK_WITH_FAILURE(cb, data); } +static void at_lock_status_cb(gboolean ok, GAtResult *result, + gpointer user_data) +{ + struct cb_data *cbd = user_data; + GAtResultIter iter; + ofono_sim_locked_cb_t cb = cbd->cb; + struct ofono_error error; + int locked; + + dump_response("at_lock_status_cb", ok, result); + decode_at_error(&error, g_at_result_final_response(result)); + + if (!ok) { + cb(&error, -1, cbd->data); + return; + } + + g_at_result_iter_init(&iter, result); + + if (!g_at_result_iter_next(&iter, "+CLCK:")) { + CALLBACK_WITH_FAILURE(cb, -1, cbd->data); + return; + } + + g_at_result_iter_next_number(&iter, &locked); + + ofono_debug("lock_status_cb: %i", locked); + + cb(&error, locked, cbd->data); +} + +static void at_pin_query_enabled(struct ofono_sim *sim, + enum ofono_sim_password_type passwd_type, + ofono_sim_locked_cb_t cb, void *data) +{ + GAtChat *chat = ofono_sim_get_data(sim); + struct cb_data *cbd = cb_data_new(cb, data); + char buf[64]; + unsigned int len = sizeof(at_clck_cpwd_fac) / sizeof(*at_clck_cpwd_fac); + + if (!cbd) + goto error; + + if (passwd_type >= len || !at_clck_cpwd_fac[passwd_type]) + goto error; + + snprintf(buf, sizeof(buf), "AT+CLCK=\"%s\",2", + at_clck_cpwd_fac[passwd_type]); + + if (g_at_chat_send(chat, buf, NULL, + at_lock_status_cb, cbd, g_free) > 0) + return; + +error: + if (cbd) + g_free(cbd); + + CALLBACK_WITH_FAILURE(cb, -1, data); +} + static gboolean at_sim_register(gpointer user) { struct ofono_sim *sim = user; @@ -675,6 +735,7 @@ static struct ofono_sim_driver driver = { .reset_passwd = at_pin_send_puk, .lock = at_pin_enable, .change_passwd = at_change_passwd, + .query_locked = at_pin_query_enabled, }; void at_sim_init() |