diff options
author | Dan Williams <dcbw@redhat.com> | 2012-07-27 10:27:58 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-08-03 10:53:14 -0500 |
commit | fdbab197ad15db74975f99b2e6122029c86c5a74 (patch) | |
tree | 2bc7d3320bca0ed8574cd021035a5e96668309c6 | |
parent | b6909eab7a0531dfe5a3a52b17adcfc57f5ff141 (diff) |
icera: add generic unlock retries checking
-rw-r--r-- | plugins/mm-modem-icera.c | 81 | ||||
-rw-r--r-- | plugins/mm-modem-icera.h | 4 | ||||
-rwxr-xr-x | plugins/mm-modem-samsung-gsm.c | 71 |
3 files changed, 86 insertions, 70 deletions
diff --git a/plugins/mm-modem-icera.c b/plugins/mm-modem-icera.c index 3cdf0452..800ccae7 100644 --- a/plugins/mm-modem-icera.c +++ b/plugins/mm-modem-icera.c @@ -822,6 +822,87 @@ mm_modem_icera_get_local_timestamp (MMModemIcera *self, /****************************************************************/ +static void +get_unlock_retries_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + int matched; + GArray *retry_counts; + PinRetryCount ur[4] = { + {"sim-pin", 0}, {"sim-puk", 0}, {"sim-pin2", 0}, {"sim-puk2", 0} + }; + + /* If the modem has already been removed, return without + * scheduling callback */ + if (mm_callback_info_check_modem_removed (info)) + return; + + if (error) { + info->error = g_error_copy (error); + goto done; + } + + matched = sscanf (response->str, "%%PINNUM: %d, %d, %d, %d", + &ur[0].count, &ur[1].count, &ur[2].count, &ur[3].count); + if (matched == 4) { + if (ur[0].count > 998) { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Invalid PIN attempts left %d", ur[0].count); + ur[0].count = 0; + } + + retry_counts = g_array_sized_new (FALSE, TRUE, sizeof (PinRetryCount), 4); + g_array_append_vals (retry_counts, &ur, 4); + mm_callback_info_set_result (info, retry_counts, NULL); + } else { + info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Could not parse PIN retries results"); + } + +done: + mm_serial_port_close (MM_SERIAL_PORT (port)); + mm_callback_info_schedule (info); +} + +void +mm_modem_icera_get_unlock_retries (MMModemIcera *self, + MMModemArrayFn callback, + gpointer user_data) +{ + MMAtSerialPort *port; + MMCallbackInfo *info; + + mm_dbg ("get_unlock_retries"); + + info = mm_callback_info_array_new (MM_MODEM (self), callback, user_data); + + /* Ensure we have a usable port to use for the command */ + port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + /* Modem may not be enabled yet, which sometimes can't be done until + * the device has been unlocked. In this case we have to open the port + * ourselves. + */ + if (!mm_serial_port_open (MM_SERIAL_PORT (port), &info->error)) { + mm_callback_info_schedule (info); + return; + } + + /* if the modem have not yet been enabled we need to make sure echoing is turned off */ + mm_at_serial_port_queue_command (port, "E0", 3, NULL, NULL); + mm_at_serial_port_queue_command (port, "%PINNUM?", 3, get_unlock_retries_done, info); + +} + +/****************************************************************/ + static const char * get_string_property (GHashTable *properties, const char *name) { diff --git a/plugins/mm-modem-icera.h b/plugins/mm-modem-icera.h index 131580c5..e0c4b06e 100644 --- a/plugins/mm-modem-icera.h +++ b/plugins/mm-modem-icera.h @@ -110,5 +110,9 @@ void mm_modem_icera_get_local_timestamp (MMModemIcera *self, MMModemIceraTimestampFn callback, gpointer user_data); +void mm_modem_icera_get_unlock_retries (MMModemIcera *self, + MMModemArrayFn callback, + gpointer user_data); + #endif /* MM_MODEM_ICERA_H */ diff --git a/plugins/mm-modem-samsung-gsm.c b/plugins/mm-modem-samsung-gsm.c index caf46755..0bda8994 100755 --- a/plugins/mm-modem-samsung-gsm.c +++ b/plugins/mm-modem-samsung-gsm.c @@ -274,51 +274,6 @@ get_band (MMModemGsmNetwork *modem, } static void -send_samsung_pinnum_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - int matched; - GArray *retry_counts; - PinRetryCount ur[4] = { - {"sim-pin", 0}, {"sim-puk", 0}, {"sim-pin2", 0}, {"sim-puk2", 0} - }; - - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - if (error) { - info->error = g_error_copy (error); - goto done; - } - - matched = sscanf (response->str, "%%PINNUM: %d, %d, %d, %d", - &ur[0].count, &ur[1].count, &ur[2].count, &ur[3].count); - if (matched == 4) { - if (ur[0].count > 998) { - info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, - "Invalid PIN attempts left %d", ur[0].count); - ur[0].count = 0; - } - - retry_counts = g_array_sized_new (FALSE, TRUE, sizeof (PinRetryCount), 4); - g_array_append_vals (retry_counts, &ur, 4); - mm_callback_info_set_result (info, retry_counts, NULL); - } else { - info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, - "Could not parse PIN retries results"); - } - -done: - mm_serial_port_close (MM_SERIAL_PORT (port)); - mm_callback_info_schedule (info); -} - -static void reset (MMModem *modem, MMModemFn callback, gpointer user_data) @@ -340,31 +295,7 @@ get_unlock_retries (MMModemGsmCard *modem, MMModemArrayFn callback, gpointer user_data) { - MMAtSerialPort *port; - MMCallbackInfo *info = mm_callback_info_array_new (MM_MODEM (modem), callback, user_data); - - mm_dbg ("get_unlock_retries"); - - /* Ensure we have a usable port to use for the command */ - port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (modem), &info->error); - if (!port) { - mm_callback_info_schedule (info); - return; - } - - /* Modem may not be enabled yet, which sometimes can't be done until - * the device has been unlocked. In this case we have to open the port - * ourselves. - */ - if (!mm_serial_port_open (MM_SERIAL_PORT (port), &info->error)) { - mm_callback_info_schedule (info); - return; - } - - /* if the modem have not yet been enabled we need to make sure echoing is turned off */ - mm_at_serial_port_queue_command (port, "E0", 3, NULL, NULL); - mm_at_serial_port_queue_command (port, "%PINNUM?", 3, send_samsung_pinnum_done, info); - + mm_modem_icera_get_unlock_retries (MM_MODEM_ICERA (modem), callback, user_data); } static void |