diff options
author | Nathan Williams <njw@google.com> | 2011-05-20 17:31:34 -0400 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-06-02 17:45:56 -0500 |
commit | a1378ae8e82e4372ca2a7abf747ff5e418675907 (patch) | |
tree | aa760a2f006eb1c7cd59949e39a95e2c197ef86d | |
parent | dfab00bf1ecc15d5df911496b375a77ecb7b7b79 (diff) |
Spec out and implement a command to get a GSM SIM SPN value.
Using a SIM with a SPN, run the following command:
dbus-send --system --dest=org.freedesktop.ModemManager --print-reply /org/freedesktop/ModemManager/Modems/0 org.freedesktop.ModemManager.Modem.Gsm.Card.GetSpn
Change-Id: I8f36c8432f40fa4e3cb3f8c6ceef16b2bdadf2a1
Reviewed-on: http://gerrit.chromium.org/gerrit/1464
Reviewed-by: Nathan J. Williams <njw@chromium.org>
Tested-by: Nathan J. Williams <njw@chromium.org>
-rw-r--r-- | introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml | 13 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 94 | ||||
-rw-r--r-- | src/mm-modem-gsm-card.c | 54 | ||||
-rw-r--r-- | src/mm-modem-gsm-card.h | 8 |
4 files changed, 169 insertions, 0 deletions
diff --git a/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml b/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml index bf33f4c6..e6af3314 100644 --- a/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml +++ b/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml @@ -42,6 +42,19 @@ </arg> </method> + <method name="GetSpn"> + <tp:docstring> + Returns the SPN (Service Provider Name) from the SIM card, + </tp:docstring> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_get_spn"/> + <arg name="spn" type="s" direction="out"> + <tp:docstring> + The Service Provider Name. + </tp:docstring> + </arg> + </method> + <method name="SendPuk"> <tp:docstring> Send the PUK and a new PIN to unlock the SIM card. diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index 16f68b0d..c014b238 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -1852,6 +1852,81 @@ get_operator_id_imsi_done (MMModem *modem, } static void +get_spn_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + int sw1, sw2; + gboolean success = FALSE; + char hex[51]; + char *bin, *utf8; + + if (error) { + info->error = g_error_copy (error); + goto done; + } + + memset (hex, 0, sizeof (hex)); + if (sscanf (response->str, "+CRSM:%d,%d,\"%50c\"", &sw1, &sw2, (char *) &hex) == 3) + success = TRUE; + else { + /* May not include quotes... */ + if (sscanf (response->str, "+CRSM:%d,%d,%50c", &sw1, &sw2, (char *) &hex) == 3) + success = TRUE; + } + + if (!success) { + info->error = g_error_new_literal (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "Could not parse the CRSM response"); + goto done; + } + + if ((sw1 == 0x90 && sw2 == 0x00) || (sw1 == 0x91) || (sw1 == 0x92) || (sw1 == 0x9f)) { + gsize buflen = 0; + + /* Make sure the buffer is only hex characters */ + while (buflen < sizeof (hex) && hex[buflen]) { + if (!isxdigit (hex[buflen])) { + hex[buflen] = 0x0; + break; + } + buflen++; + } + + /* Convert hex string to binary */ + bin = utils_hexstr2bin (hex, &buflen); + if (!bin) { + info->error = g_error_new (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "SIM returned malformed response '%s'", + hex); + goto done; + } + + /* Remove the FF filler at the end */ + while (bin[buflen - 1] == (char)0xff) + buflen--; + + /* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */ + utf8 = (char *)mm_charset_gsm_unpacked_to_utf8 ((guint8 *)bin + 1, buflen - 1); + g_free(bin); + mm_callback_info_set_result(info, utf8, g_free); + } else { + info->error = g_error_new (MM_MODEM_ERROR, + MM_MODEM_ERROR_GENERAL, + "SIM failed to handle CRSM request (sw1 %d sw2 %d)", + sw1, sw2); + } + +done: + mm_callback_info_schedule (info); +} + + +static void get_imei (MMModemGsmCard *modem, MMModemStringFn callback, gpointer user_data) @@ -1889,6 +1964,24 @@ get_operator_id (MMModemGsmCard *modem, } static void +get_spn (MMModemGsmCard *modem, + MMModemStringFn callback, + gpointer user_data) +{ + MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (modem); + MMCallbackInfo *info; + + info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data); + + /* READ BINARY of EFspn (Service Provider Name) ETSI 51.011 section 10.3.11 */ + mm_at_serial_port_queue_command_cached (priv->primary, + "+CRSM=176,28486,0,0,17", + 3, + get_spn_done, + info); +} + +static void get_card_info (MMModem *modem, MMModemInfoFn callback, gpointer user_data) @@ -5211,6 +5304,7 @@ modem_gsm_card_init (MMModemGsmCard *class) class->get_imei = get_imei; class->get_imsi = get_imsi; class->get_operator_id = get_operator_id; + class->get_spn = get_spn; class->send_pin = send_pin; class->send_puk = send_puk; class->enable_pin = enable_pin; diff --git a/src/mm-modem-gsm-card.c b/src/mm-modem-gsm-card.c index d04f0146..df55dcc8 100644 --- a/src/mm-modem-gsm-card.c +++ b/src/mm-modem-gsm-card.c @@ -31,6 +31,9 @@ static void impl_gsm_modem_get_imsi (MMModemGsmCard *modem, static void impl_gsm_modem_get_operator_id (MMModemGsmCard *modem, DBusGMethodInvocation *context); +static void impl_gsm_modem_get_spn (MMModemGsmCard *modem, + DBusGMethodInvocation *context); + static void impl_gsm_modem_send_pin (MMModemGsmCard *modem, const char *pin, DBusGMethodInvocation *context); @@ -176,6 +179,20 @@ mm_modem_gsm_card_get_operator_id (MMModemGsmCard *self, } void +mm_modem_gsm_card_get_spn (MMModemGsmCard *self, + MMModemStringFn callback, + gpointer user_data) +{ + g_return_if_fail (MM_IS_MODEM_GSM_CARD (self)); + g_return_if_fail (callback != NULL); + + if (MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_spn) + MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_spn (self, callback, user_data); + else + str_call_not_supported (self, callback, user_data); +} + +void mm_modem_gsm_card_send_puk (MMModemGsmCard *self, const char *puk, const char *pin, @@ -321,6 +338,43 @@ impl_gsm_modem_get_imsi (MMModemGsmCard *modem, DBusGMethodInvocation *context) /*****************************************************************************/ static void +spn_auth_cb (MMAuthRequest *req, + GObject *owner, + DBusGMethodInvocation *context, + gpointer user_data) +{ + MMModemGsmCard *self = MM_MODEM_GSM_CARD (owner); + GError *error = NULL; + + /* Return any authorization error, otherwise get the SPN */ + if (!mm_modem_auth_finish (MM_MODEM (self), req, &error)) { + dbus_g_method_return_error (context, error); + g_error_free (error); + } else + mm_modem_gsm_card_get_spn (self, str_call_done, context); +} + +static void +impl_gsm_modem_get_spn (MMModemGsmCard *modem, DBusGMethodInvocation *context) +{ + GError *error = NULL; + + /* Make sure the caller is authorized to get the SPN */ + if (!mm_modem_auth_request (MM_MODEM (modem), + MM_AUTHORIZATION_DEVICE_INFO, + context, + spn_auth_cb, + NULL, + NULL, + &error)) { + dbus_g_method_return_error (context, error); + g_error_free (error); + } +} + +/*****************************************************************************/ + +static void operator_id_auth_cb (MMAuthRequest *req, GObject *owner, DBusGMethodInvocation *context, diff --git a/src/mm-modem-gsm-card.h b/src/mm-modem-gsm-card.h index e617d8fe..9716bf73 100644 --- a/src/mm-modem-gsm-card.h +++ b/src/mm-modem-gsm-card.h @@ -58,6 +58,10 @@ struct _MMModemGsmCard { MMModemStringFn callback, gpointer user_data); + void (*get_spn) (MMModemGsmCard *self, + MMModemStringFn callback, + gpointer user_data); + void (*send_puk) (MMModemGsmCard *self, const char *puk, const char *pin, @@ -101,6 +105,10 @@ void mm_modem_gsm_card_get_operator_id (MMModemGsmCard *self, MMModemStringFn callback, gpointer user_data); +void mm_modem_gsm_card_get_spn (MMModemGsmCard *self, + MMModemStringFn callback, + gpointer user_data); + void mm_modem_gsm_card_send_puk (MMModemGsmCard *self, const char *puk, const char *pin, |