aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Makefile.am4
-rw-r--r--plugins/mm-modem-huawei-cdma.c288
-rw-r--r--plugins/mm-modem-huawei-cdma.h43
-rw-r--r--plugins/mm-plugin-huawei.c7
4 files changed, 338 insertions, 4 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index b4a74049..a0f6d5a7 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -69,7 +69,9 @@ libmm_plugin_huawei_la_SOURCES = \
mm-plugin-huawei.c \
mm-plugin-huawei.h \
mm-modem-huawei-gsm.c \
- mm-modem-huawei-gsm.h
+ mm-modem-huawei-gsm.h \
+ mm-modem-huawei-cdma.c \
+ mm-modem-huawei-cdma.h
libmm_plugin_huawei_la_CPPFLAGS = \
$(MM_CFLAGS) \
diff --git a/plugins/mm-modem-huawei-cdma.c b/plugins/mm-modem-huawei-cdma.c
new file mode 100644
index 00000000..b52224c3
--- /dev/null
+++ b/plugins/mm-modem-huawei-cdma.c
@@ -0,0 +1,288 @@
+/* -*- 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>
+
+#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
+#include <gudev/gudev.h>
+
+#include "mm-modem-huawei-cdma.h"
+#include "mm-errors.h"
+#include "mm-callback-info.h"
+#include "mm-serial-port.h"
+#include "mm-serial-parsers.h"
+
+static gpointer mm_modem_huawei_cdma_parent_class = NULL;
+
+#define MM_MODEM_HUAWEI_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_HUAWEI_CDMA, MMModemHuaweiCdmaPrivate))
+
+typedef struct {
+} MMModemHuaweiCdmaPrivate;
+
+MMModem *
+mm_modem_huawei_cdma_new (const char *device,
+ const char *driver,
+ const char *plugin)
+{
+ 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_HUAWEI_CDMA,
+ MM_MODEM_MASTER_DEVICE, device,
+ MM_MODEM_DRIVER, driver,
+ MM_MODEM_PLUGIN, plugin,
+ NULL));
+}
+
+/* Unsolicited message handlers */
+
+static void
+handle_signal_quality_change (MMSerialPort *port,
+ GMatchInfo *match_info,
+ gpointer user_data)
+{
+ MMModemHuaweiCdma *self = MM_MODEM_HUAWEI_CDMA (user_data);
+ char *str;
+ long int quality;
+
+ str = g_match_info_fetch (match_info, 1);
+
+ errno = 0;
+ quality = strtol (str, NULL, 10);
+ if (errno == 0) {
+ quality = CLAMP (quality, 0, 100);
+ g_debug ("Signal quality: %zd", quality);
+ mm_generic_cdma_update_signal_quality (MM_GENERIC_CDMA (self), (guint32) quality);
+ }
+ g_free (str);
+}
+
+/*****************************************************************************/
+
+static const char *
+strip_response (const char *resp, const char *cmd)
+{
+ const char *p = resp;
+
+ if (p) {
+ if (!strncmp (p, cmd, strlen (cmd)))
+ p += strlen (cmd);
+ while (*p == ' ')
+ p++;
+ }
+ return p;
+}
+
+static gboolean
+uint_from_match_item (GMatchInfo *match_info, guint32 num, guint32 *val)
+{
+ long int tmp;
+ char *str;
+ gboolean success = FALSE;
+
+ str = g_match_info_fetch (match_info, num);
+ errno = 0;
+ tmp = strtol (str, NULL, 10);
+ if (errno == 0 && tmp >= 0 && tmp <= G_MAXUINT) {
+ *val = (guint32) tmp;
+ success = TRUE;
+ }
+ g_free (str);
+ return success;
+}
+
+static void
+sysinfo_done (MMSerialPort *port,
+ GString *response,
+ GError *error,
+ gpointer user_data)
+{
+ MMCallbackInfo *info = (MMCallbackInfo *) user_data;
+ GRegex *r;
+ GMatchInfo *match_info;
+ const char *reply;
+ gboolean success = FALSE;
+
+ if (error) {
+ info->error = g_error_copy (error);
+ mm_callback_info_schedule (info);
+ return;
+ }
+
+ reply = strip_response (response->str, "^SYSINFO:");
+
+ /* Format is "<srv_status>,<srv_domain>,<roam_status>,<sys_mode>,<sim_state>" */
+ r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ if (!r) {
+ info->error = g_error_new_literal (MM_MODEM_ERROR,
+ MM_MODEM_ERROR_GENERAL,
+ "Could not parse sysinfo results (regex creation failed).");
+ goto done;
+ }
+
+ g_regex_match (r, reply, 0, &match_info);
+g_message ("%s: %d matches", __func__, g_match_info_get_match_count (match_info));
+ if (g_match_info_get_match_count (match_info) >= 5) {
+ MMModemCdmaRegistrationState reg_state;
+ guint32 val = 0;
+
+ /* At this point the generic code already knows we've been registered */
+ reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
+
+ if (uint_from_match_item (match_info, 1, &val)) {
+ if (val == 2) {
+ /* Service available, check roaming state */
+ val = 0;
+ if (uint_from_match_item (match_info, 3, &val)) {
+ if (val == 0)
+ reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
+ else if (val == 1)
+ reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
+ }
+ }
+ }
+
+ /* FIXME: Parse sysmode */
+
+g_message ("%s: reg state %d", __func__, reg_state);
+ mm_callback_info_set_result (info, GUINT_TO_POINTER (reg_state), NULL);
+ success = TRUE;
+ }
+
+done:
+ g_match_info_free (match_info);
+ g_regex_unref (r);
+
+ if (!success && !info->error) {
+ info->error = g_error_new_literal (MM_MODEM_ERROR,
+ MM_MODEM_ERROR_GENERAL,
+ "Could not parse sysinfo results.");
+ }
+
+ mm_callback_info_schedule (info);
+}
+
+static void
+query_registration_state (MMGenericCdma *cdma,
+ MMModemUIntFn callback,
+ gpointer user_data)
+{
+ MMCallbackInfo *info;
+ MMSerialPort *primary, *secondary;
+ GError *error;
+
+ primary = mm_generic_cdma_get_port (cdma, MM_PORT_TYPE_PRIMARY);
+ secondary = mm_generic_cdma_get_port (cdma, MM_PORT_TYPE_SECONDARY);
+
+g_message ("%s: adfasdf", __func__);
+ if (mm_port_get_connected (MM_PORT (primary)) && !secondary) {
+ error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_CONNECTED,
+ "Cannot get query registration state while connected");
+ callback (MM_MODEM (cdma), MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, error, user_data);
+ g_error_free (error);
+ return;
+ }
+
+g_message ("%s: here!", __func__);
+ info = mm_callback_info_uint_new (MM_MODEM (cdma), callback, user_data);
+ mm_serial_port_queue_command (secondary ? secondary : primary,
+ "AT^SYSINFO", 3,
+ sysinfo_done, info);
+}
+
+/*****************************************************************************/
+
+static gboolean
+grab_port (MMModem *modem,
+ const char *subsys,
+ const char *name,
+ MMPortType suggested_type,
+ gpointer user_data,
+ GError **error)
+{
+ MMPort *port = NULL;
+ GRegex *regex;
+
+ port = mm_generic_cdma_grab_port (MM_GENERIC_CDMA (modem), subsys, name, suggested_type, user_data, error);
+ if (port && MM_IS_SERIAL_PORT (port)) {
+ g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
+
+ regex = g_regex_new ("\\r\\n\\^RSSILVL:(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_signal_quality_change, modem, NULL);
+ g_regex_unref (regex);
+ }
+
+ return !!port;
+}
+
+/*****************************************************************************/
+
+static void
+modem_init (MMModem *modem_class)
+{
+ modem_class->grab_port = grab_port;
+}
+
+static void
+mm_modem_huawei_cdma_init (MMModemHuaweiCdma *self)
+{
+}
+
+static void
+mm_modem_huawei_cdma_class_init (MMModemHuaweiCdmaClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ MMGenericCdmaClass *cdma_class = MM_GENERIC_CDMA_CLASS (klass);
+
+ mm_modem_huawei_cdma_parent_class = g_type_class_peek_parent (klass);
+ g_type_class_add_private (object_class, sizeof (MMModemHuaweiCdmaPrivate));
+
+ cdma_class->query_registration_state = query_registration_state;
+}
+
+GType
+mm_modem_huawei_cdma_get_type (void)
+{
+ static GType modem_huawei_cdma_type = 0;
+
+ if (G_UNLIKELY (modem_huawei_cdma_type == 0)) {
+ static const GTypeInfo modem_huawei_cdma_type_info = {
+ sizeof (MMModemHuaweiCdmaClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) mm_modem_huawei_cdma_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (MMModemHuaweiCdma),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) mm_modem_huawei_cdma_init,
+ };
+
+ static const GInterfaceInfo modem_iface_info = {
+ (GInterfaceInitFunc) modem_init
+ };
+
+ modem_huawei_cdma_type = g_type_register_static (MM_TYPE_GENERIC_CDMA, "MMModemHuaweiCdma", &modem_huawei_cdma_type_info, 0);
+ g_type_add_interface_static (modem_huawei_cdma_type, MM_TYPE_MODEM, &modem_iface_info);
+ }
+
+ return modem_huawei_cdma_type;
+}
diff --git a/plugins/mm-modem-huawei-cdma.h b/plugins/mm-modem-huawei-cdma.h
new file mode 100644
index 00000000..04cf0c2a
--- /dev/null
+++ b/plugins/mm-modem-huawei-cdma.h
@@ -0,0 +1,43 @@
+/* -*- 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_HUAWEI_CDMA_H
+#define MM_MODEM_HUAWEI_CDMA_H
+
+#include "mm-generic-cdma.h"
+
+#define MM_TYPE_MODEM_HUAWEI_CDMA (mm_modem_huawei_cdma_get_type ())
+#define MM_MODEM_HUAWEI_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_HUAWEI_CDMA, MMModemHuaweiCdma))
+#define MM_MODEM_HUAWEI_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_HUAWEI_CDMA, MMModemHuaweiCdmaClass))
+#define MM_IS_MODEM_HUAWEI_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_HUAWEI_CDMA))
+#define MM_IS_MODEM_HUAWEI_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_HUAWEI_CDMA))
+#define MM_MODEM_HUAWEI_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_HUAWEI_CDMA, MMModemHuaweiCdmaClass))
+
+typedef struct {
+ MMGenericCdma parent;
+} MMModemHuaweiCdma;
+
+typedef struct {
+ MMGenericCdmaClass parent;
+} MMModemHuaweiCdmaClass;
+
+GType mm_modem_huawei_cdma_get_type (void);
+
+MMModem *mm_modem_huawei_cdma_new (const char *device,
+ const char *driver,
+ const char *plugin);
+
+#endif /* MM_MODEM_HUAWEI_CDMA_H */
diff --git a/plugins/mm-plugin-huawei.c b/plugins/mm-plugin-huawei.c
index 821afef9..bfd4bf43 100644
--- a/plugins/mm-plugin-huawei.c
+++ b/plugins/mm-plugin-huawei.c
@@ -24,6 +24,7 @@
#include "mm-generic-gsm.h"
#include "mm-generic-cdma.h"
#include "mm-modem-huawei-gsm.h"
+#include "mm-modem-huawei-cdma.h"
#include "mm-serial-parsers.h"
G_DEFINE_TYPE (MMPluginHuawei, mm_plugin_huawei, MM_TYPE_PLUGIN_BASE)
@@ -292,9 +293,9 @@ grab_port (MMPluginBase *base,
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)));
+ modem = mm_modem_huawei_cdma_new (sysfs_path,
+ mm_plugin_base_supports_task_get_driver (task),
+ mm_plugin_get_name (MM_PLUGIN (base)));
}
if (modem) {