diff options
-rw-r--r-- | introspection/Makefile.am | 2 | ||||
-rw-r--r-- | introspection/all.xml | 1 | ||||
-rw-r--r-- | introspection/mm-modem-gsm-hso.xml (renamed from introspection/mm-gsm-modem-hso.xml) | 29 | ||||
-rw-r--r-- | plugins/Makefile.am | 8 | ||||
-rw-r--r-- | plugins/mm-modem-hso.c | 248 |
5 files changed, 126 insertions, 162 deletions
diff --git a/introspection/Makefile.am b/introspection/Makefile.am index 612311c6..d318088a 100644 --- a/introspection/Makefile.am +++ b/introspection/Makefile.am @@ -1,10 +1,10 @@ EXTRA_DIST = \ - mm-gsm-modem-hso.xml \ mm-manager.xml \ mm-modem.xml \ mm-modem-cdma.xml \ mm-modem-gsm-card.xml \ mm-modem-gsm-contacts.xml \ + mm-modem-gsm-hso.xml \ mm-modem-gsm-network.xml \ mm-modem-gsm-sms.xml diff --git a/introspection/all.xml b/introspection/all.xml index 6a04900e..940ae598 100644 --- a/introspection/all.xml +++ b/introspection/all.xml @@ -29,4 +29,5 @@ <xi:include href="mm-modem-gsm-contacts.xml"/> <xi:include href="mm-modem-gsm-network.xml"/> <xi:include href="mm-modem-gsm-sms.xml"/> + <xi:include href="mm-modem-gsm-hso.xml"/> </tp:spec> diff --git a/introspection/mm-gsm-modem-hso.xml b/introspection/mm-modem-gsm-hso.xml index d994ca64..bb631c07 100644 --- a/introspection/mm-gsm-modem-hso.xml +++ b/introspection/mm-modem-gsm-hso.xml @@ -1,22 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> - <interface name="org.freedesktop.ModemManager.Modem.Gsm.Hso"> - <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> - <method name="Authenticate"> <tp:docstring> Authenticate using the passed user name and password. @@ -31,6 +16,20 @@ </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. diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 9236685c..ea67db03 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -19,14 +19,14 @@ libmm_plugin_huawei_la_LDFLAGS = -module -avoid-version # HSO libmm_plugin_hso_la_SOURCES = \ - mm-gsm-modem-hso-glue.h \ + mm-modem-gsm-hso-glue.h \ mm-modem-hso.c \ mm-modem-hso.h \ mm-plugin-hso.c \ mm-plugin-hso.h -mm-gsm-modem-hso-glue.h: $(top_srcdir)/introspection/mm-gsm-modem-hso.xml - dbus-binding-tool --prefix=mm_gsm_modem_hso --mode=glib-server --output=$@ $< +mm-modem-gsm-hso-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-hso.xml + dbus-binding-tool --prefix=mm_modem_gsm_hso --mode=glib-server --output=$@ $< libmm_plugin_hso_la_CPPFLAGS = \ $(MM_CFLAGS) \ @@ -35,6 +35,6 @@ libmm_plugin_hso_la_CPPFLAGS = \ libmm_plugin_hso_la_LDFLAGS = -module -avoid-version BUILT_SOURCES = \ - mm-gsm-modem-hso-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 8e6d239b..ca00a634 100644 --- a/plugins/mm-modem-hso.c +++ b/plugins/mm-modem-hso.c @@ -12,13 +12,15 @@ #include "mm-modem-error.h" #include "mm-callback-info.h" -static void impl_hso_get_ip4_config (MMModemHso *self, DBusGMethodInvocation *context); static void impl_hso_authenticate (MMModemHso *self, const char *username, const char *password, DBusGMethodInvocation *context); -#include "mm-gsm-modem-hso-glue.h" +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; @@ -54,104 +56,128 @@ mm_modem_hso_new (const char *serial_device, NULL)); } -/*****************************************************************************/ - static void -need_auth_done (MMModem *modem, GError *error, gpointer user_data) +hso_enable_done (MMSerial *serial, + int reply_index, + gpointer user_data) { MMCallbackInfo *info = (MMCallbackInfo *) user_data; - MMModemFn callback; - if (!MM_MODEM_HSO_GET_PRIVATE (modem)->authenticated) - /* Re-use the PIN_NEEDED error as HSO never needs PIN or PUK, right? */ - error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_PIN_NEEDED, "%s", "Authentication needed."); + switch (reply_index) { + case 0: + /* Success */ + break; + default: + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Enable/Disable failed."); + break; + } - callback = mm_callback_info_get_data (info, "callback"); - callback (MM_MODEM (modem), - error, - mm_callback_info_get_data (info, "user-data")); + mm_callback_info_schedule (info); } static void -need_auth (MMModem *modem, - MMModemFn callback, - gpointer user_data) +hso_enable (MMModemHso *self, + gboolean enabled, + MMModemFn callback, + gpointer user_data) { MMCallbackInfo *info; + char *command; + char *responses[] = { "_OWANCALL: ", "ERROR", "NO CARRIER", NULL }; + guint id = 0; - info = mm_callback_info_new (modem, need_auth_done, NULL); - info->user_data = info; - mm_callback_info_set_data (info, "callback", callback, NULL); - mm_callback_info_set_data (info, "user-data", user_data, NULL); + info = mm_callback_info_new (MM_MODEM (self), callback, user_data); - mm_callback_info_schedule (info); + command = g_strdup_printf ("AT_OWANCALL=%d,%d,1", + mm_generic_gsm_get_cid (MM_GENERIC_GSM (self)), + enabled ? 1 : 0); + + if (mm_serial_send_command_string (MM_SERIAL (self), command)) + id = mm_serial_wait_for_reply (MM_SERIAL (self), 5, responses, responses, hso_enable_done, user_data); + + g_free (command); + + if (!id) { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Enable/Disable failed."); + mm_callback_info_schedule (info); + } } static void -call_done (MMSerial *serial, - int reply_index, - gpointer user_data) +hso_enabled (MMModem *modem, + GError *error, + gpointer user_data) { MMCallbackInfo *info = (MMCallbackInfo *) user_data; - switch (reply_index) { - case 0: - /* Success */ - break; - default: - info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Dial failed."); - break; - } - + if (error) + info->error = g_error_copy (error); + mm_callback_info_schedule (info); } static void -clear_done (MMSerial *serial, - int reply_index, - gpointer user_data) +hso_disabled (MMModem *modem, + GError *error, + gpointer user_data) { MMCallbackInfo *info = (MMCallbackInfo *) user_data; - char *command; - char *responses[] = { "_OWANCALL: ", "ERROR", NULL }; - guint id = 0; - /* FIXME: Ignore errors here? */ - /* Try to connect */ - command = g_strdup_printf ("AT_OWANCALL=%d,1,1", mm_generic_gsm_get_cid (MM_GENERIC_GSM (serial))); - if (mm_serial_send_command_string (serial, command)) - id = mm_serial_wait_for_reply (serial, 10, responses, responses, call_done, user_data); + if (error) { + info->error = g_error_copy (error); + mm_callback_info_schedule (info); + } else + hso_enable (MM_MODEM_HSO (modem), TRUE, hso_enabled, info); +} - g_free (command); +static void +auth_done (MMSerial *serial, + int reply_index, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; - if (!id) { - info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Dial failed."); - mm_callback_info_schedule (info); + switch (reply_index) { + case 0: + /* success, kill any existing connections first */ + hso_enable (MM_MODEM_HSO (serial), FALSE, hso_disabled, info); + break; + default: + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Authentication failed"); + break; } + + mm_callback_info_schedule (info); } -static void -do_connect (MMModem *modem, - const char *number, - MMModemFn callback, - gpointer user_data) +void +mm_hso_modem_authenticate (MMModemHso *self, + const char *username, + const char *password, + MMModemFn callback, + gpointer user_data) { MMCallbackInfo *info; char *command; - char *responses[] = { "_OWANCALL: ", "ERROR", "NO CARRIER", NULL }; + char *responses[] = { "OK", "ERROR", NULL }; guint id = 0; - info = mm_callback_info_new (modem, callback, user_data); + g_return_if_fail (MM_IS_MODEM_HSO (self)); + g_return_if_fail (callback != NULL); + + info = mm_callback_info_new (MM_MODEM (self), callback, user_data); + command = g_strdup_printf ("AT$QCPDPP=%d,1,\"%s\",\"%s\"", + mm_generic_gsm_get_cid (MM_GENERIC_GSM (self)), + password ? password : "", + username ? username : ""); - /* Kill any existing connection first */ - command = g_strdup_printf ("AT_OWANCALL=%d,0,1", mm_generic_gsm_get_cid (MM_GENERIC_GSM (modem))); - if (mm_serial_send_command_string (MM_SERIAL (modem), command)) - id = mm_serial_wait_for_reply (MM_SERIAL (modem), 5, responses, responses, clear_done, user_data); + if (mm_serial_send_command_string (MM_SERIAL (self), command)) + id = mm_serial_wait_for_reply (MM_SERIAL (self), 5, responses, responses, auth_done, user_data); g_free (command); if (!id) { - info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Dial failed."); + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Authentication failed."); mm_callback_info_schedule (info); } } @@ -258,100 +284,50 @@ mm_hso_modem_get_ip4_config (MMModemHso *self, } } +/*****************************************************************************/ + static void -impl_hso_ip4_config_done (MMModemHso *modem, - guint32 address, - GArray *dns, - GError *error, - gpointer user_data) +impl_hso_auth_done (MMModem *modem, + 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); + dbus_g_method_return (context); } static void -auth_done (MMSerial *serial, - int reply_index, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - switch (reply_index) { - case 0: - /* success */ - MM_MODEM_HSO_GET_PRIVATE (serial)->authenticated = TRUE; - break; - default: - info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Authentication failed"); - break; - } - - mm_callback_info_schedule (info); -} - -void -mm_hso_modem_authenticate (MMModemHso *self, - const char *username, - const char *password, - MMModemFn callback, - gpointer user_data) +impl_hso_authenticate (MMModemHso *self, + const char *username, + const char *password, + DBusGMethodInvocation *context) { - MMCallbackInfo *info; - char *command; - char *responses[] = { "OK", "ERROR", NULL }; - guint id = 0; - - g_return_if_fail (MM_IS_MODEM_HSO (self)); - g_return_if_fail (callback != NULL); - - info = mm_callback_info_new (MM_MODEM (self), callback, user_data); - command = g_strdup_printf ("AT$QCPDPP=%d,1,\"%s\",\"%s\"", - mm_generic_gsm_get_cid (MM_GENERIC_GSM (self)), - password ? password : "", - username ? username : ""); - - if (mm_serial_send_command_string (MM_SERIAL (self), command)) - id = mm_serial_wait_for_reply (MM_SERIAL (self), 5, responses, responses, auth_done, user_data); - - g_free (command); - - if (!id) { - info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Authentication failed."); - mm_callback_info_schedule (info); - } + mm_hso_modem_authenticate (self, username, password, impl_hso_auth_done, context); } static void -impl_hso_auth_done (MMModem *modem, - GError *error, - gpointer user_data) +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); + dbus_g_method_return (context, address, dns); } static void -impl_hso_authenticate (MMModemHso *self, - const char *username, - const char *password, - DBusGMethodInvocation *context) +impl_hso_get_ip4_config (MMModemHso *self, + DBusGMethodInvocation *context) { - mm_hso_modem_authenticate (self, username, password, impl_hso_auth_done, context); + mm_hso_modem_get_ip4_config (self, impl_hso_ip4_config_done, context); } /*****************************************************************************/ @@ -361,12 +337,6 @@ mm_modem_hso_init (MMModemHso *self) { } -static void -modem_init (MMModem *modem_class) -{ - modem_class->connect = do_connect; -} - static GObject* constructor (GType type, guint n_construct_params, @@ -475,13 +445,7 @@ mm_modem_hso_get_type (void) (GInstanceInitFunc) mm_modem_hso_init, }; - static const GInterfaceInfo modem_iface_info = { - (GInterfaceInitFunc) modem_init - }; - modem_hso_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemHso", &modem_hso_type_info, 0); - - g_type_add_interface_static (modem_hso_type, MM_TYPE_MODEM, &modem_iface_info); } return modem_hso_type; |