diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-22 10:38:49 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-23 18:56:21 +0200 |
commit | 69316289e8aaea84cd5c22f940f4e83def1819e4 (patch) | |
tree | a24790766d5723a2322798fefe485b65f999ccd4 /plugins | |
parent | b2ada906b0c39f5b4f74fff9c4167d11faf4f3c7 (diff) |
sierra: start porting the Sierra plugin
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 21 | ||||
-rw-r--r-- | plugins/sierra/mm-plugin-sierra.c | 232 | ||||
-rw-r--r-- | plugins/sierra/mm-plugin-sierra.h | 42 |
3 files changed, 282 insertions, 13 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index f2710014..c63cea39 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -58,7 +58,8 @@ pkglib_LTLIBRARIES = \ libmm-plugin-longcheer.la \ libmm-plugin-x22x.la \ libmm-plugin-pantech.la \ - libmm-plugin-zte.la + libmm-plugin-zte.la \ + libmm-plugin-sierra.la #pkglib_LTLIBRARIES = \ # libmm-plugin-generic.la \ @@ -143,18 +144,12 @@ libmm_plugin_hso_la_SOURCES = \ libmm_plugin_hso_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) libmm_plugin_hso_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -## Sierra -#libmm_plugin_sierra_la_SOURCES = \ -# mm-plugin-sierra.c \ -# mm-plugin-sierra.h \ -# mm-modem-sierra-gsm.c \ -# mm-modem-sierra-gsm.h \ -# mm-modem-sierra-cdma.c \ -# mm-modem-sierra-cdma.h -#libmm_plugin_sierra_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) -#libmm_plugin_sierra_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) -#libmm_plugin_sierra_la_LIBADD = \ -# $(builddir)/libicera-utils.la +# Sierra +libmm_plugin_sierra_la_SOURCES = \ + sierra/mm-plugin-sierra.c \ + sierra/mm-plugin-sierra.h +libmm_plugin_sierra_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS) +libmm_plugin_sierra_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS) # Wavecom (Sierra Airlink) libmm_plugin_wavecom_la_SOURCES = \ diff --git a/plugins/sierra/mm-plugin-sierra.c b/plugins/sierra/mm-plugin-sierra.c new file mode 100644 index 00000000..fea613af --- /dev/null +++ b/plugins/sierra/mm-plugin-sierra.c @@ -0,0 +1,232 @@ +/* -*- 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) 2012 Lanedo GmbH + */ + +#include <string.h> +#include <gmodule.h> + +#include <libmm-common.h> + +#include "mm-log.h" +#include "mm-plugin-sierra.h" +#include "mm-broadband-modem.h" + +G_DEFINE_TYPE (MMPluginSierra, mm_plugin_sierra, MM_TYPE_PLUGIN) + +int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; +int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; + +/*****************************************************************************/ +/* Custom init */ + +#define TAG_SIERRA_APP1_PORT "sierra-app1-port" +#define TAG_SIERRA_APP_PPP_OK "sierra-app-ppp-ok" + +typedef struct { + MMPortProbe *probe; + MMAtSerialPort *port; + GCancellable *cancellable; + GSimpleAsyncResult *result; + guint retries; +} SierraCustomInitContext; + +static void +sierra_custom_init_context_complete_and_free (SierraCustomInitContext *ctx) +{ + g_simple_async_result_complete_in_idle (ctx->result); + + if (ctx->cancellable) + g_object_unref (ctx->cancellable); + g_object_unref (ctx->port); + g_object_unref (ctx->probe); + g_object_unref (ctx->result); + g_slice_free (SierraCustomInitContext, ctx); +} + +static gboolean +sierra_custom_init_finish (MMPortProbe *probe, + GAsyncResult *result, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error); +} + +static void sierra_custom_init_step (SierraCustomInitContext *ctx); + +static void +gcap_ready (MMAtSerialPort *port, + GString *response, + GError *error, + SierraCustomInitContext *ctx) +{ + if (error) { + /* Just retry... */ + sierra_custom_init_step (ctx); + return; + } + + /* A valid reply to +GCAP tells us this is an AT port already */ + mm_port_probe_set_result_at (ctx->probe, TRUE); + + if (strstr (response->str, "APP1")) { + g_object_set_data (G_OBJECT (ctx->probe), TAG_SIERRA_APP1_PORT, GUINT_TO_POINTER (TRUE)); + + /* 885 can handle PPP on the APP ports, leaving the primary port open + * for command and status while connected. Older modems (ie 8775) say + * they can but fail during PPP. + */ + if (strstr (response->str, "C885")) + g_object_set_data (G_OBJECT (ctx->probe), TAG_SIERRA_APP_PPP_OK, GUINT_TO_POINTER (TRUE)); + } + + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + sierra_custom_init_context_complete_and_free (ctx); +} + +static void +sierra_custom_init_step (SierraCustomInitContext *ctx) +{ + /* If cancelled, end */ + if (g_cancellable_is_cancelled (ctx->cancellable)) { + mm_dbg ("(Sierra) no need to keep on running custom init in (%s)", + mm_port_get_device (MM_PORT (ctx->port))); + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_CANCELLED, + "Custom initialization cancelled"); + sierra_custom_init_context_complete_and_free (ctx); + return; + } + + if (ctx->retries == 0) { + mm_dbg ("(Sierra) Couldn't get port type hints"); + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + sierra_custom_init_context_complete_and_free (ctx); + return; + } + + ctx->retries--; + mm_at_serial_port_queue_command ( + ctx->port, + "AT+GCAP", + 3, + ctx->cancellable, + (MMAtSerialResponseFn)gcap_ready, + ctx); +} + +static void +sierra_custom_init (MMPortProbe *probe, + MMAtSerialPort *port, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + SierraCustomInitContext *ctx; + + ctx = g_slice_new (SierraCustomInitContext); + ctx->result = g_simple_async_result_new (G_OBJECT (probe), + callback, + user_data, + sierra_custom_init); + ctx->probe = g_object_ref (probe); + ctx->port = g_object_ref (port); + ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; + ctx->retries = 3; + + sierra_custom_init_step (ctx); +} + +/*****************************************************************************/ + +static MMBaseModem * +create_modem (MMPlugin *self, + const gchar *sysfs_path, + const gchar *driver, + guint16 vendor, + guint16 product, + GList *probes, + GError **error) +{ + return MM_BASE_MODEM (mm_broadband_modem_new (sysfs_path, + driver, + mm_plugin_get_name (self), + vendor, + product)); +} + +static gboolean +grab_port (MMPlugin *self, + MMBaseModem *modem, + MMPortProbe *probe, + GError **error) +{ + MMAtPortFlag pflags = MM_AT_PORT_FLAG_NONE; + MMPortType ptype; + + ptype = mm_port_probe_get_port_type (probe); + + /* Is it a GSM secondary port? */ + if (g_object_get_data (G_OBJECT (probe), TAG_SIERRA_APP1_PORT)) { + if (g_object_get_data (G_OBJECT (probe), TAG_SIERRA_APP_PPP_OK)) + pflags = MM_AT_PORT_FLAG_PPP; + else + pflags = MM_AT_PORT_FLAG_SECONDARY; + } else if (ptype == MM_PORT_TYPE_AT) + pflags = MM_AT_PORT_FLAG_PRIMARY; + + return mm_base_modem_grab_port (modem, + mm_port_probe_get_port_subsys (probe), + mm_port_probe_get_port_name (probe), + ptype, + pflags, + error); +} + +/*****************************************************************************/ + +G_MODULE_EXPORT MMPlugin * +mm_plugin_create (void) +{ + static const gchar *subsystems[] = { "tty", "net", NULL }; + static const gchar *drivers[] = { "sierra", "sierra_net", NULL }; + static const MMAsyncMethod custom_init = { + .async = G_CALLBACK (sierra_custom_init), + .finish = G_CALLBACK (sierra_custom_init_finish), + }; + + return MM_PLUGIN ( + g_object_new (MM_TYPE_PLUGIN_SIERRA, + MM_PLUGIN_NAME, "Sierra", + MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems, + MM_PLUGIN_ALLOWED_DRIVERS, drivers, + MM_PLUGIN_CUSTOM_INIT, &custom_init, + NULL)); +} + +static void +mm_plugin_sierra_init (MMPluginSierra *self) +{ +} + +static void +mm_plugin_sierra_class_init (MMPluginSierraClass *klass) +{ + MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass); + + plugin_class->create_modem = create_modem; + plugin_class->grab_port = grab_port; +} diff --git a/plugins/sierra/mm-plugin-sierra.h b/plugins/sierra/mm-plugin-sierra.h new file mode 100644 index 00000000..59b6e6b9 --- /dev/null +++ b/plugins/sierra/mm-plugin-sierra.h @@ -0,0 +1,42 @@ +/* -*- 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) 2012 Lanedo GmbH + */ + +#ifndef MM_PLUGIN_SIERRA_H +#define MM_PLUGIN_SIERRA_H + +#include "mm-plugin.h" + +#define MM_TYPE_PLUGIN_SIERRA (mm_plugin_sierra_get_type ()) +#define MM_PLUGIN_SIERRA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_SIERRA, MMPluginSierra)) +#define MM_PLUGIN_SIERRA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_SIERRA, MMPluginSierraClass)) +#define MM_IS_PLUGIN_SIERRA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_SIERRA)) +#define MM_IS_PLUGIN_SIERRA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_SIERRA)) +#define MM_PLUGIN_SIERRA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_SIERRA, MMPluginSierraClass)) + +typedef struct { + MMPlugin parent; +} MMPluginSierra; + +typedef struct { + MMPluginClass parent; +} MMPluginSierraClass; + +GType mm_plugin_sierra_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_SIERRA_H */ |