modem: move GetInfo from GsmCard -> Modem interface
It's generic, everything implements some variant of +GMM, +GMR, and +GMI.
This commit is contained in:
@@ -28,19 +28,6 @@
|
||||
</arg>
|
||||
</method>
|
||||
|
||||
<method name="GetInfo">
|
||||
<tp:docstring>
|
||||
Get the card information (manufacturer, modem, version).
|
||||
</tp:docstring>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_get_info"/>
|
||||
<arg name="info" type="(sss)" direction="out">
|
||||
<tp:docstring>
|
||||
Structure containing manufacturer, model, and version (revision) of the card.
|
||||
</tp:docstring>
|
||||
</arg>
|
||||
</method>
|
||||
|
||||
<method name="SendPuk">
|
||||
<tp:docstring>
|
||||
Send the PUK and a new PIN to unlock the SIM card.
|
||||
|
@@ -49,6 +49,19 @@
|
||||
</arg>
|
||||
</method>
|
||||
|
||||
<method name="GetInfo">
|
||||
<tp:docstring>
|
||||
Get the card information (manufacturer, modem, version).
|
||||
</tp:docstring>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_get_info"/>
|
||||
<arg name="info" type="(sss)" direction="out">
|
||||
<tp:docstring>
|
||||
Structure containing manufacturer, model, and version (revision) of the card.
|
||||
</tp:docstring>
|
||||
</arg>
|
||||
</method>
|
||||
|
||||
<property name="Device" type="s" access="read">
|
||||
<tp:docstring>
|
||||
The modem port to use for IP configuration and traffic.
|
||||
|
@@ -248,6 +248,100 @@ disconnect (MMModem *modem,
|
||||
mm_serial_port_flash (priv->primary, 1000, disconnect_flash_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
card_info_invoke (MMCallbackInfo *info)
|
||||
{
|
||||
MMModemInfoFn callback = (MMModemInfoFn) info->callback;
|
||||
|
||||
callback (info->modem,
|
||||
(char *) mm_callback_info_get_data (info, "card-info-manufacturer"),
|
||||
(char *) mm_callback_info_get_data (info, "card-info-model"),
|
||||
(char *) mm_callback_info_get_data (info, "card-info-version"),
|
||||
info->error, info->user_data);
|
||||
}
|
||||
|
||||
static const char *
|
||||
strip_info_response (const char *resp, const char *cmd)
|
||||
{
|
||||
const char *p = resp;
|
||||
|
||||
if (p) {
|
||||
if (!strncmp (p, cmd, strlen (cmd)))
|
||||
p += strlen (cmd);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static void
|
||||
get_version_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
const char *p;
|
||||
|
||||
if (!error) {
|
||||
p = strip_info_response (response->str, "+GMR:");
|
||||
mm_callback_info_set_data (info, "card-info-version", g_strdup (p), g_free);
|
||||
} else if (!info->error)
|
||||
info->error = g_error_copy (error);
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
get_model_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
const char *p;
|
||||
|
||||
if (!error) {
|
||||
p = strip_info_response (response->str, "+GMM:");
|
||||
mm_callback_info_set_data (info, "card-info-model", g_strdup (p), g_free);
|
||||
} else if (!info->error)
|
||||
info->error = g_error_copy (error);
|
||||
}
|
||||
|
||||
static void
|
||||
get_manufacturer_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
const char *p;
|
||||
|
||||
if (!error) {
|
||||
p = strip_info_response (response->str, "+GMI:");
|
||||
mm_callback_info_set_data (info, "card-info-manufacturer", g_strdup (p), g_free);
|
||||
} else
|
||||
info->error = g_error_copy (error);
|
||||
}
|
||||
|
||||
static void
|
||||
get_card_info (MMModem *modem,
|
||||
MMModemInfoFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMGenericCdmaPrivate *priv = MM_GENERIC_CDMA_GET_PRIVATE (modem);
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_new_full (MM_MODEM (modem),
|
||||
card_info_invoke,
|
||||
G_CALLBACK (callback),
|
||||
user_data);
|
||||
|
||||
mm_serial_port_queue_command_cached (priv->primary, "+GMI", 3, get_manufacturer_done, info);
|
||||
mm_serial_port_queue_command_cached (priv->primary, "+GMM", 3, get_model_done, info);
|
||||
mm_serial_port_queue_command_cached (priv->primary, "+GMR", 3, get_version_done, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
get_signal_quality_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
@@ -456,6 +550,7 @@ modem_init (MMModem *modem_class)
|
||||
modem_class->enable = enable;
|
||||
modem_class->connect = connect;
|
||||
modem_class->disconnect = disconnect;
|
||||
modem_class->get_info = get_card_info;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -421,11 +421,11 @@ get_imsi (MMModemGsmCard *modem,
|
||||
}
|
||||
|
||||
static void
|
||||
gsm_card_info_invoke (MMCallbackInfo *info)
|
||||
card_info_invoke (MMCallbackInfo *info)
|
||||
{
|
||||
MMModemGsmCardInfoFn callback = (MMModemGsmCardInfoFn) info->callback;
|
||||
MMModemInfoFn callback = (MMModemInfoFn) info->callback;
|
||||
|
||||
callback (MM_MODEM_GSM_CARD (info->modem),
|
||||
callback (info->modem,
|
||||
(char *) mm_callback_info_get_data (info, "card-info-manufacturer"),
|
||||
(char *) mm_callback_info_get_data (info, "card-info-model"),
|
||||
(char *) mm_callback_info_get_data (info, "card-info-version"),
|
||||
@@ -477,15 +477,15 @@ get_manufacturer_done (MMSerialPort *port,
|
||||
}
|
||||
|
||||
static void
|
||||
get_card_info (MMModemGsmCard *modem,
|
||||
MMModemGsmCardInfoFn callback,
|
||||
get_card_info (MMModem *modem,
|
||||
MMModemInfoFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_new_full (MM_MODEM (modem),
|
||||
gsm_card_info_invoke,
|
||||
card_info_invoke,
|
||||
G_CALLBACK (callback),
|
||||
user_data);
|
||||
|
||||
@@ -1662,6 +1662,7 @@ modem_init (MMModem *modem_class)
|
||||
modem_class->enable = enable;
|
||||
modem_class->connect = connect;
|
||||
modem_class->disconnect = disconnect;
|
||||
modem_class->get_info = get_card_info;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1669,7 +1670,6 @@ modem_gsm_card_init (MMModemGsmCard *class)
|
||||
{
|
||||
class->get_imei = get_imei;
|
||||
class->get_imsi = get_imsi;
|
||||
class->get_info = get_card_info;
|
||||
class->send_pin = send_pin;
|
||||
class->send_puk = send_puk;
|
||||
class->enable_pin = enable_pin;
|
||||
|
@@ -12,9 +12,6 @@ static void impl_gsm_modem_get_imei (MMModemGsmCard *modem,
|
||||
static void impl_gsm_modem_get_imsi (MMModemGsmCard *modem,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
static void impl_gsm_modem_get_info (MMModemGsmCard *modem,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
static void impl_gsm_modem_send_pin (MMModemGsmCard *modem,
|
||||
const char *pin,
|
||||
DBusGMethodInvocation *context);
|
||||
@@ -63,68 +60,6 @@ str_call_not_supported (MMModemGsmCard *self,
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
info_call_done (MMModemGsmCard *self,
|
||||
const char *manufacturer,
|
||||
const char *model,
|
||||
const char *version,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
|
||||
|
||||
if (error)
|
||||
dbus_g_method_return_error (context, error);
|
||||
else {
|
||||
GValueArray *array;
|
||||
GValue value = { 0, };
|
||||
|
||||
array = g_value_array_new (3);
|
||||
|
||||
/* Manufacturer */
|
||||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value, manufacturer);
|
||||
g_value_array_append (array, &value);
|
||||
g_value_unset (&value);
|
||||
|
||||
/* Model */
|
||||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value, model);
|
||||
g_value_array_append (array, &value);
|
||||
g_value_unset (&value);
|
||||
|
||||
/* Version */
|
||||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value, version);
|
||||
g_value_array_append (array, &value);
|
||||
g_value_unset (&value);
|
||||
|
||||
dbus_g_method_return (context, array);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
info_invoke (MMCallbackInfo *info)
|
||||
{
|
||||
MMModemGsmCardInfoFn callback = (MMModemGsmCardInfoFn) info->callback;
|
||||
|
||||
callback (MM_MODEM_GSM_CARD (info->modem), NULL, NULL, NULL, info->error, info->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
info_call_not_supported (MMModemGsmCard *self,
|
||||
MMModemGsmCardInfoFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_new_full (MM_MODEM (self), info_invoke, G_CALLBACK (callback), user_data);
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
|
||||
"Operation not supported");
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
async_call_done (MMModem *modem, GError *error, gpointer user_data)
|
||||
{
|
||||
@@ -179,20 +114,6 @@ mm_modem_gsm_card_get_imsi (MMModemGsmCard *self,
|
||||
str_call_not_supported (self, callback, user_data);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_gsm_card_get_info (MMModemGsmCard *self,
|
||||
MMModemGsmCardInfoFn 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_info)
|
||||
MM_MODEM_GSM_CARD_GET_INTERFACE (self)->get_info (self, callback, user_data);
|
||||
else
|
||||
info_call_not_supported (self, callback, user_data);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_gsm_card_send_puk (MMModemGsmCard *self,
|
||||
const char *puk,
|
||||
@@ -278,13 +199,6 @@ impl_gsm_modem_get_imsi (MMModemGsmCard *modem,
|
||||
mm_modem_gsm_card_get_imsi (modem, str_call_done, context);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_gsm_modem_get_info (MMModemGsmCard *modem,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
mm_modem_gsm_card_get_info (modem, info_call_done, context);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_gsm_modem_send_puk (MMModemGsmCard *modem,
|
||||
const char *puk,
|
||||
|
@@ -12,13 +12,6 @@
|
||||
|
||||
typedef struct _MMModemGsmCard MMModemGsmCard;
|
||||
|
||||
typedef void (*MMModemGsmCardInfoFn) (MMModemGsmCard *self,
|
||||
const char *manufacturer,
|
||||
const char *model,
|
||||
const char *version,
|
||||
GError *error,
|
||||
gpointer user_data);
|
||||
|
||||
struct _MMModemGsmCard {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
@@ -31,10 +24,6 @@ struct _MMModemGsmCard {
|
||||
MMModemStringFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void (*get_info) (MMModemGsmCard *self,
|
||||
MMModemGsmCardInfoFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void (*send_puk) (MMModemGsmCard *self,
|
||||
const char *puk,
|
||||
const char *pin,
|
||||
@@ -69,10 +58,6 @@ void mm_modem_gsm_card_get_imsi (MMModemGsmCard *self,
|
||||
MMModemStringFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_modem_gsm_card_get_info (MMModemGsmCard *self,
|
||||
MMModemGsmCardInfoFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_modem_gsm_card_send_puk (MMModemGsmCard *self,
|
||||
const char *puk,
|
||||
const char *pin,
|
||||
|
@@ -10,6 +10,7 @@ static void impl_modem_enable (MMModem *modem, gboolean enable, DBusGMethodInvoc
|
||||
static void impl_modem_connect (MMModem *modem, const char *number, DBusGMethodInvocation *context);
|
||||
static void impl_modem_disconnect (MMModem *modem, DBusGMethodInvocation *context);
|
||||
static void impl_modem_get_ip4_config (MMModem *modem, DBusGMethodInvocation *context);
|
||||
static void impl_modem_get_info (MMModem *modem, DBusGMethodInvocation *context);
|
||||
|
||||
#include "mm-modem-glue.h"
|
||||
|
||||
@@ -196,6 +197,88 @@ impl_modem_disconnect (MMModem *modem,
|
||||
mm_modem_disconnect (modem, async_call_done, context);
|
||||
}
|
||||
|
||||
static void
|
||||
info_call_done (MMModem *self,
|
||||
const char *manufacturer,
|
||||
const char *model,
|
||||
const char *version,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
|
||||
|
||||
if (error)
|
||||
dbus_g_method_return_error (context, error);
|
||||
else {
|
||||
GValueArray *array;
|
||||
GValue value = { 0, };
|
||||
|
||||
array = g_value_array_new (3);
|
||||
|
||||
/* Manufacturer */
|
||||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value, manufacturer);
|
||||
g_value_array_append (array, &value);
|
||||
g_value_unset (&value);
|
||||
|
||||
/* Model */
|
||||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value, model);
|
||||
g_value_array_append (array, &value);
|
||||
g_value_unset (&value);
|
||||
|
||||
/* Version */
|
||||
g_value_init (&value, G_TYPE_STRING);
|
||||
g_value_set_string (&value, version);
|
||||
g_value_array_append (array, &value);
|
||||
g_value_unset (&value);
|
||||
|
||||
dbus_g_method_return (context, array);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
info_invoke (MMCallbackInfo *info)
|
||||
{
|
||||
MMModemInfoFn callback = (MMModemInfoFn) info->callback;
|
||||
|
||||
callback (info->modem, NULL, NULL, NULL, info->error, info->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
info_call_not_supported (MMModem *self,
|
||||
MMModemInfoFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_new_full (MM_MODEM (self), info_invoke, G_CALLBACK (callback), user_data);
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
|
||||
"Operation not supported");
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_get_info (MMModem *self,
|
||||
MMModemInfoFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (MM_IS_MODEM (self));
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
if (MM_MODEM_GET_INTERFACE (self)->get_info)
|
||||
MM_MODEM_GET_INTERFACE (self)->get_info (self, callback, user_data);
|
||||
else
|
||||
info_call_not_supported (self, callback, user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_modem_get_info (MMModem *modem,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
mm_modem_get_info (modem, info_call_done, context);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
@@ -60,6 +60,13 @@ typedef void (*MMModemIp4Fn) (MMModem *modem,
|
||||
GError *error,
|
||||
gpointer user_data);
|
||||
|
||||
typedef void (*MMModemInfoFn) (MMModem *modem,
|
||||
const char *manufacturer,
|
||||
const char *model,
|
||||
const char *version,
|
||||
GError *error,
|
||||
gpointer user_data);
|
||||
|
||||
struct _MMModem {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
@@ -94,6 +101,10 @@ struct _MMModem {
|
||||
void (*disconnect) (MMModem *self,
|
||||
MMModemFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void (*get_info) (MMModem *self,
|
||||
MMModemInfoFn callback,
|
||||
gpointer user_data);
|
||||
};
|
||||
|
||||
GType mm_modem_get_type (void);
|
||||
@@ -129,6 +140,10 @@ void mm_modem_disconnect (MMModem *self,
|
||||
MMModemFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_modem_get_info (MMModem *self,
|
||||
MMModemInfoFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean mm_modem_get_valid (MMModem *self);
|
||||
|
||||
char *mm_modem_get_device (MMModem *self);
|
||||
|
@@ -71,9 +71,6 @@ def inspect_gsm(proxy):
|
||||
pass
|
||||
print "IMSI: %s" % card.GetImsi()
|
||||
|
||||
info = card.GetInfo()
|
||||
print "Vendor: '%s' Model: '%s' Version: '%s'" % info
|
||||
|
||||
# Gsm.Network interface
|
||||
net = dbus.Interface(proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM_GSM_NETWORK)
|
||||
print "Signal quality: %d" % net.GetSignalQuality()
|
||||
@@ -130,6 +127,11 @@ for m in modems:
|
||||
modem = dbus.Interface(proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM)
|
||||
modem.Enable(True)
|
||||
|
||||
info = modem.GetInfo()
|
||||
print "Vendor: %s" % info[0]
|
||||
print "Model: %s" % info[1]
|
||||
print "Version: %s" % info[2]
|
||||
|
||||
if type == 1:
|
||||
inspect_gsm(proxy)
|
||||
elif type == 2:
|
||||
|
Reference in New Issue
Block a user