diff options
author | Dan Williams <dcbw@redhat.com> | 2012-07-19 12:12:19 -0500 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-06 20:07:26 +0200 |
commit | 32bc031ae6a8a76818bb0e8cf8f2ea5180c959a7 (patch) | |
tree | 38efe6004272d3b43c1837fd6d0f43a14c31c6d7 | |
parent | b1ebf221829ae09821d1ea6effc25feb13bd0ba5 (diff) |
hso: implement unlock retries checking
-rw-r--r-- | plugins/option/mm-broadband-modem-hso.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/option/mm-broadband-modem-hso.c b/plugins/option/mm-broadband-modem-hso.c index 55d17bbe..acd18115 100644 --- a/plugins/option/mm-broadband-modem-hso.c +++ b/plugins/option/mm-broadband-modem-hso.c @@ -111,6 +111,75 @@ modem_create_bearer (MMIfaceModem *self, } /*****************************************************************************/ +/* Load unlock retries (Modem interface) */ + +static MMUnlockRetries * +load_unlock_retries_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) + return NULL; + return (MMUnlockRetries *) g_object_ref (g_simple_async_result_get_op_res_gpointer ( + G_SIMPLE_ASYNC_RESULT (res))); +} + +static void +load_unlock_retries_ready (MMBaseModem *self, + GAsyncResult *res, + GSimpleAsyncResult *operation_result) +{ + const gchar *response; + GError *error; + int pin1, puk1; + + response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error); + if (!response) { + mm_dbg ("Couldn't query unlock retries: '%s'", error->message); + g_simple_async_result_take_error (operation_result, error); + g_simple_async_result_complete (operation_result); + g_object_unref (operation_result); + return; + } + + response = mm_strip_tag (response, "_OERCN:"); + if (sscanf (response, " %d, %d", &pin1, &puk1) == 4) { + MMUnlockRetries *retries; + retries = mm_unlock_retries_new (); + mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PIN, pin1); + mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK, puk1); + g_simple_async_result_set_op_res_gpointer (operation_result, + retries, + (GDestroyNotify)g_object_unref); + } else { + g_simple_async_result_set_error (operation_result, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Invalid unlock retries response: '%s'", + response); + } + g_simple_async_result_complete (operation_result); + g_object_unref (operation_result); +} + +static void +load_unlock_retries (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + mm_base_modem_at_command ( + MM_BASE_MODEM (self), + "_OERCN?", + 3, + FALSE, + (GAsyncReadyCallback)load_unlock_retries_ready, + g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + load_unlock_retries)); +} + +/*****************************************************************************/ /* Setup/Cleanup unsolicited events (3GPP interface) */ typedef struct { @@ -646,6 +715,8 @@ iface_modem_init (MMIfaceModem *iface) { iface->create_bearer = modem_create_bearer; iface->create_bearer_finish = modem_create_bearer_finish; + iface->load_unlock_retries = load_unlock_retries; + iface->load_unlock_retries_finish = load_unlock_retries_finish; /* HSO modems don't need the extra 10s wait after powering up */ iface->modem_after_power_up = NULL; |