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>
This commit is contained in:
committed by
Dan Williams
parent
dfab00bf1e
commit
a1378ae8e8
@@ -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.
|
||||
|
||||
@@ -1851,6 +1851,81 @@ get_operator_id_imsi_done (MMModem *modem,
|
||||
info);
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -1888,6 +1963,24 @@ get_operator_id (MMModemGsmCard *modem,
|
||||
info);
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -175,6 +178,20 @@ mm_modem_gsm_card_get_operator_id (MMModemGsmCard *self,
|
||||
str_call_not_supported (self, callback, user_data);
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -320,6 +337,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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user