diff options
-rw-r--r-- | plugins/Makefile.am | 20 | ||||
-rw-r--r-- | plugins/mm-modem-hso.c | 816 | ||||
-rw-r--r-- | plugins/mm-modem-hso.h | 51 | ||||
-rw-r--r-- | plugins/mm-modem-option-utils.c | 561 | ||||
-rw-r--r-- | plugins/mm-modem-option.c | 237 | ||||
-rw-r--r-- | plugins/mm-modem-option.h | 45 | ||||
-rw-r--r-- | plugins/mm-plugin-hso.c | 206 | ||||
-rw-r--r-- | plugins/mm-plugin-hso.h | 43 | ||||
-rw-r--r-- | plugins/mm-plugin-option.c | 184 |
9 files changed, 0 insertions, 2163 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index c5948901..a5114cd3 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -46,8 +46,6 @@ pkglib_LTLIBRARIES = \ # libmm-plugin-generic.la \ # libmm-plugin-moto-c.la \ # libmm-plugin-huawei.la \ -# libmm-plugin-hso.la \ -# libmm-plugin-option.la \ # libmm-plugin-sierra.la \ # libmm-plugin-novatel.la \ # libmm-plugin-nokia.la \ @@ -99,19 +97,6 @@ libmm_plugin_gobi_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) #libmm_plugin_huawei_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) #libmm_plugin_huawei_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) # -## HSO -#libmm_plugin_hso_la_SOURCES = \ -# mm-plugin-hso.c \ -# mm-plugin-hso.h \ -# mm-modem-gsm-hso-glue.h \ -# mm-modem-hso.c \ -# mm-modem-hso.h -#libmm_plugin_hso_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -#libmm_plugin_hso_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -# -#mm-modem-gsm-hso-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManager.Modem.Gsm.Hso.xml -# $(AM_V_GEN) dbus-binding-tool --prefix=mm_modem_gsm_hso --mode=glib-server --output=$@ $< -# ## MBM #libmm_plugin_mbm_la_SOURCES = \ # mm-plugin-mbm.c \ @@ -298,11 +283,6 @@ libmm_plugin_novatel_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) # 77-mm-simtech-port-types.rules \ # 77-mm-x22x-port-types.rules \ # -#BUILT_SOURCES = \ -# mm-modem-gsm-hso-glue.h -# -#CLEANFILES = $(BUILT_SOURCES) -# # Additional files to include in the distribution EXTRA_DIST = \ diff --git a/plugins/mm-modem-hso.c b/plugins/mm-modem-hso.c deleted file mode 100644 index 1b007fcf..00000000 --- a/plugins/mm-modem-hso.c +++ /dev/null @@ -1,816 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <stdlib.h> -#include <arpa/inet.h> -#include <dbus/dbus-glib.h> - -#define G_UDEV_API_IS_SUBJECT_TO_CHANGE -#include <gudev/gudev.h> - -#include "mm-modem-hso.h" -#include "mm-modem-simple.h" -#include "mm-serial-parsers.h" -#include "mm-errors.h" -#include "mm-callback-info.h" - -static void impl_hso_authenticate (MMModemHso *self, - const char *username, - const char *password, - DBusGMethodInvocation *context); - -#include "mm-modem-gsm-hso-glue.h" - -static void modem_init (MMModem *modem_class); -static void modem_simple_init (MMModemSimple *simple_class); - -G_DEFINE_TYPE_EXTENDED (MMModemHso, mm_modem_hso, MM_TYPE_GENERIC_GSM, 0, - G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init) - G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_SIMPLE, modem_simple_init)) - -#define MM_MODEM_HSO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_HSO, MMModemHsoPrivate)) - -static void _internal_hso_modem_authenticate (MMModemHso *self, MMCallbackInfo *info); - -const char *auth_commands[] = { - "$QCPDPP", - /* Icera-based devices (GI0322/Quicksilver, iCON 505) don't implement - * $QCPDPP, but instead use _OPDPP with the same arguments. - */ - "_OPDPP", - NULL -}; - -typedef struct { - /* Pending connection attempt */ - MMCallbackInfo *connect_pending_data; - guint connect_pending_id; - - char *username; - char *password; - - guint32 auth_idx; -} MMModemHsoPrivate; - -#define OWANDATA_TAG "_OWANDATA: " - -MMModem * -mm_modem_hso_new (const char *device, - const char *driver, - const char *plugin, - guint32 vendor, - guint32 product) -{ - g_return_val_if_fail (device != NULL, NULL); - g_return_val_if_fail (driver != NULL, NULL); - g_return_val_if_fail (plugin != NULL, NULL); - - return MM_MODEM (g_object_new (MM_TYPE_MODEM_HSO, - MM_MODEM_MASTER_DEVICE, device, - MM_MODEM_DRIVER, driver, - MM_MODEM_PLUGIN, plugin, - MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_STATIC, - MM_MODEM_HW_VID, vendor, - MM_MODEM_HW_PID, product, - NULL)); -} - -#include "mm-modem-option-utils.c" - -/*****************************************************************************/ - -static gint -hso_get_cid (MMModemHso *self) -{ - gint cid; - - cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (self)); - if (cid < 0) { - g_warn_if_fail (cid >= 0); - cid = 0; - } - - return cid; -} - -static void -auth_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - MMModemHso *self; - MMModemHsoPrivate *priv; - - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - self = MM_MODEM_HSO (info->modem); - priv = MM_MODEM_HSO_GET_PRIVATE (self); - - if (error) { - priv->auth_idx++; - if (auth_commands[priv->auth_idx]) { - /* Try the next auth command */ - _internal_hso_modem_authenticate (self, info); - return; - } else - info->error = g_error_copy (error); - } - - /* Reset to 0 so something gets tried the next connection */ - priv->auth_idx = 0; - mm_callback_info_schedule (info); -} - -static void -_internal_hso_modem_authenticate (MMModemHso *self, MMCallbackInfo *info) -{ - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self); - MMAtSerialPort *primary; - gint cid; - char *command; - - primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_AT_PORT_FLAG_PRIMARY); - g_assert (primary); - - cid = hso_get_cid (self); - g_warn_if_fail (cid >= 0); - - /* Both user and password are required; otherwise firmware returns an error */ - if (!priv->username || !priv->password) - command = g_strdup_printf ("%s=%d,0", auth_commands[priv->auth_idx], cid); - else { - command = g_strdup_printf ("%s=%d,1,\"%s\",\"%s\"", - auth_commands[priv->auth_idx], - cid, - priv->password ? priv->password : "", - priv->username ? priv->username : ""); - - } - - mm_at_serial_port_queue_command (primary, command, 3, auth_done, info); - g_free (command); -} - -void -mm_hso_modem_authenticate (MMModemHso *self, - const char *username, - const char *password, - MMModemFn callback, - gpointer user_data) -{ - MMModemHsoPrivate *priv; - MMCallbackInfo *info; - - g_return_if_fail (self != NULL); - 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); - - priv = MM_MODEM_HSO_GET_PRIVATE (self); - - g_free (priv->username); - priv->username = (username && strlen (username)) ? g_strdup (username) : NULL; - - g_free (priv->password); - priv->password = (password && strlen (password)) ? g_strdup (password) : NULL; - - _internal_hso_modem_authenticate (self, info); -} - -/*****************************************************************************/ - -static void -connect_pending_done (MMModemHso *self) -{ - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self); - GError *error = NULL; - - if (priv->connect_pending_data) { - if (priv->connect_pending_data->error) { - error = priv->connect_pending_data->error; - priv->connect_pending_data->error = NULL; - } - - /* Complete the connect */ - mm_generic_gsm_connect_complete (MM_GENERIC_GSM (self), error, priv->connect_pending_data); - priv->connect_pending_data = NULL; - } - - if (priv->connect_pending_id) { - g_source_remove (priv->connect_pending_id); - priv->connect_pending_id = 0; - } -} - -static void -connection_enabled (MMAtSerialPort *port, - GMatchInfo *match_info, - gpointer user_data) -{ - MMModemHso *self = MM_MODEM_HSO (user_data); - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self); - char *str; - - str = g_match_info_fetch (match_info, 2); - if (str[0] == '1') - connect_pending_done (self); - else if (str[0] == '3') { - MMCallbackInfo *info = priv->connect_pending_data; - - if (info) { - info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, - "Call setup failed"); - } - - connect_pending_done (self); - } else if (str[0] == '0') { - /* FIXME: disconnected. do something when we have modem status signals */ - } - - g_free (str); -} - -/*****************************************************************************/ - -#define IGNORE_ERRORS_TAG "ignore-errors" - -static void -hso_call_control_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - if (error && !mm_callback_info_get_data (info, IGNORE_ERRORS_TAG)) - info->error = g_error_copy (error); - - mm_callback_info_schedule (info); -} - -static void -hso_call_control (MMModemHso *self, - gboolean activate, - gboolean ignore_errors, - MMModemFn callback, - gpointer user_data) -{ - MMCallbackInfo *info; - char *command; - MMAtSerialPort *primary; - - info = mm_callback_info_new (MM_MODEM (self), callback, user_data); - mm_callback_info_set_data (info, IGNORE_ERRORS_TAG, GUINT_TO_POINTER (ignore_errors), NULL); - - command = g_strdup_printf ("AT_OWANCALL=%d,%d,1", hso_get_cid (self), activate ? 1 : 0); - primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_AT_PORT_FLAG_PRIMARY); - g_assert (primary); - mm_at_serial_port_queue_command (primary, command, 3, hso_call_control_done, info); - g_free (command); -} - -static void -timeout_done (MMModem *modem, - GError *error, - gpointer user_data) -{ - if (modem) - connect_pending_done (MM_MODEM_HSO (modem)); -} - -static gboolean -hso_connect_timed_out (gpointer data) -{ - MMModemHso *self = MM_MODEM_HSO (data); - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self); - MMCallbackInfo *info = priv->connect_pending_data; - - priv->connect_pending_id = 0; - - if (info) { - info->error = g_error_new_literal (MM_SERIAL_ERROR, - MM_SERIAL_ERROR_RESPONSE_TIMEOUT, - "Connection timed out"); - } - - hso_call_control (self, FALSE, TRUE, timeout_done, self); - return FALSE; -} - -static void -hso_enabled (MMModem *modem, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - /* Do nothing if modem removed */ - if (!modem || mm_callback_info_check_modem_removed (info)) - return; - - if (error) { - mm_generic_gsm_connect_complete (MM_GENERIC_GSM (modem), error, info); - } else { - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (modem); - - priv->connect_pending_data = info; - priv->connect_pending_id = g_timeout_add_seconds (30, hso_connect_timed_out, modem); - } -} - -static void -old_context_clear_done (MMModem *modem, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - /* Do nothing if modem removed */ - if (!modem || mm_callback_info_check_modem_removed (info)) - return; - - if (error) - mm_generic_gsm_connect_complete (MM_GENERIC_GSM (modem), error, info); - else { - /* Success, activate the PDP context and start the data session */ - hso_call_control (MM_MODEM_HSO (modem), TRUE, FALSE, hso_enabled, info); - } -} - -static void -connect_auth_done (MMModem *modem, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - /* Do nothing if modem removed */ - if (!modem || mm_callback_info_check_modem_removed (info)) - return; - - if (error) { - mm_generic_gsm_connect_complete (MM_GENERIC_GSM (modem), error, info); - } else { - /* Now connect; kill any existing connections first */ - hso_call_control (MM_MODEM_HSO (modem), FALSE, TRUE, old_context_clear_done, info); - } -} - -static void -do_connect (MMModem *modem, - const char *number, - MMModemFn callback, - gpointer user_data) -{ - MMModemHso *self = MM_MODEM_HSO (modem); - MMCallbackInfo *auth_info, *connect_info; - - mm_modem_set_state (modem, MM_MODEM_STATE_CONNECTING, MM_MODEM_STATE_REASON_NONE); - - connect_info = mm_callback_info_new (modem, callback, user_data); - auth_info = mm_callback_info_new (modem, connect_auth_done, connect_info); - _internal_hso_modem_authenticate (self, auth_info); -} - -/*****************************************************************************/ - -static void -parent_disable_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 -disable_done (MMModem *modem, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - MMModem *parent_modem_iface; - - /* Do the normal disable stuff */ - parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem)); - parent_modem_iface->disable (info->modem, parent_disable_done, info); -} - -static void -unsolicited_disable_done (MMModem *modem, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = user_data; - - /* Handle modem removal, but ignore other errors */ - if (g_error_matches (error, MM_MODEM_ERROR, MM_MODEM_ERROR_REMOVED)) - info->error = g_error_copy (error); - else if (!modem) { - info->error = g_error_new_literal (MM_MODEM_ERROR, - MM_MODEM_ERROR_REMOVED, - "The modem was removed."); - } - - if (info->error) { - mm_callback_info_schedule (info); - return; - } - - /* Otherwise, kill any existing connection */ - if (hso_get_cid (MM_MODEM_HSO (modem)) >= 0) - hso_call_control (MM_MODEM_HSO (modem), FALSE, TRUE, disable_done, info); - else - disable_done (modem, NULL, info); -} - -static void -disable (MMModem *modem, - MMModemFn callback, - gpointer user_data) -{ - MMModemHso *self = MM_MODEM_HSO (modem); - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self); - MMCallbackInfo *info; - - mm_generic_gsm_pending_registration_stop (MM_GENERIC_GSM (modem)); - - g_free (priv->username); - priv->username = NULL; - g_free (priv->password); - priv->password = NULL; - - info = mm_callback_info_new (modem, callback, user_data); - - /* Turn off unsolicited messages so they don't pile up in the modem */ - option_change_unsolicited_messages (MM_GENERIC_GSM (modem), FALSE, unsolicited_disable_done, info); -} - -/*****************************************************************************/ - -static void -free_dns_array (gpointer data) -{ - g_array_free ((GArray *) data, TRUE); -} - -static void -ip4_config_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); -} - -static void -get_ip4_config_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - char **items, **iter; - GArray *dns_array; - int i; - guint32 tmp; - gint cid; - - /* 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 out; - } else if (!g_str_has_prefix (response->str, OWANDATA_TAG)) { - info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, - "Retrieving failed: invalid response."); - goto out; - } - - cid = hso_get_cid (MM_MODEM_HSO (info->modem)); - dns_array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 2); - items = g_strsplit (response->str + strlen (OWANDATA_TAG), ", ", 0); - - for (iter = items, i = 0; *iter; iter++, i++) { - if (i == 0) { /* CID */ - long int num; - - errno = 0; - num = strtol (*iter, NULL, 10); - if (errno != 0 || num < 0 || (gint) num != cid) { - info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, - "Unknown CID in OWANDATA response (" - "got %d, expected %d)", (guint) num, cid); - break; - } - } else if (i == 1) { /* IP address */ - if (inet_pton (AF_INET, *iter, &tmp) > 0) - mm_callback_info_set_data (info, "ip4-address", GUINT_TO_POINTER (tmp), NULL); - } else if (i == 3) { /* DNS 1 */ - if (inet_pton (AF_INET, *iter, &tmp) > 0) - g_array_append_val (dns_array, tmp); - } else if (i == 4) { /* DNS 2 */ - if (inet_pton (AF_INET, *iter, &tmp) > 0) - g_array_append_val (dns_array, tmp); - } - } - - g_strfreev (items); - mm_callback_info_set_data (info, "ip4-dns", dns_array, free_dns_array); - - out: - mm_callback_info_schedule (info); -} - -static void -get_ip4_config (MMModem *modem, - MMModemIp4Fn callback, - gpointer user_data) -{ - MMCallbackInfo *info; - char *command; - MMAtSerialPort *primary; - - 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))); - primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (modem), MM_AT_PORT_FLAG_PRIMARY); - g_assert (primary); - mm_at_serial_port_queue_command (primary, command, 3, get_ip4_config_done, info); - g_free (command); -} - -/*****************************************************************************/ - -static void -disconnect_owancall_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - mm_callback_info_schedule (info); -} - -static void -do_disconnect (MMGenericGsm *gsm, - gint cid, - MMModemFn callback, - gpointer user_data) -{ - MMCallbackInfo *info; - MMAtSerialPort *primary; - char *command; - - info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data); - - primary = mm_generic_gsm_get_at_port (gsm, MM_AT_PORT_FLAG_PRIMARY); - g_assert (primary); - - command = g_strdup_printf ("AT_OWANCALL=%d,0,0", cid); - mm_at_serial_port_queue_command (primary, command, 3, disconnect_owancall_done, info); - g_free (command); -} - -/*****************************************************************************/ - -static void -real_do_enable_power_up_done (MMGenericGsm *gsm, - GString *response, - GError *error, - MMCallbackInfo *info) -{ - /* Enable Option unsolicited messages */ - if (gsm && !error) - option_change_unsolicited_messages (gsm, TRUE, NULL, NULL); - - /* Chain up to parent */ - MM_GENERIC_GSM_CLASS (mm_modem_hso_parent_class)->do_enable_power_up_done (gsm, response, error, info); -} - -/*****************************************************************************/ - -static void -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); -} - -static void -impl_hso_authenticate (MMModemHso *self, - const char *username, - const char *password, - DBusGMethodInvocation *context) -{ - /* DBus doesn't support NULLs */ - if (username && strlen (username) == 0) - username = NULL; - if (password && strlen (password) == 0) - password = NULL; - - mm_hso_modem_authenticate (self, username, password, impl_hso_auth_done, context); -} - -/*****************************************************************************/ - -static const char * -hso_simple_get_string_property (GHashTable *properties, const char *name, GError **error) -{ - GValue *value; - - value = (GValue *) g_hash_table_lookup (properties, name); - if (!value) - return NULL; - - if (G_VALUE_HOLDS_STRING (value)) - return g_value_get_string (value); - - g_set_error (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, - "Invalid property type for '%s': %s (string expected)", - name, G_VALUE_TYPE_NAME (value)); - - return NULL; -} - -static void -simple_connect (MMModemSimple *simple, - GHashTable *properties, - MMModemFn callback, - gpointer user_data) -{ - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (simple); - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - MMModemSimple *parent_iface; - - priv->username = g_strdup (hso_simple_get_string_property (properties, "username", NULL)); - priv->password = g_strdup (hso_simple_get_string_property (properties, "password", NULL)); - - parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (simple)); - parent_iface->connect (MM_MODEM_SIMPLE (simple), properties, callback, info); -} - -/*****************************************************************************/ - -static void -get_allowed_mode (MMGenericGsm *gsm, - MMModemUIntFn callback, - gpointer user_data) -{ - option_get_allowed_mode (gsm, callback, user_data); -} - -static void -set_allowed_mode (MMGenericGsm *gsm, - MMModemGsmAllowedMode mode, - MMModemFn callback, - gpointer user_data) -{ - option_set_allowed_mode (gsm, mode, callback, user_data); -} - -static void -get_access_technology (MMGenericGsm *gsm, - MMModemUIntFn callback, - gpointer user_data) -{ - option_get_access_technology (gsm, callback, user_data); -} - -/*****************************************************************************/ - -static void -port_grabbed (MMGenericGsm *gsm, - MMPort *port, - MMAtPortFlags pflags, - gpointer user_data) -{ - GRegex *regex; - - if (MM_IS_AT_SERIAL_PORT (port)) { - g_object_set (G_OBJECT (port), - MM_SERIAL_PORT_SEND_DELAY, (guint64) 0, - /* built-in echo removal conflicts with unsolicited _OWANCALL - * messages, which are not <CR><LF> prefixed. */ - MM_AT_SERIAL_PORT_REMOVE_ECHO, FALSE, - NULL); - - regex = g_regex_new ("\\r\\n\\+PACSP0\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, NULL, NULL, NULL); - g_regex_unref (regex); - - option_register_unsolicted_handlers (gsm, MM_AT_SERIAL_PORT (port)); - } -} - - -static void -ports_organized (MMGenericGsm *gsm, MMAtSerialPort *primary) -{ - GRegex *regex; - - regex = g_regex_new ("_OWANCALL: (\\d),\\s*(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (primary, regex, connection_enabled, gsm, NULL); - g_regex_unref (regex); -} - -/*****************************************************************************/ - -static void -mm_modem_hso_init (MMModemHso *self) -{ -} - -static void -modem_simple_init (MMModemSimple *class) -{ - class->connect = simple_connect; -} - -static void -modem_init (MMModem *modem_class) -{ - modem_class->disable = disable; - modem_class->connect = do_connect; - modem_class->get_ip4_config = get_ip4_config; -} - -static void -finalize (GObject *object) -{ - MMModemHso *self = MM_MODEM_HSO (object); - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self); - - /* Clear the pending connection if necessary */ - connect_pending_done (self); - - g_free (priv->username); - g_free (priv->password); - - G_OBJECT_CLASS (mm_modem_hso_parent_class)->finalize (object); -} - -static void -mm_modem_hso_class_init (MMModemHsoClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass); - - mm_modem_hso_parent_class = g_type_class_peek_parent (klass); - g_type_class_add_private (object_class, sizeof (MMModemHsoPrivate)); - - /* Virtual methods */ - object_class->finalize = finalize; - gsm_class->port_grabbed = port_grabbed; - gsm_class->ports_organized = ports_organized; - gsm_class->do_disconnect = do_disconnect; - gsm_class->do_enable_power_up_done = real_do_enable_power_up_done; - gsm_class->set_allowed_mode = set_allowed_mode; - gsm_class->get_allowed_mode = get_allowed_mode; - gsm_class->get_access_technology = get_access_technology; -} diff --git a/plugins/mm-modem-hso.h b/plugins/mm-modem-hso.h deleted file mode 100644 index 7e79886c..00000000 --- a/plugins/mm-modem-hso.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. - */ - -#ifndef MM_MODEM_HSO_H -#define MM_MODEM_HSO_H - -#include "mm-generic-gsm.h" - -#define MM_TYPE_MODEM_HSO (mm_modem_hso_get_type ()) -#define MM_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_HSO, MMModemHso)) -#define MM_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_HSO, MMModemHsoClass)) -#define MM_IS_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_HSO)) -#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)) - -typedef struct { - MMGenericGsm parent; -} MMModemHso; - -typedef struct { - MMGenericGsmClass parent; -} MMModemHsoClass; - -GType mm_modem_hso_get_type (void); - -MMModem *mm_modem_hso_new (const char *device, - const char *driver, - const char *plugin, - guint32 vendor, - guint32 product); - -void mm_hso_modem_authenticate (MMModemHso *self, - const char *username, - const char *password, - MMModemFn callback, - gpointer user_data); - -#endif /* MM_MODEM_HSO_H */ diff --git a/plugins/mm-modem-option-utils.c b/plugins/mm-modem-option-utils.c deleted file mode 100644 index c4c39b27..00000000 --- a/plugins/mm-modem-option-utils.c +++ /dev/null @@ -1,561 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2010 Red Hat, Inc. - */ - -/****************************************** - * Generic utilities for Option NV modems - * Used with both 'option' and 'hso' - ******************************************/ - -#include "mm-callback-info.h" -#include "mm-at-serial-port.h" -#include "mm-generic-gsm.h" -#include "mm-modem-helpers.h" - -static void -option_get_allowed_mode_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - gboolean parsed = FALSE; - - /* 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); - else if (!g_str_has_prefix (response->str, "_OPSYS: ")) { - int a, b; - - if (sscanf (response->str + 8, "%d,%d", &a, &b)) { - MMModemGsmAllowedMode mode = MM_MODEM_GSM_ALLOWED_MODE_ANY; - - switch (a) { - case 0: - mode = MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY; - break; - case 1: - mode = MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY; - break; - case 2: - mode = MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED; - break; - case 3: - mode = MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED; - break; - default: - break; - } - - mm_callback_info_set_result (info, GUINT_TO_POINTER (mode), NULL); - parsed = TRUE; - } - } - - if (!error && !parsed) - info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, - "Could not parse allowed mode results"); - - mm_callback_info_schedule (info); -} - -static void -option_get_allowed_mode (MMGenericGsm *gsm, - MMModemUIntFn callback, - gpointer user_data) -{ - MMCallbackInfo *info; - MMAtSerialPort *port; - - info = mm_callback_info_uint_new (MM_MODEM (gsm), callback, user_data); - - port = mm_generic_gsm_get_best_at_port (gsm, &info->error); - if (!port) { - mm_callback_info_schedule (info); - return; - } - mm_at_serial_port_queue_command (port, "AT_OPSYS?", 3, option_get_allowed_mode_done, info); -} - -static void -option_set_allowed_mode_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = (MMCallbackInfo *) user_data; - - /* 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); - - mm_callback_info_schedule (info); -} - -static void -option_set_allowed_mode (MMGenericGsm *gsm, - MMModemGsmAllowedMode mode, - MMModemFn callback, - gpointer user_data) -{ - MMCallbackInfo *info; - MMAtSerialPort *port; - char *command; - int i; - - info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data); - - port = mm_generic_gsm_get_best_at_port (gsm, &info->error); - if (!port) { - mm_callback_info_schedule (info); - return; - } - - switch (mode) { - case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY: - i = 0; - break; - case MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY: - i = 1; - break; - case MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED: - i = 2; - break; - case MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED: - i = 3; - break; - case MM_MODEM_GSM_ALLOWED_MODE_ANY: - default: - i = 5; - break; - } - - command = g_strdup_printf ("AT_OPSYS=%d,2", i); - mm_at_serial_port_queue_command (port, command, 3, option_set_allowed_mode_done, info); - g_free (command); -} - -static gboolean -octi_to_mm (char octi, MMModemGsmAccessTech *out_act) -{ - if (octi == '1') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_GSM; - return TRUE; - } else if (octi == '2') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_GPRS; - return TRUE; - } else if (octi == '3') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_EDGE; - return TRUE; - } - return FALSE; -} - -static gboolean -owcti_to_mm (char owcti, MMModemGsmAccessTech *out_act) -{ - if (owcti == '1') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_UMTS; - return TRUE; - } else if (owcti == '2') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_HSDPA; - return TRUE; - } else if (owcti == '3') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_HSUPA; - return TRUE; - } else if (owcti == '4') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_HSPA; - return TRUE; - } - return FALSE; -} - -static gboolean -ossys_to_mm (char ossys, MMModemGsmAccessTech *out_act) -{ - if (ossys == '0') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_GPRS; - return TRUE; - } else if (ossys == '2') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_UMTS; - return TRUE; - } else if (ossys == '3') { - *out_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - return TRUE; - } - return FALSE; -} - -static gboolean -parse_octi_response (GString *response, MMModemGsmAccessTech *act) -{ - MMModemGsmAccessTech cur_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - const char *p; - GRegex *r; - GMatchInfo *match_info; - char *str; - gboolean success = FALSE; - - g_return_val_if_fail (act != NULL, FALSE); - g_return_val_if_fail (response != NULL, FALSE); - - p = mm_strip_tag (response->str, "_OCTI:"); - - r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL); - g_return_val_if_fail (r != NULL, FALSE); - - g_regex_match (r, p, 0, &match_info); - if (g_match_info_matches (match_info)) { - str = g_match_info_fetch (match_info, 2); - if (str && octi_to_mm (str[0], &cur_act)) { - *act = cur_act; - success = TRUE; - } - g_free (str); - } - g_match_info_free (match_info); - g_regex_unref (r); - - return success; -} - -static gboolean -parse_ossys_response (GString *response, MMModemGsmAccessTech *act) -{ - MMModemGsmAccessTech cur_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - const char *p; - GRegex *r; - GMatchInfo *match_info; - char *str; - gboolean success = FALSE; - - g_return_val_if_fail (act != NULL, FALSE); - g_return_val_if_fail (response != NULL, FALSE); - - p = mm_strip_tag (response->str, "_OSSYS:"); - - r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL); - g_return_val_if_fail (r != NULL, FALSE); - - g_regex_match (r, p, 0, &match_info); - if (g_match_info_matches (match_info)) { - str = g_match_info_fetch (match_info, 2); - if (str && ossys_to_mm (str[0], &cur_act)) { - *act = cur_act; - success = TRUE; - } - g_free (str); - } - g_match_info_free (match_info); - g_regex_unref (r); - - return success; -} - -static void -ossys_octi_request_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - - if (!error) { - if (parse_octi_response (response, &act)) - mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (user_data), act); - } -} - -static void -ossys_owcti_request_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - const char *p; - MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - - if (!error) { - p = mm_strip_tag (response->str, "_OWCTI:"); - if (owcti_to_mm (*p, &act)) - mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (user_data), act); - } -} - -static void -option_ossys_tech_changed (MMAtSerialPort *port, - GMatchInfo *info, - gpointer user_data) -{ - MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - char *str; - - str = g_match_info_fetch (info, 1); - if (str) - ossys_to_mm (str[0], &act); - g_free (str); - - mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (user_data), act); - - /* _OSSYSI only indicates general 2G/3G mode, so queue up some explicit - * access technology requests. - */ - if (act == MM_MODEM_GSM_ACCESS_TECH_GPRS) - mm_at_serial_port_queue_command (port, "_OCTI?", 3, ossys_octi_request_done, user_data); - else if (act == MM_MODEM_GSM_ACCESS_TECH_UMTS) - mm_at_serial_port_queue_command (port, "_OWCTI?", 3, ossys_owcti_request_done, user_data); -} - -static void -option_2g_tech_changed (MMAtSerialPort *port, - GMatchInfo *match_info, - gpointer user_data) -{ - MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - char *str; - - str = g_match_info_fetch (match_info, 1); - if (octi_to_mm (str[0], &act)) - mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (user_data), act); - g_free (str); -} - -static void -option_3g_tech_changed (MMAtSerialPort *port, - GMatchInfo *match_info, - gpointer user_data) -{ - MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - char *str; - - str = g_match_info_fetch (match_info, 1); - if (owcti_to_mm (str[0], &act)) - mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (user_data), act); - g_free (str); -} - -static void -option_signal_changed (MMAtSerialPort *port, - GMatchInfo *match_info, - gpointer user_data) -{ - char *str; - int quality = 0; - - str = g_match_info_fetch (match_info, 1); - quality = atoi (str); - g_free (str); - - if (quality == 99) { - /* 99 means unknown */ - quality = 0; - } else { - /* Normalize the quality */ - quality = CLAMP (quality, 0, 31) * 100 / 31; - } - - mm_generic_gsm_update_signal_quality (MM_GENERIC_GSM (user_data), (guint32) quality); -} - -static void -option_register_unsolicted_handlers (MMGenericGsm *modem, MMAtSerialPort *port) -{ - GRegex *regex; - - regex = g_regex_new ("\\r\\n_OSSYSI:\\s*(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (port, regex, option_ossys_tech_changed, modem, NULL); - g_regex_unref (regex); - - regex = g_regex_new ("\\r\\n_OCTI:\\s*(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (port, regex, option_2g_tech_changed, modem, NULL); - g_regex_unref (regex); - - regex = g_regex_new ("\\r\\n_OUWCTI:\\s*(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (port, regex, option_3g_tech_changed, modem, NULL); - g_regex_unref (regex); - - regex = g_regex_new ("\\r\\n_OSIGQ:\\s*(\\d+),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (port, regex, option_signal_changed, modem, NULL); - g_regex_unref (regex); -} - -static void -unsolicited_msg_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = user_data; - - if (info) { - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - mm_callback_info_chain_complete_one (info); - } -} - -static void -option_change_unsolicited_messages (MMGenericGsm *modem, - gboolean enabled, - MMModemFn callback, - gpointer user_data) -{ - MMCallbackInfo *info = NULL; - MMAtSerialPort *primary; - - if (callback) { - info = mm_callback_info_new (MM_MODEM (modem), callback, user_data); - mm_callback_info_chain_start (info, 4); - } - - primary = mm_generic_gsm_get_at_port (modem, MM_AT_PORT_FLAG_PRIMARY); - g_assert (primary); - - mm_at_serial_port_queue_command (primary, enabled ? "_OSSYS=1" : "_OSSYS=0", 3, unsolicited_msg_done, info); - mm_at_serial_port_queue_command (primary, enabled ? "_OCTI=1" : "_OCTI=0", 3, unsolicited_msg_done, info); - mm_at_serial_port_queue_command (primary, enabled ? "_OUWCTI=1" : "_OUWCTI=0", 3, unsolicited_msg_done, info); - mm_at_serial_port_queue_command (primary, enabled ? "_OSQI=1" : "_OSQI=0", 3, unsolicited_msg_done, info); -} - -static void -get_act_octi_request_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = user_data; - MMModemGsmAccessTech octi = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - MMModemGsmAccessTech act; - - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - if (!error) { - if (parse_octi_response (response, &octi)) { - /* If current tech is 2G or unknown then use the more specific - * OCTI response. - */ - act = GPOINTER_TO_UINT (mm_callback_info_get_result (info)); - if (act < MM_MODEM_GSM_ACCESS_TECH_UMTS) - mm_callback_info_set_result (info, GUINT_TO_POINTER (octi), NULL); - } - } - - mm_callback_info_chain_complete_one (info); -} - -static void -get_act_owcti_request_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = user_data; - MMModemGsmAccessTech owcti = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - const char *p; - - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - if (!error) { - p = mm_strip_tag (response->str, "_OWCTI:"); - if (owcti_to_mm (*p, &owcti) && owcti) - mm_callback_info_set_result (info, GUINT_TO_POINTER (owcti), NULL); - } - - mm_callback_info_chain_complete_one (info); -} - -static void -get_act_ossys_request_done (MMAtSerialPort *port, - GString *response, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = user_data; - MMModemGsmAccessTech ossys = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; - gboolean check_2g = TRUE, check_3g = TRUE; - - /* If the modem has already been removed, return without - * scheduling callback */ - if (mm_callback_info_check_modem_removed (info)) - return; - - /* If for some reason the OSSYS request failed, still try to check - * explicit 2G/3G mode with OCTI and OWCTI; maybe we'll get something. - */ - - if (!error) { - /* Response is _OSSYS: <n>,<act> so we must skip the <n> */ - if (parse_ossys_response (response, &ossys)) { - mm_callback_info_set_result (info, GUINT_TO_POINTER (ossys), NULL); - - /* If the OSSYS response indicated a generic access tech type - * then only check for more specific access tech of that type. - */ - if (ossys == MM_MODEM_GSM_ACCESS_TECH_GPRS) - check_3g = FALSE; - if (ossys == MM_MODEM_GSM_ACCESS_TECH_UMTS) - check_2g = FALSE; - } - } - - if (check_2g) - mm_at_serial_port_queue_command (port, "_OCTI?", 3, get_act_octi_request_done, info); - else - mm_callback_info_chain_complete_one (info); /* complete it if it wasn't used */ - - if (check_3g) - mm_at_serial_port_queue_command (port, "_OWCTI?", 3, get_act_owcti_request_done, info); - else - mm_callback_info_chain_complete_one (info); /* complete it if it wasn't used */ - - mm_callback_info_chain_complete_one (info); -} - -static void -option_get_access_technology (MMGenericGsm *modem, - MMModemUIntFn callback, - gpointer user_data) -{ - MMAtSerialPort *port; - MMCallbackInfo *info; - - info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data); - mm_callback_info_chain_start (info, 3); - - port = mm_generic_gsm_get_best_at_port (modem, &info->error); - if (!port) { - mm_callback_info_schedule (info); - return; - } - - mm_at_serial_port_queue_command (port, "_OSSYS?", 3, get_act_ossys_request_done, info); -} - diff --git a/plugins/mm-modem-option.c b/plugins/mm-modem-option.c deleted file mode 100644 index 1b0d3631..00000000 --- a/plugins/mm-modem-option.c +++ /dev/null @@ -1,237 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include "mm-modem-option.h" -#include "mm-errors.h" -#include "mm-callback-info.h" - -static void modem_init (MMModem *modem_class); - -G_DEFINE_TYPE_EXTENDED (MMModemOption, mm_modem_option, MM_TYPE_GENERIC_GSM, 0, - G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init)) - -#define MM_MODEM_OPTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_OPTION, MMModemOptionPrivate)) - -typedef struct { - guint enable_wait_id; -} MMModemOptionPrivate; - -MMModem * -mm_modem_option_new (const char *device, - const char *driver, - const char *plugin, - guint32 vendor, - guint32 product) -{ - g_return_val_if_fail (device != NULL, NULL); - g_return_val_if_fail (driver != NULL, NULL); - g_return_val_if_fail (plugin != NULL, NULL); - - return MM_MODEM (g_object_new (MM_TYPE_MODEM_OPTION, - MM_MODEM_MASTER_DEVICE, device, - MM_MODEM_DRIVER, driver, - MM_MODEM_PLUGIN, plugin, - MM_MODEM_HW_VID, vendor, - MM_MODEM_HW_PID, product, - NULL)); -} - -#include "mm-modem-option-utils.c" - -/*****************************************************************************/ - -static gboolean -option_enabled (gpointer user_data) -{ - MMCallbackInfo *info = user_data; - MMGenericGsm *modem; - MMModemOptionPrivate *priv; - - /* Make sure we don't use an invalid modem that may have been removed */ - if (info->modem) { - modem = MM_GENERIC_GSM (info->modem); - priv = MM_MODEM_OPTION_GET_PRIVATE (modem); - priv->enable_wait_id = 0; - - option_change_unsolicited_messages (modem, TRUE, NULL, NULL); - - MM_GENERIC_GSM_CLASS (mm_modem_option_parent_class)->do_enable_power_up_done (modem, NULL, NULL, info); - } - return FALSE; -} - -static void -real_do_enable_power_up_done (MMGenericGsm *gsm, - GString *response, - GError *error, - MMCallbackInfo *info) -{ - MMModemOptionPrivate *priv = MM_MODEM_OPTION_GET_PRIVATE (gsm); - - if (error) { - /* Chain up to parent */ - MM_GENERIC_GSM_CLASS (mm_modem_option_parent_class)->do_enable_power_up_done (gsm, NULL, error, info); - return; - } - - /* Some Option devices return OK on +CFUN=1 right away but need some time - * to finish initialization. - */ - g_warn_if_fail (priv->enable_wait_id == 0); - priv->enable_wait_id = g_timeout_add_seconds (10, option_enabled, info); -} - -/*****************************************************************************/ - -static void -get_allowed_mode (MMGenericGsm *gsm, - MMModemUIntFn callback, - gpointer user_data) -{ - option_get_allowed_mode (gsm, callback, user_data); -} - -static void -set_allowed_mode (MMGenericGsm *gsm, - MMModemGsmAllowedMode mode, - MMModemFn callback, - gpointer user_data) -{ - option_set_allowed_mode (gsm, mode, callback, user_data); -} - -static void -get_access_technology (MMGenericGsm *gsm, - MMModemUIntFn callback, - gpointer user_data) -{ - option_get_access_technology (gsm, callback, user_data); -} - -/*****************************************************************************/ - -static void -parent_disable_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 -unsolicited_disable_done (MMModem *modem, - GError *error, - gpointer user_data) -{ - MMCallbackInfo *info = user_data; - MMModem *parent_modem_iface; - GError *tmp_error = NULL; - - /* Handle modem removal, but ignore other errors */ - if (g_error_matches (error, MM_MODEM_ERROR, MM_MODEM_ERROR_REMOVED)) { - parent_disable_done (modem, error, user_data); - return; - } else if (!modem) { - tmp_error = g_error_new_literal (MM_MODEM_ERROR, - MM_MODEM_ERROR_REMOVED, - "The modem was removed."); - parent_disable_done (modem, tmp_error, user_data); - g_error_free (tmp_error); - return; - } - - /* Chain up to parent */ - parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem)); - parent_modem_iface->disable (info->modem, parent_disable_done, info); -} - -static void -disable (MMModem *modem, - MMModemFn callback, - gpointer user_data) -{ - MMCallbackInfo *info; - - mm_generic_gsm_pending_registration_stop (MM_GENERIC_GSM (modem)); - - info = mm_callback_info_new (modem, callback, user_data); - - /* Turn off unsolicited messages so they don't pile up in the modem */ - option_change_unsolicited_messages (MM_GENERIC_GSM (modem), FALSE, unsolicited_disable_done, info); -} - -static void -port_grabbed (MMGenericGsm *gsm, - MMPort *port, - MMAtPortFlags pflags, - gpointer user_data) -{ - GRegex *regex; - - if (MM_IS_AT_SERIAL_PORT (port)) { - regex = g_regex_new ("\\r\\n\\+PACSP0\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); - mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, NULL, NULL, NULL); - g_regex_unref (regex); - - option_register_unsolicted_handlers (gsm, MM_AT_SERIAL_PORT (port)); - } -} - -/*****************************************************************************/ - -static void -modem_init (MMModem *modem_class) -{ - modem_class->disable = disable; -} - -static void -mm_modem_option_init (MMModemOption *self) -{ -} - -static void -dispose (GObject *object) -{ - MMModemOptionPrivate *priv = MM_MODEM_OPTION_GET_PRIVATE (object); - - if (priv->enable_wait_id) - g_source_remove (priv->enable_wait_id); -} - -static void -mm_modem_option_class_init (MMModemOptionClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass); - - mm_modem_option_parent_class = g_type_class_peek_parent (klass); - g_type_class_add_private (object_class, sizeof (MMModemOptionPrivate)); - - object_class->dispose = dispose; - gsm_class->port_grabbed = port_grabbed; - gsm_class->do_enable_power_up_done = real_do_enable_power_up_done; - gsm_class->set_allowed_mode = set_allowed_mode; - gsm_class->get_allowed_mode = get_allowed_mode; - gsm_class->get_access_technology = get_access_technology; -} - diff --git a/plugins/mm-modem-option.h b/plugins/mm-modem-option.h deleted file mode 100644 index 3af9b1e9..00000000 --- a/plugins/mm-modem-option.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. - */ - -#ifndef MM_MODEM_OPTION_H -#define MM_MODEM_OPTION_H - -#include "mm-generic-gsm.h" - -#define MM_TYPE_MODEM_OPTION (mm_modem_option_get_type ()) -#define MM_MODEM_OPTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_OPTION, MMModemOption)) -#define MM_MODEM_OPTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_OPTION, MMModemOptionClass)) -#define MM_IS_MODEM_OPTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_OPTION)) -#define MM_IS_MODEM_OPTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_OPTION)) -#define MM_MODEM_OPTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_OPTION, MMModemOptionClass)) - -typedef struct { - MMGenericGsm parent; -} MMModemOption; - -typedef struct { - MMGenericGsmClass parent; -} MMModemOptionClass; - -GType mm_modem_option_get_type (void); - -MMModem *mm_modem_option_new (const char *device, - const char *driver, - const char *plugin_name, - guint32 vendor, - guint32 product); - -#endif /* MM_MODEM_OPTION_H */ diff --git a/plugins/mm-plugin-hso.c b/plugins/mm-plugin-hso.c deleted file mode 100644 index 2b1a64c2..00000000 --- a/plugins/mm-plugin-hso.c +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. - */ - -#include <string.h> -#include <gmodule.h> - -#define G_UDEV_API_IS_SUBJECT_TO_CHANGE -#include <gudev/gudev.h> - -#include "mm-plugin-hso.h" -#include "mm-modem-hso.h" - -G_DEFINE_TYPE (MMPluginHso, mm_plugin_hso, MM_TYPE_PLUGIN_BASE) - -int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; -int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; - - -G_MODULE_EXPORT MMPlugin * -mm_plugin_create (void) -{ - return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_HSO, - MM_PLUGIN_BASE_NAME, "Option High-Speed", - NULL)); -} - -/*****************************************************************************/ - -static guint32 -get_level_for_capabilities (guint32 capabilities) -{ - if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM) - return 10; - return 0; -} - -static void -probe_result (MMPluginBase *base, - MMPluginBaseSupportsTask *task, - guint32 capabilities, - gpointer user_data) -{ - mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities)); -} - -static MMPluginSupportsResult -supports_port (MMPluginBase *base, - MMModem *existing, - MMPluginBaseSupportsTask *task) -{ - GUdevDevice *port; - const char *driver, *subsys; - - port = mm_plugin_base_supports_task_get_port (task); - - driver = mm_plugin_base_supports_task_get_driver (task); - if (!driver || strcmp (driver, "hso")) - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - - subsys = g_udev_device_get_subsystem (port); - g_assert (subsys); - if (!strcmp (subsys, "net")) { - mm_plugin_base_supports_task_complete (task, 10); - return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; - } - - /* Check if a previous probing was already launched in this port */ - if (mm_plugin_base_supports_task_propagate_cached (task)) { - guint32 level; - - /* A previous probing was already done, use its results */ - level = get_level_for_capabilities (mm_plugin_base_supports_task_get_probed_capabilities (task)); - if (level) { - mm_plugin_base_supports_task_complete (task, level); - return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; - } - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - } - - /* Otherwise kick off a probe */ - if (mm_plugin_base_probe_port (base, task, 0, NULL)) - return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; - - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; -} - -static MMModem * -grab_port (MMPluginBase *base, - MMModem *existing, - MMPluginBaseSupportsTask *task, - GError **error) -{ - GUdevDevice *port = NULL; - MMModem *modem = NULL; - const char *name, *subsys, *sysfs_path; - char *devfile; - guint32 caps; - guint16 vendor = 0, product = 0; - MMPortType ptype; - MMAtPortFlags pflags = MM_AT_PORT_FLAG_NONE; - - port = mm_plugin_base_supports_task_get_port (task); - g_assert (port); - - subsys = g_udev_device_get_subsystem (port); - name = g_udev_device_get_name (port); - - if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { - g_set_error (error, 0, 0, "Could not get modem product ID."); - return NULL; - } - - devfile = g_strdup (g_udev_device_get_device_file (port)); - if (!devfile) { - if (!strcmp (subsys, "net")) { - /* Apparently 'hso' doesn't set up the right links for the netdevice, - * and thus libgudev can't get the sysfs file path for it. - */ - devfile = g_strdup_printf ("/sys/class/net/%s", name); - if (!g_file_test (devfile, G_FILE_TEST_EXISTS)) { - g_free (devfile); - devfile = NULL; - } - } - - if (!devfile) { - g_set_error (error, 0, 0, "Could not get port's sysfs file."); - goto out; - } - } - - sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); - - /* Detect port types */ - if (!strcmp (subsys, "tty")) { - char *hsotype_path; - char *contents = NULL; - - hsotype_path = g_build_filename (sysfs_path, "hsotype", NULL); - if (g_file_get_contents (hsotype_path, &contents, NULL, NULL)) { - if (g_str_has_prefix (contents, "Control")) - pflags = MM_AT_PORT_FLAG_PRIMARY; - else if (g_str_has_prefix (contents, "Application") || g_str_has_prefix (contents, "Application2")) - pflags = MM_AT_PORT_FLAG_SECONDARY; /* secondary */ - g_free (contents); - } - g_free (hsotype_path); - } - - caps = mm_plugin_base_supports_task_get_probed_capabilities (task); - if (!(caps & MM_PLUGIN_BASE_PORT_CAP_GSM) && strcmp (subsys, "net")) - goto out; - - ptype = mm_plugin_base_probed_capabilities_to_port_type (caps); - if (!existing) { - modem = mm_modem_hso_new (sysfs_path, - mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base)), - vendor, - product); - if (modem) { - if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) { - g_object_unref (modem); - return NULL; - } - } - } else { - modem = existing; - if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) - return NULL; - } - -out: - g_free (devfile); - return modem; -} - -/*****************************************************************************/ - -static void -mm_plugin_hso_init (MMPluginHso *self) -{ - g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL); -} - -static void -mm_plugin_hso_class_init (MMPluginHsoClass *klass) -{ - MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass); - - pb_class->supports_port = supports_port; - pb_class->grab_port = grab_port; -} diff --git a/plugins/mm-plugin-hso.h b/plugins/mm-plugin-hso.h deleted file mode 100644 index a3f4caf9..00000000 --- a/plugins/mm-plugin-hso.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. - */ - -#ifndef MM_PLUGIN_HSO_H -#define MM_PLUGIN_HSO_H - -#include "mm-plugin.h" -#include "mm-plugin-base.h" -#include "mm-generic-gsm.h" - -#define MM_TYPE_PLUGIN_HSO (mm_plugin_hso_get_type ()) -#define MM_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHso)) -#define MM_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass)) -#define MM_IS_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_HSO)) -#define MM_IS_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_HSO)) -#define MM_PLUGIN_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass)) - -typedef struct { - MMPluginBase parent; -} MMPluginHso; - -typedef struct { - MMPluginBaseClass parent; -} MMPluginHsoClass; - -GType mm_plugin_hso_get_type (void); - -G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); - -#endif /* MM_PLUGIN_HSO_H */ diff --git a/plugins/mm-plugin-option.c b/plugins/mm-plugin-option.c deleted file mode 100644 index 0f90a4e7..00000000 --- a/plugins/mm-plugin-option.c +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details: - * - * Copyright (C) 2008 - 2009 Novell, Inc. - * Copyright (C) 2009 Red Hat, Inc. - */ - -#include <string.h> -#include <gmodule.h> -#include "mm-plugin-option.h" -#include "mm-modem-option.h" - -G_DEFINE_TYPE (MMPluginOption, mm_plugin_option, MM_TYPE_PLUGIN_BASE) - -int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; -int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; - -G_MODULE_EXPORT MMPlugin * -mm_plugin_create (void) -{ - return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_OPTION, - MM_PLUGIN_BASE_NAME, "Option", - NULL)); -} - -/*****************************************************************************/ - -static guint32 -get_level_for_capabilities (guint32 capabilities) -{ - if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM) - return 10; - return 0; -} - -static void -probe_result (MMPluginBase *base, - MMPluginBaseSupportsTask *task, - guint32 capabilities, - gpointer user_data) -{ - mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities)); -} - -static MMPluginSupportsResult -supports_port (MMPluginBase *base, - MMModem *existing, - MMPluginBaseSupportsTask *task) -{ - GUdevDevice *port; - const char *driver, *subsys, *name; - guint16 vendor = 0, product = 0; - - /* Can't do anything with non-serial ports */ - port = mm_plugin_base_supports_task_get_port (task); - if (strcmp (g_udev_device_get_subsystem (port), "tty")) - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - - subsys = g_udev_device_get_subsystem (port); - name = g_udev_device_get_name (port); - - driver = mm_plugin_base_supports_task_get_driver (task); - if (!driver || (strcmp (driver, "option1") && strcmp (driver, "option") && strcmp (driver, "nozomi"))) - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - - if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - - if ( (vendor != 0x0af0) /* Option USB devices */ - && (vendor != 0x1931 || product != 0x000c)) /* Nozomi CardBus devices */ - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - - /* Check if a previous probing was already launched in this port */ - if (mm_plugin_base_supports_task_propagate_cached (task)) { - guint32 level; - - /* A previous probing was already done, use its results */ - level = get_level_for_capabilities (mm_plugin_base_supports_task_get_probed_capabilities (task)); - if (level) { - mm_plugin_base_supports_task_complete (task, level); - return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; - } - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; - } - - /* Otherwise kick off a probe */ - if (mm_plugin_base_probe_port (base, task, 0, NULL)) - return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; - - return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; -} - -static MMModem * -grab_port (MMPluginBase *base, - MMModem *existing, - MMPluginBaseSupportsTask *task, - GError **error) -{ - GUdevDevice *port = NULL; - MMModem *modem = NULL; - const char *name, *subsys, *devfile, *sysfs_path; - guint32 caps; - int usbif; - MMPortType ptype; - MMAtPortFlags pflags = MM_AT_PORT_FLAG_NONE; - guint16 vendor = 0, product = 0; - - port = mm_plugin_base_supports_task_get_port (task); - g_assert (port); - - devfile = g_udev_device_get_device_file (port); - if (!devfile) { - g_set_error (error, 0, 0, "Could not get port's sysfs file."); - return NULL; - } - - /* This is the MM equivalent of NM commit 9d7f5b3d084eee2ccfff721c4beca3e3f34bdc50; - * Genuine Option NV devices are always supposed to use USB interface 0 as - * the modem/data port, per mail with Option engineers. Only this port - * will emit responses to dialing commands. - */ - usbif = g_udev_device_get_property_as_int (port, "ID_USB_INTERFACE_NUM"); - if (usbif == 0) - pflags = MM_AT_PORT_FLAG_PRIMARY | MM_AT_PORT_FLAG_PPP; - - subsys = g_udev_device_get_subsystem (port); - name = g_udev_device_get_name (port); - if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { - g_set_error (error, 0, 0, "Could not get modem product ID."); - return NULL; - } - - caps = mm_plugin_base_supports_task_get_probed_capabilities (task); - sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); - ptype = mm_plugin_base_probed_capabilities_to_port_type (caps); - if (!existing) { - if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { - modem = mm_modem_option_new (sysfs_path, - mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base)), - vendor, - product); - } - - if (modem) { - if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) { - g_object_unref (modem); - return NULL; - } - } - } else if (get_level_for_capabilities (caps)) { - modem = existing; - if (!mm_modem_grab_port (modem, subsys, name, ptype, pflags, NULL, error)) - return NULL; - } - - return modem; -} - -/*****************************************************************************/ - -static void -mm_plugin_option_init (MMPluginOption *self) -{ - g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL); -} - -static void -mm_plugin_option_class_init (MMPluginOptionClass *klass) -{ - MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass); - - pb_class->supports_port = supports_port; - pb_class->grab_port = grab_port; -} |