Adds a GetMsIsdn method on the org.freedesktop.ModemManager.Modem.Gsm.Card interface.
Eric
From 6d8c7029de28e821ef88729b3db896d605ccae10 Mon Sep 17 00:00:00 2001 From: Eric Shienbrood <e...@google.com> Date: Wed, 29 Jun 2011 10:03:35 -0400 Subject: [PATCH] Add GetMsIsdn method to return the phone number. This is useful even on a data-only device, where you need a phone number in order to send SMS messages to the device. --- ...org.freedesktop.ModemManager.Modem.Gsm.Card.xml | 13 +++++ src/mm-generic-gsm.c | 54 ++++++++++++++++++++ src/mm-modem-gsm-card.c | 54 ++++++++++++++++++++ src/mm-modem-gsm-card.h | 8 +++ 4 files changed, 129 insertions(+), 0 deletions(-) diff --git a/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml b/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml index 03c8a9f..18cd21f 100644 --- a/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml +++ b/introspection/org.freedesktop.ModemManager.Modem.Gsm.Card.xml @@ -55,6 +55,19 @@ </arg> </method> + <method name="GetMsIsdn"> + <tp:docstring> + Get the subscriber phone number. + </tp:docstring> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_get_msisdn"/> + <arg name="msisdn" type="s" direction="out"> + <tp:docstring> + The MSISDN. + </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 d814c57..942b44b 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -2020,6 +2020,47 @@ done: mm_callback_info_schedule (info); } +static void +get_msisdn_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + GRegex *r; + GMatchInfo *match_info; + char *msisdn = NULL; + + /* 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; + } + + r = g_regex_new ("\\+CNUM:\\s*\"?\\S*\"?,\"(\\S+)\"", G_REGEX_UNGREEDY, 0, NULL); + if (!r) { + info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NOT_SUPPORTED); + goto done; + } + + g_regex_match (r, response->str, 0, &match_info); + if (g_match_info_matches (match_info)) { + msisdn = g_match_info_fetch (match_info, 1); + } else { + info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NOT_SUPPORTED); + } + + g_match_info_free (match_info); + g_regex_unref (r); + if (msisdn != NULL) + mm_callback_info_set_result (info, msisdn, g_free); +done: + mm_callback_info_schedule (info); +} static void get_imei (MMModemGsmCard *modem, @@ -2077,6 +2118,18 @@ get_spn (MMModemGsmCard *modem, } static void +get_msisdn (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); + mm_at_serial_port_queue_command_cached (priv->primary, "+CNUM", 3, get_msisdn_done, info); +} + +static void get_card_info (MMModem *modem, MMModemInfoFn callback, gpointer user_data) @@ -5628,6 +5681,7 @@ modem_gsm_card_init (MMModemGsmCard *class) class->get_imsi = get_imsi; class->get_operator_id = get_operator_id; class->get_spn = get_spn; + class->get_msisdn = get_msisdn; 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 df55dcc..95027ec 100644 --- a/src/mm-modem-gsm-card.c +++ b/src/mm-modem-gsm-card.c @@ -34,6 +34,9 @@ static void impl_gsm_modem_get_operator_id (MMModemGsmCard *modem, static void impl_gsm_modem_get_spn (MMModemGsmCard *modem, DBusGMethodInvocation *context); +static void impl_gsm_modem_get_msisdn (MMModemGsmCard *modem, + DBusGMethodInvocation *context); + static void impl_gsm_modem_send_pin (MMModemGsmCard *modem, const char *pin, DBusGMethodInvocation *context); @@ -193,6 +196,20 @@ mm_modem_gsm_card_get_spn (MMModemGsmCard *self, } void +mm_modem_gsm_card_get_msisdn (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_msisdn) + MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_msisdn (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, @@ -375,6 +392,43 @@ impl_gsm_modem_get_spn (MMModemGsmCard *modem, DBusGMethodInvocation *context) /*****************************************************************************/ static void +msisdn_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 MSISDN */ + 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_msisdn (self, str_call_done, context); +} + +static void +impl_gsm_modem_get_msisdn (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, + msisdn_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 9716bf7..60b71ce 100644 --- a/src/mm-modem-gsm-card.h +++ b/src/mm-modem-gsm-card.h @@ -62,6 +62,10 @@ struct _MMModemGsmCard { MMModemStringFn callback, gpointer user_data); + void (*get_msisdn) (MMModemGsmCard *self, + MMModemStringFn callback, + gpointer user_data); + void (*send_puk) (MMModemGsmCard *self, const char *puk, const char *pin, @@ -109,6 +113,10 @@ void mm_modem_gsm_card_get_spn (MMModemGsmCard *self, MMModemStringFn callback, gpointer user_data); +void mm_modem_gsm_card_get_msisdn (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
_______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list