[PATCH] ModemManager: Add and implement an interface to get a GSM SPN
- From: Nathan Williams <njw google com>
- To: "networkmanager-list gnome org" <networkmanager-list gnome org>
- Subject: [PATCH] ModemManager: Add and implement an interface to get a GSM SPN
- Date: Thu, 26 May 2011 12:32:42 -0400
This adds a feature in parallel with GetOperatorId, which gets the GSM
Service Provider Name value from the SIM card; this is useful for
displaying the name of the home operator when said operator is a MVNO
or otherwise branded differently than the carrier's usual name.
There's clearly some code to be factored out of the various routines
that parse the response of AT+CRSM commands, but that cleanup will
come in a separate patch.
- Nathan
From 94bb1798e85a9a5c91eeaa6b82c7300591953aa6 Mon Sep 17 00:00:00 2001
From: Nathan Williams <njw google com>
Date: Fri, 20 May 2011 17:31:34 -0400
Subject: [PATCH] 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>
---
...org.freedesktop.ModemManager.Modem.Gsm.Card.xml | 13 +++
src/mm-generic-gsm.c | 94 ++++++++++++++++++++
src/mm-modem-gsm-card.c | 54 +++++++++++
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 bf33f4c..e6af331 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 58454da..5b33ed7 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -1847,6 +1847,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)
@@ -1884,6 +1959,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)
@@ -5187,6 +5280,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 d04f014..df55dcc 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 e617d8f..9716bf7 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,
--
1.7.3.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]