aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Williams <njw@google.com>2012-02-22 08:41:18 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-16 14:53:14 +0100
commit8e640d3adcabac0373ec0ee916bf665d08cbe2f6 (patch)
treea76b837ccda0d64e8410b6f8a9c491294d3c0274
parente992d5cbd1d6bf1d56df6451bd6fdb35d0253c7d (diff)
novatel: new plugin for the Novatel E362
-rw-r--r--plugins/Makefile.am13
-rw-r--r--plugins/novatel/mm-broadband-bearer-novatel.c422
-rw-r--r--plugins/novatel/mm-broadband-bearer-novatel.h60
-rw-r--r--plugins/novatel/mm-broadband-modem-novatel.c452
-rw-r--r--plugins/novatel/mm-broadband-modem-novatel.h50
-rw-r--r--plugins/novatel/mm-plugin-novatel.c111
-rw-r--r--plugins/novatel/mm-plugin-novatel.h47
7 files changed, 1155 insertions, 0 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 8303e2f4..20838a02 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -38,6 +38,7 @@ pkglib_LTLIBRARIES = \
libmm-plugin-nokia.la \
libmm-plugin-gobi.la \
libmm-plugin-motorola.la \
+ libmm-plugin-novatel.la \
libmm-plugin-option.la
#pkglib_LTLIBRARIES = \
@@ -263,6 +264,18 @@ udevrulesdir = $(UDEV_BASE_DIR)/rules.d
udevrules_DATA = \
nokia/77-mm-nokia-port-types.rules
+
+# Novatel modem
+libmm_plugin_novatel_la_SOURCES = \
+ novatel/mm-plugin-novatel.c \
+ novatel/mm-plugin-novatel.h \
+ novatel/mm-broadband-modem-novatel.c \
+ novatel/mm-broadband-modem-novatel.h \
+ novatel/mm-broadband-bearer-novatel.c \
+ novatel/mm-broadband-bearer-novatel.h
+libmm_plugin_novatel_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
+libmm_plugin_novatel_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
+
# 77-mm-ericsson-mbm.rules \
# 77-mm-zte-port-types.rules \
# 77-mm-longcheer-port-types.rules \
diff --git a/plugins/novatel/mm-broadband-bearer-novatel.c b/plugins/novatel/mm-broadband-bearer-novatel.c
new file mode 100644
index 00000000..e519029a
--- /dev/null
+++ b/plugins/novatel/mm-broadband-bearer-novatel.c
@@ -0,0 +1,422 @@
+/* -*- 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 - 2012 Red Hat, Inc.
+ * Copyright (C) 2011 - 2012 Google, Inc.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <ModemManager.h>
+#include <libmm-common.h>
+
+#include "mm-base-modem-at.h"
+#include "mm-broadband-bearer-novatel.h"
+#include "mm-log.h"
+#include "mm-modem-helpers.h"
+#include "mm-utils.h"
+
+G_DEFINE_TYPE (MMBroadbandBearerNovatel, mm_broadband_bearer_novatel, MM_TYPE_BROADBAND_BEARER);
+
+/*****************************************************************************/
+
+typedef struct {
+ MMBroadbandBearer *self;
+ MMBaseModem *modem;
+ MMAtSerialPort *primary;
+ MMPort *data;
+ GCancellable *cancellable;
+ GSimpleAsyncResult *result;
+ int retries;
+} DetailedConnectContext;
+
+static DetailedConnectContext *
+detailed_connect_context_new (MMBroadbandBearer *self,
+ MMBroadbandModem *modem,
+ MMAtSerialPort *primary,
+ MMPort *data,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ DetailedConnectContext *ctx;
+
+ ctx = g_new0 (DetailedConnectContext, 1);
+ ctx->self = g_object_ref (self);
+ ctx->modem = MM_BASE_MODEM (g_object_ref (modem));
+ ctx->primary = g_object_ref (primary);
+ ctx->data = g_object_ref (data);
+ /* NOTE:
+ * We don't currently support cancelling AT commands, so we'll just check
+ * whether the operation is to be cancelled at each step. */
+ ctx->cancellable = g_object_ref (cancellable);
+ ctx->result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ detailed_connect_context_new);
+ ctx->retries = 4;
+ return ctx;
+}
+
+static void
+detailed_connect_context_complete_and_free (DetailedConnectContext *ctx)
+{
+ g_simple_async_result_complete_in_idle (ctx->result);
+ g_object_unref (ctx->result);
+ g_object_unref (ctx->cancellable);
+ g_object_unref (ctx->data);
+ g_object_unref (ctx->primary);
+ g_object_unref (ctx->modem);
+ g_object_unref (ctx->self);
+ g_free (ctx);
+}
+
+static void
+detailed_connect_context_complete_and_free_successful (DetailedConnectContext *ctx)
+{
+ MMCommonBearerIpConfig *config;
+
+ config = mm_common_bearer_ip_config_new ();
+ mm_common_bearer_ip_config_set_method (config, MM_BEARER_IP_METHOD_DHCP);
+ g_simple_async_result_set_op_res_gpointer (ctx->result,
+ config,
+ (GDestroyNotify)g_object_unref);
+ detailed_connect_context_complete_and_free (ctx);
+}
+
+
+static gboolean
+connect_3gpp_finish (MMBroadbandBearer *self,
+ GAsyncResult *res,
+ MMCommonBearerIpConfig **ipv4_config,
+ MMCommonBearerIpConfig **ipv6_config,
+ GError **error)
+{
+ MMCommonBearerIpConfig *config;
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return FALSE;
+
+ config = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+
+ /* In the default implementation, we assume we'll have the same configs */
+ *ipv4_config = g_object_ref (config);
+ *ipv6_config = g_object_ref (config);
+ return TRUE;
+}
+
+static gboolean connect_3gpp_qmistatus (DetailedConnectContext *ctx);
+
+static void
+connect_3gpp_qmistatus_ready (MMBaseModem *modem,
+ GAsyncResult *res,
+ DetailedConnectContext *ctx)
+{
+ const gchar *result;
+ GError *error = NULL;
+
+ result = mm_base_modem_at_command_finish (MM_BASE_MODEM (ctx->modem),
+ res,
+ &error);
+ if (!result) {
+ mm_warn ("QMI connection status failed: %s", error->message);
+ g_simple_async_result_take_error (ctx->result, error);
+ detailed_connect_context_complete_and_free (ctx);
+ return;
+ }
+
+ result = mm_strip_tag (result, "$NWQMISTATUS:");
+ if (g_strrstr(result, "QMI State: CONNECTED")) {
+ mm_dbg("Connected");
+ detailed_connect_context_complete_and_free_successful (ctx);
+ return;
+ } else {
+ mm_dbg("Error: '%s'", result);
+ if (ctx->retries > 0) {
+ ctx->retries--;
+ mm_dbg("Retrying status check in a second. %d retries left.",
+ ctx->retries);
+ g_timeout_add_seconds(1, (GSourceFunc)connect_3gpp_qmistatus, ctx);
+ return;
+ }
+ g_simple_async_result_set_error (ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "%s", result);
+ }
+ detailed_connect_context_complete_and_free (ctx);
+}
+
+static gboolean
+connect_3gpp_qmistatus (DetailedConnectContext *ctx)
+{
+ mm_base_modem_at_command (
+ ctx->modem,
+ "$NWQMISTATUS",
+ 3, /* timeout */
+ FALSE, /* allow_cached */
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)connect_3gpp_qmistatus_ready, /* callback */
+ ctx); /* user_data */
+
+ return FALSE;
+}
+
+static void
+connect_3gpp_qmiconnect_ready (MMBaseModem *modem,
+ GAsyncResult *res,
+ DetailedConnectContext *ctx)
+{
+ const gchar *result;
+ GError *error = NULL;
+
+ result = mm_base_modem_at_command_finish (MM_BASE_MODEM (modem),
+ res,
+ &error);
+ if (!result) {
+ mm_warn ("QMI connection failed: %s", error->message);
+ g_simple_async_result_take_error (ctx->result, error);
+ detailed_connect_context_complete_and_free (ctx);
+ return;
+ }
+
+ /*
+ * The connection takes a bit of time to set up, but there's no
+ * asynchronous notification from the modem when this has
+ * happened. Instead, we need to poll the modem to see if it's
+ * ready.
+ */
+ g_timeout_add_seconds(1, (GSourceFunc)connect_3gpp_qmistatus, ctx);
+}
+
+static void
+connect_3gpp (MMBroadbandBearer *self,
+ MMBroadbandModem *modem,
+ MMAtSerialPort *primary,
+ MMAtSerialPort *secondary,
+ MMPort *data,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ DetailedConnectContext *ctx;
+
+ ctx = detailed_connect_context_new (self,
+ modem,
+ primary,
+ data,
+ cancellable,
+ callback,
+ user_data);
+
+ mm_base_modem_at_command (
+ ctx->modem,
+ "$NWQMICONNECT=,,,,,,,,,,",
+ 10, /* timeout */
+ FALSE, /* allow_cached */
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)connect_3gpp_qmiconnect_ready,
+ ctx); /* user_data */
+}
+
+
+typedef struct {
+ MMBroadbandBearer *self;
+ MMBaseModem *modem;
+ MMAtSerialPort *primary;
+ MMAtSerialPort *secondary;
+ MMPort *data;
+ GSimpleAsyncResult *result;
+} DetailedDisconnectContext;
+
+
+static DetailedDisconnectContext *
+detailed_disconnect_context_new (MMBroadbandBearer *self,
+ MMBroadbandModem *modem,
+ MMAtSerialPort *primary,
+ MMAtSerialPort *secondary,
+ MMPort *data,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ DetailedDisconnectContext *ctx;
+
+ ctx = g_new0 (DetailedDisconnectContext, 1);
+ ctx->self = g_object_ref (self);
+ ctx->modem = MM_BASE_MODEM (g_object_ref (modem));
+ ctx->primary = g_object_ref (primary);
+ ctx->secondary = (secondary ? g_object_ref (secondary) : NULL);
+ ctx->data = g_object_ref (data);
+ ctx->result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ detailed_disconnect_context_new);
+ return ctx;
+}
+
+static void
+detailed_disconnect_context_complete_and_free (DetailedDisconnectContext *ctx)
+{
+ g_simple_async_result_complete_in_idle (ctx->result);
+ g_object_unref (ctx->result);
+ g_object_unref (ctx->data);
+ if (ctx->secondary)
+ g_object_unref (ctx->secondary);
+ g_object_unref (ctx->primary);
+ g_object_unref (ctx->modem);
+ g_object_unref (ctx->self);
+ g_free (ctx);
+}
+
+static gboolean
+disconnect_3gpp_finish (MMBroadbandBearer *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+disconnect_3gpp_status_complete (MMBaseModem *modem,
+ GAsyncResult *res,
+ DetailedDisconnectContext *ctx)
+{
+ const gchar *result;
+ GError *error = NULL;
+
+ result = mm_base_modem_at_command_finish (MM_BASE_MODEM (modem),
+ res,
+ &error);
+
+ g_simple_async_result_set_op_res_gboolean (ctx->result, FALSE);
+ if (error) {
+ mm_dbg("QMI connection status failed: %s", error->message);
+ g_error_free (error);
+ }
+
+ result = mm_strip_tag (result, "$NWQMISTATUS:");
+ if (g_strrstr(result, "QMI State: DISCONNECTED"))
+ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
+
+ detailed_disconnect_context_complete_and_free (ctx);
+}
+
+
+static void
+disconnect_3gpp_check_status (MMBaseModem *modem,
+ GAsyncResult *res,
+ DetailedDisconnectContext *ctx)
+{
+ GError *error = NULL;
+
+ mm_base_modem_at_command_finish (MM_BASE_MODEM (modem),
+ res,
+ &error);
+ if (error) {
+ mm_dbg("Disconnection error: %s", error->message);
+ g_error_free (error);
+ }
+
+ mm_base_modem_at_command (
+ ctx->modem,
+ "$NWQMISTATUS",
+ 3, /* timeout */
+ FALSE, /* allow_cached */
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)disconnect_3gpp_status_complete,
+ ctx); /* user_data */
+}
+
+static void
+disconnect_3gpp (MMBroadbandBearer *self,
+ MMBroadbandModem *modem,
+ MMAtSerialPort *primary,
+ MMAtSerialPort *secondary,
+ MMPort *data,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ DetailedDisconnectContext *ctx;
+
+ ctx = detailed_disconnect_context_new (self, modem, primary, secondary,
+ data, callback, user_data);
+
+ mm_base_modem_at_command (
+ ctx->modem,
+ "$NWQMIDISCONNECT",
+ 10, /* timeout */
+ FALSE, /* allow_cached */
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)disconnect_3gpp_check_status,
+ ctx); /* user_data */
+}
+
+
+static void
+mm_broadband_bearer_novatel_init (MMBroadbandBearerNovatel *self)
+{
+}
+
+static void
+mm_broadband_bearer_novatel_class_init (MMBroadbandBearerNovatelClass *klass)
+{
+ MMBroadbandBearerClass *bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
+
+ bearer_class->connect_3gpp = connect_3gpp;
+ bearer_class->connect_3gpp_finish = connect_3gpp_finish;
+
+ bearer_class->disconnect_3gpp = disconnect_3gpp;
+ bearer_class->disconnect_3gpp_finish = disconnect_3gpp_finish;
+}
+
+MMBearer *
+mm_broadband_bearer_novatel_new_finish (GAsyncResult *res,
+ GError **error)
+{
+ GObject *bearer;
+ GObject *source;
+
+ source = g_async_result_get_source_object (res);
+ bearer = g_async_initable_new_finish (G_ASYNC_INITABLE (source), res, error);
+ g_object_unref (source);
+
+ if (!bearer)
+ return NULL;
+
+ /* Only export valid bearers */
+ mm_bearer_export (MM_BEARER (bearer));
+
+ return MM_BEARER (bearer);
+}
+
+void mm_broadband_bearer_novatel_new (MMBroadbandModemNovatel *modem,
+ MMCommonBearerProperties *properties,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_async_initable_new_async (
+ MM_TYPE_BROADBAND_BEARER_NOVATEL,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ callback,
+ user_data,
+ MM_BEARER_MODEM, modem,
+ NULL);
+}
diff --git a/plugins/novatel/mm-broadband-bearer-novatel.h b/plugins/novatel/mm-broadband-bearer-novatel.h
new file mode 100644
index 00000000..228362e0
--- /dev/null
+++ b/plugins/novatel/mm-broadband-bearer-novatel.h
@@ -0,0 +1,60 @@
+/* -*- 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:
+ *
+ * Author: Nathan Williams <njw@google.com>
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#ifndef MM_BROADBAND_BEARER_NOVATEL_H
+#define MM_BROADBAND_BEARER_NOVATEL_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <libmm-common.h>
+
+#include "mm-broadband-bearer.h"
+#include "mm-broadband-modem-novatel.h"
+
+#define MM_TYPE_BROADBAND_BEARER_NOVATEL (mm_broadband_bearer_novatel_get_type ())
+#define MM_BROADBAND_BEARER_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_BEARER_NOVATEL, MMBroadbandBearerNovatel))
+#define MM_BROADBAND_BEARER_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_BEARER_NOVATEL, MMBroadbandBearerNovatelClass))
+#define MM_IS_BROADBAND_BEARER_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_BEARER_NOVATEL))
+#define MM_IS_BROADBAND_BEARER_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_BEARER_NOVATEL))
+#define MM_BROADBAND_BEARER_NOVATEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_BEARER_NOVATEL, MMBroadbandBearerNovatelClass))
+
+typedef struct _MMBroadbandBearerNovatel MMBroadbandBearerNovatel;
+typedef struct _MMBroadbandBearerNovatelClass MMBroadbandBearerNovatelClass;
+typedef struct _MMBroadbandBearerNovatelPrivate MMBroadbandBearerNovatelPrivate;
+
+struct _MMBroadbandBearerNovatel {
+ MMBroadbandBearer parent;
+};
+
+struct _MMBroadbandBearerNovatelClass {
+ MMBroadbandBearerClass parent;
+};
+
+GType mm_broadband_bearer_novatel_get_type (void);
+
+/* Default 3GPP bearer creation implementation */
+void mm_broadband_bearer_novatel_new (MMBroadbandModemNovatel *modem,
+ MMCommonBearerProperties *properties,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMBearer *mm_broadband_bearer_novatel_new_finish (GAsyncResult *res,
+ GError **error);
+
+
+#endif /* MM_BROADBAND_BEARER_NOVATEL_H */
diff --git a/plugins/novatel/mm-broadband-modem-novatel.c b/plugins/novatel/mm-broadband-modem-novatel.c
new file mode 100644
index 00000000..8135c306
--- /dev/null
+++ b/plugins/novatel/mm-broadband-modem-novatel.c
@@ -0,0 +1,452 @@
+/* -*- 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) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+
+#include "ModemManager.h"
+#include "mm-base-modem-at.h"
+#include "mm-broadband-bearer-novatel.h"
+#include "mm-broadband-modem-novatel.h"
+#include "mm-errors-types.h"
+#include "mm-iface-modem.h"
+#include "mm-log.h"
+#include "mm-modem-helpers.h"
+#include "mm-serial-parsers.h"
+
+
+/*****************************************************************************/
+/* Create Bearer (Modem interface) */
+
+static MMBearer *
+modem_create_bearer_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ MMBearer *bearer;
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return NULL;
+
+ bearer = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+
+ return g_object_ref (bearer);
+}
+
+static void
+broadband_bearer_new_ready (GObject *source,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ MMBearer *bearer = NULL;
+ GError *error = NULL;
+
+ bearer = mm_broadband_bearer_novatel_new_finish (res, &error);
+ if (!bearer)
+ g_simple_async_result_take_error (simple, error);
+ else
+ g_simple_async_result_set_op_res_gpointer (simple,
+ bearer,
+ (GDestroyNotify)g_object_unref);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+modem_create_bearer (MMIfaceModem *self,
+ MMCommonBearerProperties *properties,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ /* Set a new ref to the bearer object as result */
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ modem_create_bearer);
+
+ /* We just create a MMBroadbandBearer */
+ mm_broadband_bearer_novatel_new (MM_BROADBAND_MODEM_NOVATEL (self),
+ properties,
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)broadband_bearer_new_ready,
+ result);
+}
+
+static void iface_modem_init (MMIfaceModem *iface);
+
+G_DEFINE_TYPE_EXTENDED (MMBroadbandModemNovatel, mm_broadband_modem_novatel, MM_TYPE_BROADBAND_MODEM, 0,
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init));
+
+MMBroadbandModemNovatel *
+mm_broadband_modem_novatel_new (const gchar *device,
+ const gchar *driver,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id)
+{
+ return g_object_new (MM_TYPE_BROADBAND_MODEM_NOVATEL,
+ MM_BASE_MODEM_DEVICE, device,
+ MM_BASE_MODEM_DRIVER, driver,
+ MM_BASE_MODEM_PLUGIN, plugin,
+ MM_BASE_MODEM_VENDOR_ID, vendor_id,
+ MM_BASE_MODEM_PRODUCT_ID, product_id,
+ NULL);
+}
+
+static void
+mm_broadband_modem_novatel_init (MMBroadbandModemNovatel *self)
+{
+}
+
+/*****************************************************************************/
+/* SUPPORTED MODES */
+
+static MMModemMode
+load_supported_modes_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
+ return MM_MODEM_MODE_NONE;
+
+ return (MMModemMode) GPOINTER_TO_UINT (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+supported_networks_query_ready (MMBroadbandModemNovatel *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ const gchar *response;
+ GError *error = NULL;
+ MMModemMode mode;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ /* Let the error be critical. */
+ g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+ return;
+ }
+
+ /*
+ * More than one numeric ID may appear in the list, that's why
+ * they are checked separately.
+ */
+
+ mode = MM_MODEM_MODE_NONE;
+
+ if (strstr (response, "12") != NULL) {
+ mm_dbg ("Device allows 2G-only network mode");
+ mode |= MM_MODEM_MODE_2G;
+ }
+
+ if (strstr (response, "22") != NULL) {
+ mm_dbg ("Device allows 3G-only network mode");
+ mode |= MM_MODEM_MODE_3G;
+ }
+
+ if (strstr (response, "25") != NULL) {
+ mm_dbg ("Device allows 2G/3G/4G network mode");
+ mode |= (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G | MM_MODEM_MODE_4G);
+ }
+
+ /* If no expected ID found, error */
+ if (mode == MM_MODEM_MODE_NONE)
+ g_simple_async_result_set_error (operation_result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Invalid list of supported networks: '%s'",
+ response);
+ else
+ g_simple_async_result_set_op_res_gpointer (operation_result,
+ GUINT_TO_POINTER (mode),
+ NULL);
+
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+load_supported_modes (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_supported_modes);
+
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "+WS46=?",
+ 3,
+ FALSE,
+ NULL, /* cancellable */
+ (GAsyncReadyCallback)supported_networks_query_ready,
+ result);
+}
+
+
+/*****************************************************************************/
+/* SUPPORTED BANDS */
+
+/*
+ * Mapping from bits set in response of $NWBAND? command to MMModemBand values.
+ * The bit positions and band names on the right come from the response to $NWBAND=?
+ */
+static MMModemBand bandbits[] = {
+ MM_MODEM_BAND_CDMA_BC0_CELLULAR_800, /* "00 CDMA2000 Band Class 0, A-System" */
+ MM_MODEM_BAND_CDMA_BC0_CELLULAR_800, /* "01 CDMA2000 Band Class 0, B-System" */
+ MM_MODEM_BAND_CDMA_BC1_PCS_1900, /* "02 CDMA2000 Band Class 1, all blocks" */
+ MM_MODEM_BAND_CDMA_BC2_TACS, /* "03 CDMA2000 Band Class 2, place holder" */
+ MM_MODEM_BAND_CDMA_BC3_JTACS, /* "04 CDMA2000 Band Class 3, A-System" */
+ MM_MODEM_BAND_CDMA_BC4_KOREAN_PCS, /* "05 CDMA2000 Band Class 4, all blocks" */
+ MM_MODEM_BAND_CDMA_BC5_NMT450, /* "06 CDMA2000 Band Class 5, all blocks" */
+ MM_MODEM_BAND_DCS, /* "07 GSM DCS band" */
+ MM_MODEM_BAND_EGSM, /* "08 GSM Extended GSM (E-GSM) band" */
+ MM_MODEM_BAND_UNKNOWN, /* "09 GSM Primary GSM (P-GSM) band" */
+ MM_MODEM_BAND_CDMA_BC6_IMT2000, /* "10 CDMA2000 Band Class 6" */
+ MM_MODEM_BAND_CDMA_BC7_CELLULAR_700, /* "11 CDMA2000 Band Class 7" */
+ MM_MODEM_BAND_CDMA_BC8_1800, /* "12 CDMA2000 Band Class 8" */
+ MM_MODEM_BAND_CDMA_BC9_900, /* "13 CDMA2000 Band Class 9" */
+ MM_MODEM_BAND_CDMA_BC10_SECONDARY_800, /* "14 CDMA2000 Band Class 10 */
+ MM_MODEM_BAND_CDMA_BC11_PAMR_400, /* "15 CDMA2000 Band Class 11 */
+ MM_MODEM_BAND_UNKNOWN, /* "16 GSM 450 band" */
+ MM_MODEM_BAND_UNKNOWN, /* "17 GSM 480 band" */
+ MM_MODEM_BAND_UNKNOWN, /* "18 GSM 750 band" */
+ MM_MODEM_BAND_G850, /* "19 GSM 850 band" */
+ MM_MODEM_BAND_UNKNOWN, /* "20 GSM band" */
+ MM_MODEM_BAND_PCS, /* "21 GSM PCS band" */
+ MM_MODEM_BAND_U2100, /* "22 WCDMA I IMT 2000 band" */
+ MM_MODEM_BAND_U1900, /* "23 WCDMA II PCS band" */
+ MM_MODEM_BAND_U1800, /* "24 WCDMA III 1700 band" */
+ MM_MODEM_BAND_U17IV, /* "25 WCDMA IV 1700 band" */
+ MM_MODEM_BAND_U850, /* "26 WCDMA V US850 band" */
+ MM_MODEM_BAND_U800, /* "27 WCDMA VI JAPAN 800 band" */
+ MM_MODEM_BAND_UNKNOWN, /* "28 Reserved for BC12/BC14 */
+ MM_MODEM_BAND_UNKNOWN, /* "29 Reserved for BC12/BC14 */
+ MM_MODEM_BAND_UNKNOWN, /* "30 Reserved" */
+ MM_MODEM_BAND_UNKNOWN, /* "31 Reserved" */
+};
+
+static GArray *
+load_supported_bands_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ /* Never fails */
+ return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+load_supported_bands (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GArray *bands;
+ guint i;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_supported_bands);
+
+ /*
+ * The modem doesn't support telling us what bands are supported;
+ * list everything we know about.
+ */
+ bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 23);
+ for (i = 0 ; i < G_N_ELEMENTS (bandbits) ; i++) {
+ if (bandbits[i] != MM_MODEM_BAND_UNKNOWN)
+ g_array_append_val(bands, bandbits[i]);
+ }
+
+ g_simple_async_result_set_op_res_gpointer (result,
+ bands,
+ (GDestroyNotify)g_array_unref);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+
+static GArray *
+load_current_bands_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ /* Never fails */
+ return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
+ G_SIMPLE_ASYNC_RESULT (res)));
+}
+
+static void
+load_current_bands_done (MMIfaceModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ GArray *bands;
+ const gchar *response;
+ GError *error = NULL;
+ guint i;
+ guint32 bandval;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ mm_dbg ("Couldn't query supported bands: '%s'", error->message);
+ g_simple_async_result_take_error (operation_result, error);
+ g_simple_async_result_complete_in_idle (operation_result);
+ g_object_unref (operation_result);
+ return;
+ }
+
+ /*
+ * Response is "$NWBAND: <hex value>", where the hex value is a
+ * bitmask of supported bands.
+ */
+ bandval = (guint32)strtoul(response + 9, NULL, 16);
+
+ bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 4);
+ for (i = 0 ; i < G_N_ELEMENTS (bandbits) ; i++) {
+ if ((bandval & (1 << i)) && bandbits[i] != MM_MODEM_BAND_UNKNOWN)
+ g_array_append_val(bands, bandbits[i]);
+ }
+
+ g_simple_async_result_set_op_res_gpointer (operation_result,
+ bands,
+ (GDestroyNotify)g_array_unref);
+ g_simple_async_result_complete_in_idle (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+load_current_bands (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ load_current_bands);
+
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "$NWBAND?",
+ 3,
+ FALSE,
+ NULL,
+ (GAsyncReadyCallback)load_current_bands_done,
+ result);
+}
+
+static gboolean
+set_bands_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+}
+
+static void
+set_bands_done (MMIfaceModem *self,
+ GAsyncResult *res,
+ GSimpleAsyncResult *operation_result)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error))
+ g_simple_async_result_take_error (operation_result, error);
+ else
+ g_simple_async_result_set_op_res_gboolean (operation_result, TRUE);
+
+ g_simple_async_result_complete (operation_result);
+ g_object_unref (operation_result);
+}
+
+static void
+set_bands (MMIfaceModem *self,
+ GArray *bands_array,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ gchar *cmd;
+ guint32 bandval;
+ guint i, j;
+
+ result = g_simple_async_result_new (G_OBJECT (self),
+ callback,
+ user_data,
+ set_bands);
+
+ bandval = 0;
+ for (i = 0 ; i < bands_array->len ; i++) {
+ MMModemBand band = g_array_index (bands_array, MMModemBand, i);
+ for (j = 0 ; j < G_N_ELEMENTS (bandbits) ; j++) {
+ if (bandbits[j] == band ||
+ (band == MM_MODEM_BAND_ANY && bandbits[j] != MM_MODEM_BAND_UNKNOWN))
+ bandval |= 1 << j;
+ }
+ }
+
+ cmd = g_strdup_printf ("$NWBAND=%x", bandval);
+
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ cmd,
+ 3,
+ FALSE,
+ NULL,
+ (GAsyncReadyCallback)set_bands_done,
+ result);
+
+ g_free (cmd);
+}
+
+static void
+iface_modem_init (MMIfaceModem *iface)
+{
+ iface->create_bearer = modem_create_bearer;
+ iface->create_bearer_finish = modem_create_bearer_finish;
+ iface->load_supported_modes = load_supported_modes;
+ iface->load_supported_modes_finish = load_supported_modes_finish;
+ iface->load_supported_bands = load_supported_bands;
+ iface->load_supported_bands_finish = load_supported_bands_finish;
+ iface->load_current_bands = load_current_bands;
+ iface->load_current_bands_finish = load_current_bands_finish;
+ iface->set_bands = set_bands;
+ iface->set_bands_finish = set_bands_finish;
+}
+
+static void
+mm_broadband_modem_novatel_class_init (MMBroadbandModemNovatelClass *klass)
+{
+}
diff --git a/plugins/novatel/mm-broadband-modem-novatel.h b/plugins/novatel/mm-broadband-modem-novatel.h
new file mode 100644
index 00000000..67d51236
--- /dev/null
+++ b/plugins/novatel/mm-broadband-modem-novatel.h
@@ -0,0 +1,50 @@
+/* -*- 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) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#ifndef MM_BROADBAND_MODEM_NOVATEL_H
+#define MM_BROADBAND_MODEM_NOVATEL_H
+
+#include "mm-broadband-modem.h"
+
+#define MM_TYPE_BROADBAND_MODEM_NOVATEL (mm_broadband_modem_novatel_get_type ())
+#define MM_BROADBAND_MODEM_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_NOVATEL, MMBroadbandModemNovatel))
+#define MM_BROADBAND_MODEM_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_NOVATEL_AIRLINK, MMBroadbandModemNovatelClass))
+#define MM_IS_BROADBAND_MODEM_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_NOVATEL_AIRLINK))
+#define MM_IS_BROADBAND_MODEM_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_NOVATEL_AIRLINK))
+#define MM_BROADBAND_MODEM_NOVATEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_NOVATEL_AIRLINK, MMBroadbandModemNovatelClass))
+
+typedef struct _MMBroadbandModemNovatel MMBroadbandModemNovatel;
+typedef struct _MMBroadbandModemNovatelClass MMBroadbandModemNovatelClass;
+typedef struct _MMBroadbandModemNovatelPrivate MMBroadbandModemNovatelPrivate;
+
+struct _MMBroadbandModemNovatel {
+ MMBroadbandModem parent;
+ MMBroadbandModemNovatelPrivate *priv;
+};
+
+struct _MMBroadbandModemNovatelClass{
+ MMBroadbandModemClass parent;
+};
+
+GType mm_broadband_modem_novatel_get_type (void);
+
+MMBroadbandModemNovatel *mm_broadband_modem_novatel_new (const gchar *device,
+ const gchar *driver,
+ const gchar *plugin,
+ guint16 vendor_id,
+ guint16 product_id);
+
+#endif /* MM_BROADBAND_MODEM_NOVATEL_H */
diff --git a/plugins/novatel/mm-plugin-novatel.c b/plugins/novatel/mm-plugin-novatel.c
new file mode 100644
index 00000000..10fa6a6b
--- /dev/null
+++ b/plugins/novatel/mm-plugin-novatel.c
@@ -0,0 +1,111 @@
+/* -*- 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#include <string.h>
+#include <gmodule.h>
+
+#include "mm-plugin-novatel.h"
+#include "mm-private-boxed-types.h"
+#include "mm-broadband-modem-novatel.h"
+#include "mm-log.h"
+
+G_DEFINE_TYPE (MMPluginNovatel, mm_plugin_novatel, MM_TYPE_PLUGIN_BASE)
+
+int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
+int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
+
+static MMBaseModem *
+grab_port (MMPluginBase *base,
+ MMBaseModem *existing,
+ MMPortProbe *probe,
+ GError **error)
+{
+ MMBaseModem *modem = NULL;
+ const gchar *name, *subsys, *driver;
+ guint16 vendor = 0, product = 0;
+
+ /* The Novatel plugin uses AT and net ports */
+ if (!mm_port_probe_is_at (probe) &&
+ !g_str_equal (mm_port_probe_get_port_subsys (probe), "net")) {
+ g_set_error (error, 0, 0, "Ignoring non-AT/net port");
+ return NULL;
+ }
+
+ subsys = mm_port_probe_get_port_subsys (probe);
+ name = mm_port_probe_get_port_name (probe);
+ driver = mm_port_probe_get_port_driver (probe);
+
+ /* Try to get Product IDs from udev. */
+ mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product);
+
+ /* If this is the first port being grabbed, create a new modem object */
+ if (!existing)
+ modem = MM_BASE_MODEM (mm_broadband_modem_novatel_new (mm_port_probe_get_port_physdev (probe),
+ driver,
+ mm_plugin_get_name (MM_PLUGIN (base)),
+ vendor,
+ product));
+
+ if (!mm_base_modem_grab_port (existing ? existing : modem,
+ subsys,
+ name,
+ mm_port_probe_get_port_type (probe),
+ MM_AT_PORT_FLAG_NONE,
+ error)) {
+ if (modem)
+ g_object_unref (modem);
+ return NULL;
+ }
+
+ return existing ? existing : modem;
+}
+
+/*****************************************************************************/
+
+G_MODULE_EXPORT MMPlugin *
+mm_plugin_create (void)
+{
+ static const gchar *subsystems[] = { "tty", "net", NULL };
+ static const mm_uint16_pair products[] = { { 0x1410, 0x9010 }, /* Novatel E362 */
+ {0, 0} };
+
+ return MM_PLUGIN (
+ g_object_new (MM_TYPE_PLUGIN_NOVATEL,
+ MM_PLUGIN_BASE_NAME, "Novatel",
+ MM_PLUGIN_BASE_ALLOWED_SUBSYSTEMS, subsystems,
+ MM_PLUGIN_BASE_ALLOWED_PRODUCT_IDS, products,
+ MM_PLUGIN_BASE_ALLOWED_AT, TRUE,
+ NULL));
+}
+
+static void
+mm_plugin_novatel_init (MMPluginNovatel *self)
+{
+}
+
+static void
+mm_plugin_novatel_class_init (MMPluginNovatelClass *klass)
+{
+ MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
+
+ pb_class->grab_port = grab_port;
+}
diff --git a/plugins/novatel/mm-plugin-novatel.h b/plugins/novatel/mm-plugin-novatel.h
new file mode 100644
index 00000000..bffbf3c8
--- /dev/null
+++ b/plugins/novatel/mm-plugin-novatel.h
@@ -0,0 +1,47 @@
+/* -*- 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) 2012 Google Inc.
+ * Author: Nathan Williams <njw@google.com>
+ */
+
+#ifndef MM_PLUGIN_NOVATEL_H
+#define MM_PLUGIN_NOVATEL_H
+
+#include "mm-plugin-base.h"
+
+#define MM_TYPE_PLUGIN_NOVATEL (mm_plugin_novatel_get_type ())
+#define MM_PLUGIN_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_NOVATEL, MMPluginNovatel))
+#define MM_PLUGIN_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_NOVATEL, MMPluginNovatelClass))
+#define MM_IS_PLUGIN_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_NOVATEL))
+#define MM_IS_PLUGIN_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_NOVATEL))
+#define MM_PLUGIN_NOVATEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_NOVATEL, MMPluginNovatelClass))
+
+typedef struct {
+ MMPluginBase parent;
+} MMPluginNovatel;
+
+typedef struct {
+ MMPluginBaseClass parent;
+} MMPluginNovatelClass;
+
+GType mm_plugin_novatel_get_type (void);
+
+G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
+
+#endif /* MM_PLUGIN_NOVATEL_H */