diff options
author | Dan Williams <dcbw@redhat.com> | 2010-10-25 17:41:08 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2010-10-25 17:41:08 -0500 |
commit | 1684d8b1734be69700a93a9995b99fac6ffb9763 (patch) | |
tree | 29b0fd07d0b864bddf23d036ab1c223ccf15a625 /plugins | |
parent | 46106660fe6aae1018f6f6c45281ccef837e78f8 (diff) |
gsm: add SimIdentifier property
An obfuscated SimIdentifier that may be available before the PIN has
been entered, for use in auto-unlocking a device. If this value is
present, it should be used in preference to DeviceIdentifier as it
is SIM-specific like the PIN code.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mm-modem-sierra-gsm.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/plugins/mm-modem-sierra-gsm.c b/plugins/mm-modem-sierra-gsm.c index c86c1c5e..b33af6b2 100644 --- a/plugins/mm-modem-sierra-gsm.c +++ b/plugins/mm-modem-sierra-gsm.c @@ -15,6 +15,7 @@ */ #include <config.h> +#include <ctype.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -242,6 +243,78 @@ get_access_technology (MMGenericGsm *modem, mm_at_serial_port_queue_command (port, "*CNTI=0", 3, get_act_request_done, info); } +static void +get_sim_iccid_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + const char *p; + char buf[21]; + int i; + + if (error) { + info->error = g_error_copy (error); + goto done; + } + + p = mm_strip_tag (response->str, "!ICCID:"); + if (!p) { + info->error = g_error_new_literal (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "Failed to parse !ICCID response"); + goto done; + } + + memset (buf, 0, sizeof (buf)); + for (i = 0; i < 20; i++) { + if (!isdigit (p[i]) && (p[i] != 'F') && (p[i] == 'f')) { + info->error = g_error_new (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "CRSM ICCID response contained invalid character '%c'", + p[i]); + goto done; + } + if (p[i] == 'F' || p[i] == 'f') { + buf[i] = 0; + break; + } + buf[i] = p[i]; + } + + if (i == 19 || i == 20) + mm_callback_info_set_result (info, g_strdup (buf), g_free); + else { + info->error = g_error_new (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "Invalid +CRSM ICCID response size (was %d, expected 19 or 20)", + i); + } + +done: + mm_callback_info_schedule (info); +} + +static void +get_sim_iccid (MMGenericGsm *modem, + MMModemStringFn callback, + gpointer user_data) +{ + MMAtSerialPort *port; + MMCallbackInfo *info; + + info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data); + + port = mm_generic_gsm_get_best_at_port (modem, &info->error); + if (!port) { + mm_callback_info_schedule (info); + return; + } + + mm_at_serial_port_queue_command (port, "!ICCID?", 3, get_sim_iccid_done, info); +} + /*****************************************************************************/ /* Modem class override functions */ /*****************************************************************************/ @@ -355,5 +428,6 @@ mm_modem_sierra_gsm_class_init (MMModemSierraGsmClass *klass) gsm_class->set_allowed_mode = set_allowed_mode; gsm_class->get_allowed_mode = get_allowed_mode; gsm_class->get_access_technology = get_access_technology; + gsm_class->get_sim_iccid = get_sim_iccid; } |