diff options
-rw-r--r-- | plugins/Makefile.am | 4 | ||||
-rw-r--r-- | plugins/mm-modem-hso.c | 13 | ||||
-rw-r--r-- | plugins/mm-modem-novatel-cdma.c | 190 | ||||
-rw-r--r-- | plugins/mm-modem-novatel-cdma.h | 45 | ||||
-rw-r--r-- | plugins/mm-plugin-novatel.c | 12 | ||||
-rw-r--r-- | src/mm-generic-cdma.c | 30 |
6 files changed, 271 insertions, 23 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index a3613588..4bac31ef 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -169,7 +169,9 @@ libmm_plugin_novatel_la_SOURCES = \ mm-plugin-novatel.c \ mm-plugin-novatel.h \ mm-modem-novatel-gsm.c \ - mm-modem-novatel-gsm.h + mm-modem-novatel-gsm.h \ + mm-modem-novatel-cdma.c \ + mm-modem-novatel-cdma.h libmm_plugin_novatel_la_CPPFLAGS = \ $(MM_CFLAGS) \ diff --git a/plugins/mm-modem-hso.c b/plugins/mm-modem-hso.c index 4fe6fd03..8a7ffdbb 100644 --- a/plugins/mm-modem-hso.c +++ b/plugins/mm-modem-hso.c @@ -141,8 +141,10 @@ _internal_hso_modem_authenticate (MMModemHso *self, MMCallbackInfo *info) g_assert (primary); cid = hso_get_cid (self); + g_warn_if_fail (cid >= 0); - if (!priv->username && !priv->password) + /* 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\"", @@ -367,14 +369,13 @@ do_connect (MMModem *modem, gpointer user_data) { MMModemHso *self = MM_MODEM_HSO (modem); - MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self); - MMCallbackInfo *info; + MMCallbackInfo *auth_info, *connect_info; mm_modem_set_state (modem, MM_MODEM_STATE_CONNECTING, MM_MODEM_STATE_REASON_NONE); - info = mm_callback_info_new (modem, callback, user_data); - - mm_hso_modem_authenticate (self, priv->username, priv->password, connect_auth_done, info); + 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); } /*****************************************************************************/ diff --git a/plugins/mm-modem-novatel-cdma.c b/plugins/mm-modem-novatel-cdma.c new file mode 100644 index 00000000..c578d18b --- /dev/null +++ b/plugins/mm-modem-novatel-cdma.c @@ -0,0 +1,190 @@ +/* -*- 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 - 2010 Red Hat, Inc. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <ctype.h> + +#include "mm-modem-novatel-cdma.h" +#include "mm-errors.h" +#include "mm-callback-info.h" + +static void modem_cdma_init (MMModemCdma *cdma_class); + +G_DEFINE_TYPE_EXTENDED (MMModemNovatelCdma, mm_modem_novatel_cdma, MM_TYPE_GENERIC_CDMA, 0, + G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_CDMA, modem_cdma_init)) + + +MMModem * +mm_modem_novatel_cdma_new (const char *device, + const char *driver, + const char *plugin, + gboolean evdo_rev0, + gboolean evdo_revA) +{ + 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_NOVATEL_CDMA, + MM_MODEM_MASTER_DEVICE, device, + MM_MODEM_DRIVER, driver, + MM_MODEM_PLUGIN, plugin, + MM_GENERIC_CDMA_EVDO_REV0, evdo_rev0, + MM_GENERIC_CDMA_EVDO_REVA, evdo_revA, + NULL)); +} + +/*****************************************************************************/ + +static void +parent_csq_done (MMModem *modem, + guint32 result, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = user_data; + + if (error) + info->error = g_error_copy (error); + else + mm_callback_info_set_result (info, GUINT_TO_POINTER (result), NULL); + mm_callback_info_schedule (info); +} + +static int +get_one_qual (const char *reply, const char *tag) +{ + int qual = -1; + const char *p; + + p = strstr (reply, tag); + if (!p) + return -1; + + /* Skip the tag */ + p += strlen (tag); + + /* Skip spaces */ + while (isspace (*p)) + p++; + if (*p == '-') { + long int dbm; + + errno = 0; + dbm = strtol (p, NULL, 10); + if (dbm < 0 && errno == 0) { + dbm = CLAMP (dbm, -113, -51); + qual = 100 - ((dbm + 51) * 100 / (-113 + 51)); + } + } + + return qual; +} + +static void +get_rssi_done (MMAtSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModemCdma *parent_iface; + int qual; + + info->error = mm_modem_check_removed (info->modem, error); + if (info->error) { + if (info->modem) { + /* Fallback to parent's method */ + g_clear_error (&info->error); + parent_iface = g_type_interface_peek_parent (MM_MODEM_CDMA_GET_INTERFACE (info->modem)); + parent_iface->get_signal_quality (MM_MODEM_CDMA (info->modem), parent_csq_done, info); + } else + mm_callback_info_schedule (info); + + return; + } + + /* Parse the signal quality */ + qual = get_one_qual (response->str, "RX0="); + if (qual < 0) + qual = get_one_qual (response->str, "RX1="); + + if (qual >= 0) { + mm_callback_info_set_result (info, GUINT_TO_POINTER ((guint32) qual), NULL); + mm_generic_cdma_update_cdma1x_quality (MM_GENERIC_CDMA (info->modem), (guint32) qual); + } else { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "%s", "Could not parse signal quality results"); + } + + mm_callback_info_schedule (info); +} + +static void +get_signal_quality (MMModemCdma *modem, + MMModemUIntFn callback, + gpointer user_data) +{ + MMGenericCdma *cdma = MM_GENERIC_CDMA (modem); + MMCallbackInfo *info; + MMAtSerialPort *primary, *secondary, *port; + + port = primary = mm_generic_cdma_get_at_port (cdma, MM_PORT_TYPE_PRIMARY); + secondary = mm_generic_cdma_get_at_port (cdma, MM_PORT_TYPE_SECONDARY); + + info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data); + + if (mm_port_get_connected (MM_PORT (primary))) { + if (!secondary) { + info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_CONNECTED, + "Cannot query signal quality while connected"); + mm_callback_info_schedule (info); + return; + } + + /* Use secondary port if primary is connected */ + port = secondary; + } + + /* Many Novatel CDMA cards don't report CSQ in standard 0 - 31 and the CSQ + * reply doesn't appear to be in positive dBm either; instead try the custom + * Novatel command for it. + */ + mm_at_serial_port_queue_command (port, "$NWRSSI", 3, get_rssi_done, info); +} + +/*****************************************************************************/ + +static void +modem_cdma_init (MMModemCdma *cdma_class) +{ + cdma_class->get_signal_quality = get_signal_quality; +} + +static void +mm_modem_novatel_cdma_init (MMModemNovatelCdma *self) +{ +} + +static void +mm_modem_novatel_cdma_class_init (MMModemNovatelCdmaClass *klass) +{ + mm_modem_novatel_cdma_parent_class = g_type_class_peek_parent (klass); +} + diff --git a/plugins/mm-modem-novatel-cdma.h b/plugins/mm-modem-novatel-cdma.h new file mode 100644 index 00000000..4d38d8ed --- /dev/null +++ b/plugins/mm-modem-novatel-cdma.h @@ -0,0 +1,45 @@ +/* -*- 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 - 2010 Red Hat, Inc. + */ + +#ifndef MM_MODEM_NOVATEL_CDMA_H +#define MM_MODEM_NOVATEL_CDMA_H + +#include "mm-generic-cdma.h" + +#define MM_TYPE_MODEM_NOVATEL_CDMA (mm_modem_novatel_cdma_get_type ()) +#define MM_MODEM_NOVATEL_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_NOVATEL_CDMA, MMModemNovatelCdma)) +#define MM_MODEM_NOVATEL_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_NOVATEL_CDMA, MMModemNovatelCdmaClass)) +#define MM_IS_MODEM_NOVATEL_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_NOVATEL_CDMA)) +#define MM_IS_MODEM_NOVATEL_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_NOVATEL_CDMA)) +#define MM_MODEM_NOVATEL_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_NOVATEL_CDMA, MMModemNovatelCdmaClass)) + +typedef struct { + MMGenericCdma parent; +} MMModemNovatelCdma; + +typedef struct { + MMGenericCdmaClass parent; +} MMModemNovatelCdmaClass; + +GType mm_modem_novatel_cdma_get_type (void); + +MMModem *mm_modem_novatel_cdma_new (const char *device, + const char *driver, + const char *plugin, + gboolean evdo_rev0, + gboolean evdo_revA); + +#endif /* MM_MODEM_NOVATEL_CDMA_H */ diff --git a/plugins/mm-plugin-novatel.c b/plugins/mm-plugin-novatel.c index 48ff7ec7..cd7ee86a 100644 --- a/plugins/mm-plugin-novatel.c +++ b/plugins/mm-plugin-novatel.c @@ -18,7 +18,7 @@ #include <gmodule.h> #include "mm-plugin-novatel.h" #include "mm-modem-novatel-gsm.h" -#include "mm-generic-cdma.h" +#include "mm-modem-novatel-cdma.h" G_DEFINE_TYPE (MMPluginNovatel, mm_plugin_novatel, MM_TYPE_PLUGIN_BASE) @@ -141,11 +141,11 @@ grab_port (MMPluginBase *base, mm_plugin_base_supports_task_get_driver (task), mm_plugin_get_name (MM_PLUGIN (base))); } else if (caps & CAP_CDMA) { - modem = mm_generic_cdma_new (sysfs_path, - mm_plugin_base_supports_task_get_driver (task), - mm_plugin_get_name (MM_PLUGIN (base)), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), - !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); + modem = mm_modem_novatel_cdma_new (sysfs_path, + mm_plugin_base_supports_task_get_driver (task), + mm_plugin_get_name (MM_PLUGIN (base)), + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856), + !!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A)); } if (modem) { diff --git a/src/mm-generic-cdma.c b/src/mm-generic-cdma.c index 4d558c3e..d598f62a 100644 --- a/src/mm-generic-cdma.c +++ b/src/mm-generic-cdma.c @@ -151,9 +151,9 @@ mm_generic_cdma_grab_port (MMGenericCdma *self, if (port && MM_IS_AT_SERIAL_PORT (port)) { g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL); mm_at_serial_port_set_response_parser (MM_AT_SERIAL_PORT (port), - mm_serial_parser_v1_parse, - mm_serial_parser_v1_new (), - mm_serial_parser_v1_destroy); + mm_serial_parser_v1_e1_parse, + mm_serial_parser_v1_e1_new (), + mm_serial_parser_v1_e1_destroy); if (ptype == MM_PORT_TYPE_PRIMARY) { priv->primary = MM_AT_SERIAL_PORT (port); @@ -1612,16 +1612,26 @@ simple_uint_value (guint32 i) return val; } +#define SS_HASH_TAG "simple-get-status" + static void simple_status_got_signal_quality (MMModem *modem, guint32 result, GError *error, gpointer user_data) { - if (error) + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + GHashTable *properties; + + if (error) { + info->error = g_error_copy (error); g_warning ("Error getting signal quality: %s", error->message); - else - g_hash_table_insert ((GHashTable *) user_data, "signal_quality", simple_uint_value (result)); + } else { + properties = (GHashTable *) mm_callback_info_get_data (info, SS_HASH_TAG); + g_hash_table_insert (properties, "signal_quality", simple_uint_value (result)); + } + + mm_callback_info_schedule (info); } static void @@ -1630,7 +1640,7 @@ simple_get_status_invoke (MMCallbackInfo *info) MMModemSimpleGetStatusFn callback = (MMModemSimpleGetStatusFn) info->callback; callback (MM_MODEM_SIMPLE (info->modem), - (GHashTable *) mm_callback_info_get_data (info, "simple-get-status"), + (GHashTable *) mm_callback_info_get_data (info, SS_HASH_TAG), info->error, info->user_data); } @@ -1647,9 +1657,9 @@ simple_get_status (MMModemSimple *simple, G_CALLBACK (callback), user_data); - properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, simple_free_gvalue); - mm_callback_info_set_data (info, "simple-get-status", properties, (GDestroyNotify) g_hash_table_unref); - mm_modem_cdma_get_signal_quality (MM_MODEM_CDMA (simple), simple_status_got_signal_quality, properties); + properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, simple_free_gvalue); + mm_callback_info_set_data (info, SS_HASH_TAG, properties, (GDestroyNotify) g_hash_table_unref); + mm_modem_cdma_get_signal_quality (MM_MODEM_CDMA (simple), simple_status_got_signal_quality, info); } /*****************************************************************************/ |