diff options
author | Tambet Ingo <tambet@gmail.com> | 2009-02-06 13:34:02 +0200 |
---|---|---|
committer | Tambet Ingo <tambet@gmail.com> | 2009-02-06 13:34:02 +0200 |
commit | fd5f4222d7c18a3279085edd4ca6ed36247923e6 (patch) | |
tree | c4bd92fe5296bdda7cd02878835519778bfbcd19 | |
parent | 19bd7d7e7f9e6128f29de8888ba23071f8f4e4d8 (diff) |
Extend org.freedesktop.ModemManager.Modem interface.
* Add IpMethod property with known values ppp (default), static, DHCP.
* Rename DataDevice property to Device.
* Add GetIP4Config method. It should be implemented only when IpMethod==static.
* Update org.freedesktop.ModemManager.Modem.Gsm.Sms interface based on
Pablo Martà Gamboa's suggestions.
* Adjust MBM and HSO interfaces to take advantage of the generic Modem
interface.
-rw-r--r-- | introspection/Makefile.am | 1 | ||||
-rw-r--r-- | introspection/mm-modem-gsm-hso.xml | 21 | ||||
-rw-r--r-- | introspection/mm-modem-gsm-sms.xml | 36 | ||||
-rw-r--r-- | introspection/mm-modem.xml | 41 | ||||
-rw-r--r-- | plugins/Makefile.am | 7 | ||||
-rw-r--r-- | plugins/mm-modem-hso.c | 259 | ||||
-rw-r--r-- | plugins/mm-modem-hso.h | 14 | ||||
-rw-r--r-- | plugins/mm-modem-huawei.c | 3 | ||||
-rw-r--r-- | plugins/mm-modem-mbm.c | 71 | ||||
-rw-r--r-- | plugins/mm-modem-mbm.h | 19 | ||||
-rw-r--r-- | plugins/mm-modem-novatel.c | 3 | ||||
-rw-r--r-- | plugins/mm-modem-option.c | 1 | ||||
-rw-r--r-- | plugins/mm-modem-sierra.c | 1 | ||||
-rw-r--r-- | src/mm-generic-cdma.c | 17 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 30 | ||||
-rw-r--r-- | src/mm-modem.c | 108 | ||||
-rw-r--r-- | src/mm-modem.h | 30 | ||||
-rw-r--r-- | src/mm-serial.h | 2 |
18 files changed, 356 insertions, 308 deletions
diff --git a/introspection/Makefile.am b/introspection/Makefile.am index 03a2e4a4..3712db8a 100644 --- a/introspection/Makefile.am +++ b/introspection/Makefile.am @@ -8,7 +8,6 @@ EXTRA_DIST = \ mm-modem-gsm-card.xml \ mm-modem-gsm-contacts.xml \ mm-modem-gsm-hso.xml \ - mm-modem-gsm-mbm.xml \ mm-modem-gsm-network.xml \ mm-modem-gsm-sms.xml \ mm-modem-simple.xml \ diff --git a/introspection/mm-modem-gsm-hso.xml b/introspection/mm-modem-gsm-hso.xml index bb631c07..d646acc3 100644 --- a/introspection/mm-modem-gsm-hso.xml +++ b/introspection/mm-modem-gsm-hso.xml @@ -15,26 +15,5 @@ The password. </arg> </method> - - <method name="GetIP4Config"> - <tp:docstring> - Request the IP4 configuration from the device. - </tp:docstring> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_hso_get_ip4_config"/> - <arg name="address" type="u" direction="out"> - The IP4 address. - </arg> - <arg name="dns" type="au" direction="out"> - The DNS addresses. - </arg> - </method> - - <property name="NetworkDevice" type="s" access="read"> - <tp:docstring> - The network device. - </tp:docstring> - </property> - </interface> </node> diff --git a/introspection/mm-modem-gsm-sms.xml b/introspection/mm-modem-gsm-sms.xml index e710c166..69bf7351 100644 --- a/introspection/mm-modem-gsm-sms.xml +++ b/introspection/mm-modem-gsm-sms.xml @@ -26,11 +26,7 @@ The index of the SMS. </tp:docstring> </arg> - <arg name="sms" type="(ussd)" direction="out"> - <tp:docstring> - The SMS structure containing index, number, contents and time stamp. - </tp:docstring> - </arg> + <arg name="sms" type="a{sv}" direction="out"/> </method> <method name="GetFormat"> @@ -50,17 +46,37 @@ </method> <method name="List"> - <arg name="result" type="a(ussd)" direction="out"/> + <arg name="result" type="aa{sv}" direction="out"/> </method> <method name="Save"> - <arg name="number" type="s" direction="in"/> - <arg name="contents" type="s" direction="in"/> - <arg name="index" type="u" direction="out"/> + <arg name="properties" type="a{sv}" direction="in"> + <tp:docstring> + SMS properties to save with the following key values: + + number : string - Phone number (mandatory) + text : string - SMS text (mandatory) + smsc : string - SMS service center number (optional) + validity : uint (0..255) - Specifies when the SMS expires in SMSC (optional) + class : uint (0..3) - Message importance and location (optional) + </tp:docstring> + </arg> + <arg name="index" type="au" direction="out"/> </method> <method name="Send"> - <arg name="result" type="u" direction="out"/> + <arg name="properties" type="a{sv}" direction="in"> + <tp:docstring> + SMS properties to save with the following key values: + + number : string - Phone number (mandatory) + text : string - SMS text (mandatory) + smsc : string - SMS service center number (optional) + validity : uint (0..255) - Specifies when the SMS expires in SMSC (optional) + class : uint (0..3) - Message importance and location (optional) + </tp:docstring> + </arg> + <arg name="result" type="au" direction="out"/> </method> <method name="SendFromStorage"> diff --git a/introspection/mm-modem.xml b/introspection/mm-modem.xml index 25ecf941..ecf5ec8b 100644 --- a/introspection/mm-modem.xml +++ b/introspection/mm-modem.xml @@ -36,9 +36,22 @@ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_disconnect"/> </method> - <property name="DataDevice" type="s" access="read"> + <method name="GetIP4Config"> <tp:docstring> - The serial device which can be used to start pppd. + Request the IP4 configuration from the device. + Note that it'll only be supported for IPMethod MM_MODEM_IP_METHOD_STATIC. + </tp:docstring> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_get_ip4_config"/> + <arg name="address" type="(uuuu)" direction="out"> + Structure containing IP4 address, DNS1, DNS2, DNS3. + The DNS list is padded with 0's if there's less than 3 DNS servers. + </arg> + </method> + + <property name="Device" type="s" access="read"> + <tp:docstring> + The device to use for IP configuration and traffic. </tp:docstring> </property> @@ -54,6 +67,12 @@ </tp:docstring> </property> + <property name="IpMethod" type="u" access="read" tp:type="MM_MODEM_IP_METHOD"> + <tp:docstring> + The IP configuration method. + </tp:docstring> + </property> + <tp:enum name="MM_MODEM_TYPE" type="u"> <tp:enumvalue suffix="GSM" value="1"> <tp:docstring> @@ -67,5 +86,23 @@ </tp:enumvalue> </tp:enum> + <tp:enum name="MM_MODEM_IP_METHOD" type="u"> + <tp:enumvalue suffix="PPP" value="0"> + <tp:docstring> + Use PPP to get the address. + </tp:docstring> + </tp:enumvalue> + <tp:enumvalue suffix="STATIC" value="1"> + <tp:docstring> + Static configuration, the modem will provide IP information. + </tp:docstring> + </tp:enumvalue> + <tp:enumvalue suffix="DHCP" value="2"> + <tp:docstring> + Use DHCP + </tp:docstring> + </tp:enumvalue> + </tp:enum> + </interface> </node> diff --git a/plugins/Makefile.am b/plugins/Makefile.am index b98af706..813b37c4 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -41,15 +41,11 @@ libmm_plugin_hso_la_LDFLAGS = -module -avoid-version # MBM libmm_plugin_mbm_la_SOURCES = \ - mm-modem-gsm-mbm-glue.h \ mm-modem-mbm.c \ mm-modem-mbm.h \ mm-plugin-mbm.c \ mm-plugin-mbm.h -mm-modem-gsm-mbm-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-mbm.xml - dbus-binding-tool --prefix=mm_modem_gsm_mbm --mode=glib-server --output=$@ $< - libmm_plugin_mbm_la_CPPFLAGS = \ $(MM_CFLAGS) \ -I$(top_srcdir)/src @@ -100,7 +96,6 @@ libmm_plugin_novatel_la_LDFLAGS = -module -avoid-version BUILT_SOURCES = \ - mm-modem-gsm-hso-glue.h \ - mm-modem-gsm-mbm-glue.h + mm-modem-gsm-hso-glue.h CLEANFILES = $(BUILT_SOURCES) diff --git a/plugins/mm-modem-hso.c b/plugins/mm-modem-hso.c index bd15e36a..bf901056 100644 --- a/plugins/mm-modem-hso.c +++ b/plugins/mm-modem-hso.c @@ -20,9 +20,6 @@ static void impl_hso_authenticate (MMModemHso *self, const char *password, DBusGMethodInvocation *context); -static void impl_hso_get_ip4_config (MMModemHso *self, - DBusGMethodInvocation *context); - #include "mm-modem-gsm-hso-glue.h" static gpointer mm_modem_hso_parent_class = NULL; @@ -30,7 +27,6 @@ static gpointer mm_modem_hso_parent_class = NULL; #define MM_MODEM_HSO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_HSO, MMModemHsoPrivate)) typedef struct { - char *network_device; GRegex *connection_enabled_regex; gpointer std_parser; @@ -39,13 +35,6 @@ typedef struct { guint connect_pending_id; } MMModemHsoPrivate; -enum { - PROP_0, - PROP_NETWORK_DEVICE, - - LAST_PROP -}; - #define OWANDATA_TAG "_OWANDATA: " MMModem * @@ -61,7 +50,9 @@ mm_modem_hso_new (const char *serial_device, MM_SERIAL_DEVICE, serial_device, MM_SERIAL_SEND_DELAY, (guint64) 10000, MM_MODEM_DRIVER, driver, - MM_MODEM_HSO_NETWORK_DEVICE, network_device, + MM_MODEM_DEVICE, network_device, + MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_STATIC, + MM_MODEM_TYPE, MM_MODEM_TYPE_GSM, NULL)); } @@ -217,6 +208,80 @@ mm_hso_modem_authenticate (MMModemHso *self, auth_done (MM_SERIAL (self), NULL, NULL, info); } +/*****************************************************************************/ + +static void +pin_check_done (MMModem *modem, GError *error, gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (error) + info->error = g_error_copy (error); + mm_callback_info_schedule (info); +} + +static void +parent_enable_done (MMModem *modem, GError *error, gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (error) { + info->error = g_error_copy (error); + mm_callback_info_schedule (info); + } else if (GPOINTER_TO_INT (mm_callback_info_get_data (info, "enable")) == FALSE) { + /* Disable, we're done */ + mm_callback_info_schedule (info); + } else { + /* HSO needs manual PIN checking */ + mm_generic_gsm_check_pin (MM_GENERIC_GSM (modem), pin_check_done, info); + } +} + +static void +modem_enable_done (MMSerial *serial, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModem *parent_modem_iface; + + parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (serial)); + parent_modem_iface->enable (MM_MODEM (serial), + GPOINTER_TO_INT (mm_callback_info_get_data (info, "enable")), + parent_enable_done, info); +} + +static void +enable (MMModem *modem, + gboolean enable, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + + info = mm_callback_info_new (modem, callback, user_data); + mm_callback_info_set_data (info, "enable", GINT_TO_POINTER (enable), NULL); + + if (enable) + modem_enable_done (MM_SERIAL (modem), NULL, NULL, info); + else + mm_serial_queue_command (MM_SERIAL (modem), "AT_OWANCALL=1,0,0", 3, modem_enable_done, info); +} + +static void +do_connect (MMModem *modem, + const char *number, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + + info = mm_callback_info_new (modem, callback, user_data); + mm_callback_info_schedule (info); +} + + static void free_dns_array (gpointer data) { @@ -226,9 +291,9 @@ free_dns_array (gpointer data) static void ip4_config_invoke (MMCallbackInfo *info) { - MMModemHsoIp4Fn callback = (MMModemHsoIp4Fn) info->callback; + MMModemIp4Fn callback = (MMModemIp4Fn) info->callback; - callback (MM_MODEM_HSO (info->modem), + callback (info->modem, GPOINTER_TO_UINT (mm_callback_info_get_data (info, "ip4-address")), (GArray *) mm_callback_info_get_data (info, "ip4-dns"), info->error, info->user_data); @@ -290,94 +355,29 @@ get_ip4_config_done (MMSerial *serial, mm_callback_info_schedule (info); } -void -mm_hso_modem_get_ip4_config (MMModemHso *self, - MMModemHsoIp4Fn callback, - gpointer user_data) +static void +get_ip4_config (MMModem *modem, + MMModemIp4Fn callback, + gpointer user_data) { MMCallbackInfo *info; char *command; - g_return_if_fail (MM_IS_MODEM_HSO (self)); - g_return_if_fail (callback != NULL); - - info = mm_callback_info_new_full (MM_MODEM (self), ip4_config_invoke, G_CALLBACK (callback), user_data); - command = g_strdup_printf ("AT_OWANDATA=%d", hso_get_cid (self)); - mm_serial_queue_command (MM_SERIAL (self), command, 3, get_ip4_config_done, info); + info = mm_callback_info_new_full (modem, ip4_config_invoke, G_CALLBACK (callback), user_data); + command = g_strdup_printf ("AT_OWANDATA=%d", hso_get_cid (MM_MODEM_HSO (modem))); + mm_serial_queue_command (MM_SERIAL (modem), command, 3, get_ip4_config_done, info); g_free (command); } -/*****************************************************************************/ - static void -pin_check_done (MMModem *modem, GError *error, gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - if (error) - info->error = g_error_copy (error); - mm_callback_info_schedule (info); -} - -static void -parent_enable_done (MMModem *modem, GError *error, gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - if (error) { - info->error = g_error_copy (error); - mm_callback_info_schedule (info); - } else if (GPOINTER_TO_INT (mm_callback_info_get_data (info, "enable")) == FALSE) { - /* Disable, we're done */ - mm_callback_info_schedule (info); - } else { - /* HSO needs manual PIN checking */ - mm_generic_gsm_check_pin (MM_GENERIC_GSM (modem), pin_check_done, info); - } -} - -static void -modem_enable_done (MMSerial *serial, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - MMModem *parent_modem_iface; - - parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (serial)); - parent_modem_iface->enable (MM_MODEM (serial), - GPOINTER_TO_INT (mm_callback_info_get_data (info, "enable")), - parent_enable_done, info); -} - -static void -enable (MMModem *modem, - gboolean enable, - MMModemFn callback, - gpointer user_data) -{ - MMCallbackInfo *info; - - info = mm_callback_info_new (modem, callback, user_data); - mm_callback_info_set_data (info, "enable", GINT_TO_POINTER (enable), NULL); - - if (enable) - modem_enable_done (MM_SERIAL (modem), NULL, NULL, info); - else - mm_serial_queue_command (MM_SERIAL (modem), "AT_OWANCALL=1,0,0", 3, modem_enable_done, info); -} - -static void -do_connect (MMModem *modem, - const char *number, +disconnect (MMModem *modem, MMModemFn callback, gpointer user_data) { MMCallbackInfo *info; info = mm_callback_info_new (modem, callback, user_data); - mm_callback_info_schedule (info); + mm_serial_queue_command (MM_SERIAL (modem), "AT_OWANCALL=1,0,0", 3, NULL, info); } /*****************************************************************************/ @@ -411,28 +411,6 @@ impl_hso_authenticate (MMModemHso *self, } static void -impl_hso_ip4_config_done (MMModemHso *modem, - guint32 address, - GArray *dns, - GError *error, - gpointer user_data) -{ - DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data; - - if (error) - dbus_g_method_return_error (context, error); - else - dbus_g_method_return (context, address, dns); -} - -static void -impl_hso_get_ip4_config (MMModemHso *self, - DBusGMethodInvocation *context) -{ - mm_hso_modem_get_ip4_config (self, impl_hso_ip4_config_done, context); -} - -static void connection_enabled (const char *str, gpointer data) { if (str && strlen (str) == 4) { @@ -566,6 +544,8 @@ modem_init (MMModem *modem_class) { modem_class->enable = enable; modem_class->connect = do_connect; + modem_class->get_ip4_config = get_ip4_config; + modem_class->disconnect = disconnect; } static GObject* @@ -574,7 +554,8 @@ constructor (GType type, GObjectConstructParam *construct_params) { GObject *object; - MMModemHsoPrivate *priv; + char *modem_device; + char *serial_device; object = G_OBJECT_CLASS (mm_modem_hso_parent_class)->constructor (type, n_construct_params, @@ -582,50 +563,25 @@ constructor (GType type, if (!object) return NULL; - priv = MM_MODEM_HSO_GET_PRIVATE (object); + /* Make sure both serial device and data device are provided */ + g_object_get (object, + MM_MODEM_DEVICE, &modem_device, + MM_SERIAL_DEVICE, &serial_device, + NULL); - if (!priv->network_device) { + if (!modem_device || !serial_device || !strcmp (modem_device, serial_device)) { g_warning ("No network device provided"); g_object_unref (object); - return NULL; + object = NULL; } - return object; -} + g_free (modem_device); + g_free (serial_device); -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_NETWORK_DEVICE: - /* Construct only */ - priv->network_device = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + return object; } static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_NETWORK_DEVICE: - g_value_set_string (value, priv->network_device); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} -static void finalize (GObject *object) { MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (object); @@ -633,7 +589,6 @@ finalize (GObject *object) /* Clear the pending connection if necessary */ connect_pending_done (MM_MODEM_HSO (object)); - g_free (priv->network_device); g_regex_unref (priv->connection_enabled_regex); mm_serial_parser_v1_destroy (priv->std_parser); @@ -650,17 +605,7 @@ mm_modem_hso_class_init (MMModemHsoClass *klass) /* Virtual methods */ object_class->constructor = constructor; - object_class->set_property = set_property; - object_class->get_property = get_property; object_class->finalize = finalize; - /* Properties */ - g_object_class_install_property - (object_class, PROP_NETWORK_DEVICE, - g_param_spec_string (MM_MODEM_HSO_NETWORK_DEVICE, - "NetworkDevice", - "Network device", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } GType diff --git a/plugins/mm-modem-hso.h b/plugins/mm-modem-hso.h index 343b0fed..8780ee1a 100644 --- a/plugins/mm-modem-hso.h +++ b/plugins/mm-modem-hso.h @@ -12,8 +12,6 @@ #define MM_IS_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_HSO)) #define MM_MODEM_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_HSO, MMModemHsoClass)) -#define MM_MODEM_HSO_NETWORK_DEVICE "network-device" - typedef struct { MMGenericGsm parent; } MMModemHso; @@ -22,13 +20,6 @@ typedef struct { MMGenericGsmClass parent; } MMModemHsoClass; -typedef void (*MMModemHsoIp4Fn) (MMModemHso *modem, - guint32 address, - GArray *dns, - GError *error, - gpointer user_data); - - GType mm_modem_hso_get_type (void); MMModem *mm_modem_hso_new (const char *serial_device, @@ -41,9 +32,4 @@ void mm_hso_modem_authenticate (MMModemHso *self, MMModemFn callback, gpointer user_data); -void mm_hso_modem_get_ip4_config (MMModemHso *self, - MMModemHsoIp4Fn callback, - gpointer user_data); - - #endif /* MM_MODEM_HSO_H */ diff --git a/plugins/mm-modem-huawei.c b/plugins/mm-modem-huawei.c index 4f0ae36b..d503d17e 100644 --- a/plugins/mm-modem-huawei.c +++ b/plugins/mm-modem-huawei.c @@ -47,8 +47,9 @@ mm_modem_huawei_new (const char *data_device, return MM_MODEM (g_object_new (MM_TYPE_MODEM_HUAWEI, MM_SERIAL_DEVICE, monitor_device, - MM_MODEM_DATA_DEVICE, data_device, + MM_MODEM_DEVICE, data_device, MM_MODEM_DRIVER, driver, + MM_MODEM_TYPE, MM_MODEM_TYPE_GSM, NULL)); } diff --git a/plugins/mm-modem-mbm.c b/plugins/mm-modem-mbm.c index 10415bcc..74b96b9c 100644 --- a/plugins/mm-modem-mbm.c +++ b/plugins/mm-modem-mbm.c @@ -48,7 +48,6 @@ static gpointer mm_modem_mbm_parent_class = NULL; #define MM_MODEM_MBM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_MBM, MMModemMbmPrivate)) typedef struct { - char *network_device; GRegex *boot_trig_regex; GRegex *msg_waiting_regex; GRegex *ciev_regex; @@ -56,13 +55,6 @@ typedef struct { guint32 signal_quality; } MMModemMbmPrivate; -enum { - PROP_0, - PROP_NETWORK_DEVICE, - - LAST_PROP -}; - MMModem * mm_modem_mbm_new (const char *serial_device, const char *network_device, @@ -76,7 +68,9 @@ mm_modem_mbm_new (const char *serial_device, MM_SERIAL_DEVICE, serial_device, MM_SERIAL_SEND_DELAY, (guint64) 10000, MM_MODEM_DRIVER, driver, - MM_MODEM_MBM_NETWORK_DEVICE, network_device, + MM_MODEM_DEVICE, network_device, + MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_DHCP, + MM_MODEM_TYPE, MM_MODEM_TYPE_GSM, NULL)); } @@ -460,7 +454,8 @@ constructor (GType type, GObjectConstructParam *construct_params) { GObject *object; - MMModemMbmPrivate *priv; + char *modem_device; + char *serial_device; object = G_OBJECT_CLASS (mm_modem_mbm_parent_class)->constructor (type, n_construct_params, @@ -468,55 +463,29 @@ constructor (GType type, if (!object) return NULL; - priv = MM_MODEM_MBM_GET_PRIVATE (object); + /* Make sure both serial device and data device are provided */ + g_object_get (object, + MM_MODEM_DEVICE, &modem_device, + MM_SERIAL_DEVICE, &serial_device, + NULL); - if (!priv->network_device) { + if (!modem_device || !serial_device || !strcmp (modem_device, serial_device)) { g_warning ("No network device provided"); g_object_unref (object); - return NULL; + object = NULL; } - return object; -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (object); + g_free (modem_device); + g_free (serial_device); - switch (prop_id) { - case PROP_NETWORK_DEVICE: - /* Construct only */ - priv->network_device = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } + return object; } static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_NETWORK_DEVICE: - g_value_set_string (value, priv->network_device); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} -static void finalize (GObject *object) { MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (object); - g_free (priv->network_device); mm_serial_parser_v1_destroy (priv->std_parser); g_regex_unref (priv->boot_trig_regex); g_regex_unref (priv->msg_waiting_regex); @@ -535,17 +504,7 @@ mm_modem_mbm_class_init (MMModemMbmClass *klass) /* Virtual methods */ object_class->constructor = constructor; - object_class->set_property = set_property; - object_class->get_property = get_property; object_class->finalize = finalize; - /* Properties */ - g_object_class_install_property - (object_class, PROP_NETWORK_DEVICE, - g_param_spec_string (MM_MODEM_MBM_NETWORK_DEVICE, - "NetworkDevice", - "Network device", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } GType diff --git a/plugins/mm-modem-mbm.h b/plugins/mm-modem-mbm.h index a165d899..9a26f1a3 100644 --- a/plugins/mm-modem-mbm.h +++ b/plugins/mm-modem-mbm.h @@ -35,8 +35,6 @@ #define MM_IS_MODEM_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_MBM)) #define MM_MODEM_MBM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_MBM, MMModemMbmClass)) -#define MM_MODEM_MBM_NETWORK_DEVICE "network-device" - typedef struct { MMGenericGsm parent; } MMModemMbm; @@ -45,27 +43,10 @@ typedef struct { MMGenericGsmClass parent; } MMModemMbmClass; -typedef void (*MMModemMbmIp4Fn) (MMModemMbm *modem, - guint32 address, - GArray *dns, - GError *error, - gpointer user_data); - - GType mm_modem_mbm_get_type (void); MMModem *mm_modem_mbm_new (const char *serial_device, const char *network_device, const char *driver); -void mm_mbm_modem_authenticate (MMModemMbm *self, - const char *username, - const char *password, - MMModemFn callback, - gpointer user_data); - -void mm_mbm_modem_get_ip4_config (MMModemMbm *self, - MMModemMbmIp4Fn callback, - gpointer user_data); - #endif /* MM_MODEM_MBM_H */ diff --git a/plugins/mm-modem-novatel.c b/plugins/mm-modem-novatel.c index 8260d692..00188fd3 100644 --- a/plugins/mm-modem-novatel.c +++ b/plugins/mm-modem-novatel.c @@ -20,6 +20,7 @@ mm_modem_novatel_new (const char *data_device, return MM_MODEM (g_object_new (MM_TYPE_MODEM_NOVATEL, MM_SERIAL_DEVICE, data_device, MM_MODEM_DRIVER, driver, + MM_MODEM_TYPE, MM_MODEM_TYPE_GSM, NULL)); } @@ -51,7 +52,7 @@ pin_check_done (MMModem *modem, GError *error, gpointer user_data) mm_callback_info_schedule (info); } else /* Finish the initialization */ - mm_serial_queue_command (MM_SERIAL (modem), "Z X4 &C1 +CMEE=1;+CFUN=1", 10, init_modem_done, info); + mm_serial_queue_command (MM_SERIAL (modem), "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1", 10, init_modem_done, info); } static void diff --git a/plugins/mm-modem-option.c b/plugins/mm-modem-option.c index f5bf4fc9..c09d1df4 100644 --- a/plugins/mm-modem-option.c +++ b/plugins/mm-modem-option.c @@ -20,6 +20,7 @@ mm_modem_option_new (const char *data_device, return MM_MODEM (g_object_new (MM_TYPE_MODEM_OPTION, MM_SERIAL_DEVICE, data_device, MM_MODEM_DRIVER, driver, + MM_MODEM_TYPE, MM_MODEM_TYPE_GSM, NULL)); } diff --git a/plugins/mm-modem-sierra.c b/plugins/mm-modem-sierra.c index cb5b92c0..4b5389a5 100644 --- a/plugins/mm-modem-sierra.c +++ b/plugins/mm-modem-sierra.c @@ -20,6 +20,7 @@ mm_modem_sierra_new (const char *data_device, return MM_MODEM (g_object_new (MM_TYPE_MODEM_SIERRA, MM_SERIAL_DEVICE, data_device, MM_MODEM_DRIVER, driver, + MM_MODEM_TYPE, MM_MODEM_TYPE_GSM, NULL)); } diff --git a/src/mm-generic-cdma.c b/src/mm-generic-cdma.c index 6701e407..eb9e25b0 100644 --- a/src/mm-generic-cdma.c +++ b/src/mm-generic-cdma.c @@ -27,6 +27,7 @@ mm_generic_cdma_new (const char *serial_device, const char *driver) return MM_MODEM (g_object_new (MM_TYPE_GENERIC_CDMA, MM_SERIAL_DEVICE, serial_device, MM_MODEM_DRIVER, driver, + MM_MODEM_TYPE, MM_MODEM_TYPE_CDMA, NULL)); } @@ -375,8 +376,9 @@ set_property (GObject *object, guint prop_id, /* Construct only */ MM_GENERIC_CDMA_GET_PRIVATE (object)->driver = g_value_dup_string (value); break; - case MM_MODEM_PROP_DATA_DEVICE: + case MM_MODEM_PROP_DEVICE: case MM_MODEM_PROP_TYPE: + case MM_MODEM_PROP_IP_METHOD: break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -389,7 +391,7 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { switch (prop_id) { - case MM_MODEM_PROP_DATA_DEVICE: + case MM_MODEM_PROP_DEVICE: g_value_set_string (value, mm_serial_get_device (MM_SERIAL (object))); break; case MM_MODEM_PROP_DRIVER: @@ -398,6 +400,9 @@ get_property (GObject *object, guint prop_id, case MM_MODEM_PROP_TYPE: g_value_set_uint (value, MM_MODEM_TYPE_CDMA); break; + case MM_MODEM_PROP_IP_METHOD: + g_value_set_uint (value, MM_MODEM_IP_METHOD_PPP); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -429,8 +434,8 @@ mm_generic_cdma_class_init (MMGenericCdmaClass *klass) /* Properties */ g_object_class_override_property (object_class, - MM_MODEM_PROP_DATA_DEVICE, - MM_MODEM_DATA_DEVICE); + MM_MODEM_PROP_DEVICE, + MM_MODEM_DEVICE); g_object_class_override_property (object_class, MM_MODEM_PROP_DRIVER, @@ -439,6 +444,10 @@ mm_generic_cdma_class_init (MMGenericCdmaClass *klass) g_object_class_override_property (object_class, MM_MODEM_PROP_TYPE, MM_MODEM_TYPE); + + g_object_class_override_property (object_class, + MM_MODEM_PROP_IP_METHOD, + MM_MODEM_IP_METHOD); } GType diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index 56002648..b4475cdc 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -20,6 +20,8 @@ typedef struct { char *data_device; char *oper_code; char *oper_name; + guint32 modem_type; + guint32 ip_method; MMModemGsmNetworkRegStatus reg_status; guint32 signal_quality; guint32 cid; @@ -40,6 +42,7 @@ mm_generic_gsm_new (const char *serial_device, const char *driver) return MM_MODEM (g_object_new (MM_TYPE_GENERIC_GSM, MM_SERIAL_DEVICE, serial_device, MM_MODEM_DRIVER, driver, + MM_MODEM_TYPE, MM_MODEM_TYPE_GSM, NULL)); } @@ -1121,9 +1124,10 @@ simple_state_machine (MMModem *modem, GError *error, gpointer user_data) gboolean need_pin = FALSE; if (error) { - if (state == SIMPLE_STATE_CHECK_PIN && g_error_matches (error, MM_MOBILE_ERROR, MM_MOBILE_ERROR_SIM_PIN)) + if (state == g_error_matches (error, MM_MOBILE_ERROR, MM_MOBILE_ERROR_SIM_PIN)) { need_pin = TRUE; - else { + state = SIMPLE_STATE_CHECK_PIN; + } else { info->error = g_error_copy (error); goto out; } @@ -1379,11 +1383,15 @@ set_property (GObject *object, guint prop_id, /* Construct only */ priv->driver = g_value_dup_string (value); break; - case MM_MODEM_PROP_DATA_DEVICE: + case MM_MODEM_PROP_DEVICE: g_free (priv->data_device); priv->data_device = g_value_dup_string (value); break; case MM_MODEM_PROP_TYPE: + priv->modem_type = g_value_get_uint (value); + break; + case MM_MODEM_PROP_IP_METHOD: + priv->ip_method = g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1398,7 +1406,7 @@ get_property (GObject *object, guint prop_id, MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (object); switch (prop_id) { - case MM_MODEM_PROP_DATA_DEVICE: + case MM_MODEM_PROP_DEVICE: if (priv->data_device) g_value_set_string (value, priv->data_device); else @@ -1408,7 +1416,10 @@ get_property (GObject *object, guint prop_id, g_value_set_string (value, MM_GENERIC_GSM_GET_PRIVATE (object)->driver); break; case MM_MODEM_PROP_TYPE: - g_value_set_uint (value, MM_MODEM_TYPE_GSM); + g_value_set_uint (value, priv->modem_type); + break; + case MM_MODEM_PROP_IP_METHOD: + g_value_set_uint (value, priv->ip_method); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1444,8 +1455,8 @@ mm_generic_gsm_class_init (MMGenericGsmClass *klass) /* Properties */ g_object_class_override_property (object_class, - MM_MODEM_PROP_DATA_DEVICE, - MM_MODEM_DATA_DEVICE); + MM_MODEM_PROP_DEVICE, + MM_MODEM_DEVICE); g_object_class_override_property (object_class, MM_MODEM_PROP_DRIVER, @@ -1454,6 +1465,11 @@ mm_generic_gsm_class_init (MMGenericGsmClass *klass) g_object_class_override_property (object_class, MM_MODEM_PROP_TYPE, MM_MODEM_TYPE); + + g_object_class_override_property (object_class, + MM_MODEM_PROP_IP_METHOD, + MM_MODEM_IP_METHOD); + } GType diff --git a/src/mm-modem.c b/src/mm-modem.c index 88afd9c2..7bf913ec 100644 --- a/src/mm-modem.c +++ b/src/mm-modem.c @@ -9,6 +9,7 @@ static void impl_modem_enable (MMModem *modem, gboolean enable, DBusGMethodInvocation *context); 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); #include "mm-modem-glue.h" @@ -83,6 +84,97 @@ impl_modem_connect (MMModem *modem, mm_modem_connect (modem, number, async_call_done, context); } +static void +get_ip4_invoke (MMCallbackInfo *info) +{ + MMModemIp4Fn callback = (MMModemIp4Fn) info->callback; + + callback (info->modem, + GPOINTER_TO_UINT (mm_callback_info_get_data (info, "ip4-address")), + (GArray *) mm_callback_info_get_data (info, "ip4-dns"), + info->error, info->user_data); +} + +void +mm_modem_get_ip4_config (MMModem *self, + MMModemIp4Fn 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_ip4_config) + MM_MODEM_GET_INTERFACE (self)->get_ip4_config (self, callback, user_data); + else { + MMCallbackInfo *info; + + info = mm_callback_info_new_full (self, + get_ip4_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 +value_array_add_uint (GValueArray *array, guint32 i) +{ + GValue value = { 0, }; + + g_value_init (&value, G_TYPE_UINT); + g_value_set_uint (&value, i); + g_value_array_append (array, &value); + g_value_unset (&value); +} + +static void +get_ip4_done (MMModem *modem, + guint32 address, + GArray *dns, + GError *error, + gpointer user_data) +{ + DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data; + + if (error) + dbus_g_method_return_error (context, error); + else { + GValueArray *array; + guint32 dns1 = 0; + guint32 dns2 = 0; + guint32 dns3 = 0; + + array = g_value_array_new (4); + + if (dns) { + if (dns->len > 0) + + dns1 = g_array_index (dns, guint32, 0); + if (dns->len > 1) + dns2 = g_array_index (dns, guint32, 1); + if (dns->len > 2) + dns3 = g_array_index (dns, guint32, 2); + } + + value_array_add_uint (array, address); + value_array_add_uint (array, dns1); + value_array_add_uint (array, dns2); + value_array_add_uint (array, dns3); + + dbus_g_method_return (context, array); + } +} + +static void +impl_modem_get_ip4_config (MMModem *modem, + DBusGMethodInvocation *context) +{ + mm_modem_get_ip4_config (modem, get_ip4_done, context); +} + void mm_modem_disconnect (MMModem *self, MMModemFn callback, @@ -118,9 +210,9 @@ mm_modem_init (gpointer g_iface) /* Properties */ g_object_interface_install_property (g_iface, - g_param_spec_string (MM_MODEM_DATA_DEVICE, - "DataDevice", - "DataDevice", + g_param_spec_string (MM_MODEM_DEVICE, + "Device", + "Device", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); @@ -140,6 +232,16 @@ mm_modem_init (gpointer g_iface) 0, G_MAXUINT32, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_interface_install_property + (g_iface, + g_param_spec_uint (MM_MODEM_IP_METHOD, + "IP method", + "IP configuration method", + MM_MODEM_IP_METHOD_PPP, + MM_MODEM_IP_METHOD_DHCP, + MM_MODEM_IP_METHOD_PPP, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + initialized = TRUE; } diff --git a/src/mm-modem.h b/src/mm-modem.h index fdcce25b..914b86a3 100644 --- a/src/mm-modem.h +++ b/src/mm-modem.h @@ -10,19 +10,25 @@ #define MM_IS_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM)) #define MM_MODEM_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM, MMModem)) -#define MM_MODEM_DATA_DEVICE "data-device" -#define MM_MODEM_DRIVER "driver" -#define MM_MODEM_TYPE "type" +#define MM_MODEM_DEVICE "device" +#define MM_MODEM_DRIVER "driver" +#define MM_MODEM_TYPE "type" +#define MM_MODEM_IP_METHOD "ip-method" #define MM_MODEM_TYPE_GSM 1 #define MM_MODEM_TYPE_CDMA 2 +#define MM_MODEM_IP_METHOD_PPP 0 +#define MM_MODEM_IP_METHOD_STATIC 1 +#define MM_MODEM_IP_METHOD_DHCP 2 + typedef enum { MM_MODEM_PROP_FIRST = 0x1000, - MM_MODEM_PROP_DATA_DEVICE = MM_MODEM_PROP_FIRST, + MM_MODEM_PROP_DEVICE = MM_MODEM_PROP_FIRST, MM_MODEM_PROP_DRIVER, - MM_MODEM_PROP_TYPE + MM_MODEM_PROP_TYPE, + MM_MODEM_PROP_IP_METHOD, } MMModemProp; typedef struct _MMModem MMModem; @@ -41,6 +47,12 @@ typedef void (*MMModemStringFn) (MMModem *modem, GError *error, gpointer user_data); +typedef void (*MMModemIp4Fn) (MMModem *modem, + guint32 address, + GArray *dns, + GError *error, + gpointer user_data); + struct _MMModem { GTypeInterface g_iface; @@ -55,6 +67,10 @@ struct _MMModem { MMModemFn callback, gpointer user_data); + void (*get_ip4_config) (MMModem *self, + MMModemIp4Fn callback, + gpointer user_data); + void (*disconnect) (MMModem *self, MMModemFn callback, gpointer user_data); @@ -72,6 +88,10 @@ void mm_modem_connect (MMModem *self, MMModemFn callback, gpointer user_data); +void mm_modem_get_ip4_config (MMModem *self, + MMModemIp4Fn callback, + gpointer user_data); + void mm_modem_disconnect (MMModem *self, MMModemFn callback, gpointer user_data); diff --git a/src/mm-serial.h b/src/mm-serial.h index eeaac9c1..7d9e6961 100644 --- a/src/mm-serial.h +++ b/src/mm-serial.h @@ -13,7 +13,7 @@ #define MM_IS_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_SERIAL)) #define MM_SERIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_SERIAL, MMSerialClass)) -#define MM_SERIAL_DEVICE "device" +#define MM_SERIAL_DEVICE "serial-device" #define MM_SERIAL_BAUD "baud" #define MM_SERIAL_BITS "bits" #define MM_SERIAL_PARITY "parity" |