aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTambet Ingo <tambet@gmail.com>2009-04-02 14:48:12 +0300
committerTambet Ingo <tambet@gmail.com>2009-04-02 14:48:12 +0300
commit636fe2921c39293a8e2e121f134a764151b4799e (patch)
treec246bbed75bfdef4c3fe6def1f8689dd116b44f4
parent1ca34cfc0cb126f5f824a10720b6ed24fd1f4a8d (diff)
Implement a plugin for ZTE modems.
Contributed by Jesse Sung (jsung@novell.com).
-rw-r--r--plugins/Makefile.am17
-rw-r--r--plugins/mm-modem-zte.c191
-rw-r--r--plugins/mm-modem-zte.h28
-rw-r--r--plugins/mm-plugin-zte.c148
-rw-r--r--plugins/mm-plugin-zte.h27
5 files changed, 410 insertions, 1 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 393c376d..ed8b2240 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -5,7 +5,8 @@ pkglib_LTLIBRARIES = \
libmm-plugin-option.la \
libmm-plugin-sierra.la \
libmm-plugin-novatel.la \
- libmm-plugin-nokia.la
+ libmm-plugin-nokia.la \
+ libmm-plugin-zte.la
# Huawei
@@ -111,6 +112,20 @@ libmm_plugin_nokia_la_CPPFLAGS = \
libmm_plugin_nokia_la_LDFLAGS = -module -avoid-version
+# Zte
+
+libmm_plugin_zte_la_SOURCES = \
+ mm-modem-zte.c \
+ mm-modem-zte.h \
+ mm-plugin-zte.c \
+ mm-plugin-zte.h
+
+libmm_plugin_zte_la_CPPFLAGS = \
+ $(MM_CFLAGS) \
+ -I$(top_srcdir)/src
+
+libmm_plugin_zte_la_LDFLAGS = -module -avoid-version
+
BUILT_SOURCES = \
mm-modem-gsm-hso-glue.h
diff --git a/plugins/mm-modem-zte.c b/plugins/mm-modem-zte.c
new file mode 100644
index 00000000..2128dc49
--- /dev/null
+++ b/plugins/mm-modem-zte.c
@@ -0,0 +1,191 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "mm-modem-zte.h"
+#include "mm-serial.h"
+#include "mm-errors.h"
+#include "mm-callback-info.h"
+
+static gpointer mm_modem_zte_parent_class = NULL;
+
+MMModem *
+mm_modem_zte_new (const char *data_device,
+ const char *driver)
+{
+ g_return_val_if_fail (data_device != NULL, NULL);
+ g_return_val_if_fail (driver != NULL, NULL);
+
+ return MM_MODEM (g_object_new (MM_TYPE_MODEM_ZTE,
+ MM_SERIAL_DEVICE, data_device,
+ MM_MODEM_DRIVER, driver,
+ NULL));
+}
+
+/*****************************************************************************/
+/* Modem class override functions */
+/*****************************************************************************/
+
+static void
+init_modem_done (MMSerial *serial,
+ GString *response,
+ 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
+pin_check_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);
+ } else
+ /* Finish the initialization */
+ mm_serial_queue_command (MM_SERIAL (modem), "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1;", 10, init_modem_done, info);
+}
+
+static void
+pre_init_done (MMSerial *serial,
+ GString *response,
+ GError *error,
+ gpointer user_data)
+{
+ MMCallbackInfo *info = (MMCallbackInfo *) user_data;
+
+ if (error) {
+ info->error = g_error_copy (error);
+ mm_callback_info_schedule (info);
+ } else {
+ /* Now check the PIN explicitly, zte doesn't seem to report
+ that it needs it otherwise */
+ mm_generic_gsm_check_pin (MM_GENERIC_GSM (info->modem), pin_check_done, info);
+ }
+}
+
+static void
+enable_flash_done (MMSerial *serial, gpointer user_data)
+{
+ mm_serial_queue_command (serial, "E0 V1", 3, pre_init_done, user_data);
+}
+
+static void
+disable_done (MMSerial *serial,
+ GString *response,
+ GError *error,
+ gpointer user_data)
+{
+ mm_serial_close (serial);
+ mm_callback_info_schedule ((MMCallbackInfo *) user_data);
+}
+
+static void
+disable_flash_done (MMSerial *serial, gpointer user_data)
+{
+ mm_serial_queue_command (serial, "+CFUN=0", 5, disable_done, user_data);
+}
+
+static void
+enable (MMModem *modem,
+ gboolean do_enable,
+ MMModemFn callback,
+ gpointer user_data)
+{
+ MMCallbackInfo *info;
+
+ /* First, reset the previously used CID */
+ mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
+
+ info = mm_callback_info_new (modem, callback, user_data);
+
+ if (!do_enable) {
+ if (mm_serial_is_connected (MM_SERIAL (modem)))
+ mm_serial_flash (MM_SERIAL (modem), 1000, disable_flash_done, info);
+ else
+ disable_flash_done (MM_SERIAL (modem), info);
+ } else {
+ if (mm_serial_open (MM_SERIAL (modem), &info->error))
+ mm_serial_flash (MM_SERIAL (modem), 100, enable_flash_done, info);
+
+ if (info->error)
+ mm_callback_info_schedule (info);
+ }
+}
+
+/*****************************************************************************/
+
+static void
+modem_init (MMModem *modem_class)
+{
+ modem_class->enable = enable;
+}
+
+static void
+mm_modem_zte_init (MMModemZte *self)
+{
+ GRegex *regex;
+
+ mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (self), TRUE);
+ g_object_set (G_OBJECT (self), MM_SERIAL_CARRIER_DETECT, FALSE, NULL);
+
+ regex = g_regex_new ("\\r\\n\\+ZUSIMR:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ mm_serial_add_unsolicited_msg_handler (MM_SERIAL (self), regex, NULL, NULL, NULL);
+ g_regex_unref (regex);
+
+ regex = g_regex_new ("\\r\\n\\+ZDONR: (.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ mm_serial_add_unsolicited_msg_handler (MM_SERIAL (self), regex, NULL, NULL, NULL);
+ g_regex_unref (regex);
+
+ regex = g_regex_new ("\\r\\n\\+ZPASR: (.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ mm_serial_add_unsolicited_msg_handler (MM_SERIAL (self), regex, NULL, NULL, NULL);
+ g_regex_unref (regex);
+
+ g_regex_new ("\\r\\n\\+ZEND\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+ mm_serial_add_unsolicited_msg_handler (MM_SERIAL (self), regex, NULL, NULL, NULL);
+ g_regex_unref (regex);
+}
+
+static void
+mm_modem_zte_class_init (MMModemZteClass *klass)
+{
+ mm_modem_zte_parent_class = g_type_class_peek_parent (klass);
+}
+
+GType
+mm_modem_zte_get_type (void)
+{
+ static GType modem_zte_type = 0;
+
+ if (G_UNLIKELY (modem_zte_type == 0)) {
+ static const GTypeInfo modem_zte_type_info = {
+ sizeof (MMModemZteClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) mm_modem_zte_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (MMModemZte),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) mm_modem_zte_init,
+ };
+
+ static const GInterfaceInfo modem_iface_info = {
+ (GInterfaceInitFunc) modem_init
+ };
+
+ modem_zte_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemZte", &modem_zte_type_info, 0);
+ g_type_add_interface_static (modem_zte_type, MM_TYPE_MODEM, &modem_iface_info);
+ }
+
+ return modem_zte_type;
+}
diff --git a/plugins/mm-modem-zte.h b/plugins/mm-modem-zte.h
new file mode 100644
index 00000000..285dc938
--- /dev/null
+++ b/plugins/mm-modem-zte.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#ifndef MM_MODEM_ZTE_H
+#define MM_MODEM_ZTE_H
+
+#include "mm-generic-gsm.h"
+
+#define MM_TYPE_MODEM_ZTE (mm_modem_zte_get_type ())
+#define MM_MODEM_ZTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_ZTE, MMModemZte))
+#define MM_MODEM_ZTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_ZTE, MMModemZteClass))
+#define MM_IS_MODEM_ZTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_ZTE))
+#define MM_IS_MODEM_ZTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_ZTE))
+#define MM_MODEM_ZTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_ZTE, MMModemZteClass))
+
+typedef struct {
+ MMGenericGsm parent;
+} MMModemZte;
+
+typedef struct {
+ MMGenericGsmClass parent;
+} MMModemZteClass;
+
+GType mm_modem_zte_get_type (void);
+
+MMModem *mm_modem_zte_new (const char *data_device,
+ const char *driver);
+
+#endif /* MM_MODEM_ZTE_H */
diff --git a/plugins/mm-plugin-zte.c b/plugins/mm-plugin-zte.c
new file mode 100644
index 00000000..29e90ab9
--- /dev/null
+++ b/plugins/mm-plugin-zte.c
@@ -0,0 +1,148 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#include <string.h>
+#include <gmodule.h>
+#include "mm-plugin-zte.h"
+#include "mm-modem-zte.h"
+
+static void plugin_init (MMPlugin *plugin_class);
+
+G_DEFINE_TYPE_EXTENDED (MMPluginZte, mm_plugin_zte, G_TYPE_OBJECT,
+ 0, G_IMPLEMENT_INTERFACE (MM_TYPE_PLUGIN, plugin_init))
+
+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_ZTE, NULL));
+}
+
+/*****************************************************************************/
+
+static const char *
+get_name (MMPlugin *plugin)
+{
+ return "ZTE";
+}
+
+static char **
+list_supported_udis (MMPlugin *plugin, LibHalContext *hal_ctx)
+{
+ char **supported = NULL;
+ char **devices;
+ int num_devices;
+ int i;
+
+ devices = libhal_find_device_by_capability (hal_ctx, "modem", &num_devices, NULL);
+ if (devices) {
+ GPtrArray *array;
+
+ array = g_ptr_array_new ();
+
+ for (i = 0; i < num_devices; i++) {
+ char *udi = devices[i];
+
+ if (mm_plugin_supports_udi (plugin, hal_ctx, udi))
+ g_ptr_array_add (array, g_strdup (udi));
+ }
+
+ if (array->len > 0) {
+ g_ptr_array_add (array, NULL);
+ supported = (char **) g_ptr_array_free (array, FALSE);
+ } else
+ g_ptr_array_free (array, TRUE);
+ }
+
+ g_strfreev (devices);
+
+ return supported;
+}
+
+static gboolean
+supports_udi (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi)
+{
+ char **capabilities;
+ char **iter;
+ gboolean supported = FALSE;
+
+ capabilities = libhal_device_get_property_strlist (hal_ctx, udi, "modem.command_sets", NULL);
+ for (iter = capabilities; iter && *iter && !supported; iter++) {
+ if (!strcmp (*iter, "GSM-07.07")) {
+ char *parent_udi;
+
+ parent_udi = libhal_device_get_property_string (hal_ctx, udi, "info.parent", NULL);
+ if (parent_udi) {
+ int vendor;
+
+ vendor = libhal_device_get_property_int (hal_ctx, parent_udi, "usb.vendor_id", NULL);
+ if (vendor == 0x19d2)
+ supported = TRUE;
+
+ libhal_free_string (parent_udi);
+ }
+ }
+ }
+ g_strfreev (capabilities);
+
+ return supported;
+}
+
+static char *
+get_driver_name (LibHalContext *ctx, const char *udi)
+{
+ char *parent_udi;
+ char *driver = NULL;
+
+ parent_udi = libhal_device_get_property_string (ctx, udi, "info.parent", NULL);
+ if (parent_udi) {
+ driver = libhal_device_get_property_string (ctx, parent_udi, "info.linux.driver", NULL);
+ libhal_free_string (parent_udi);
+ }
+
+ return driver;
+}
+
+static MMModem *
+create_modem (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi)
+{
+ char *data_device;
+ char *driver;
+ MMModem *modem;
+
+ data_device = libhal_device_get_property_string (hal_ctx, udi, "serial.device", NULL);
+ g_return_val_if_fail (data_device != NULL, NULL);
+
+ driver = get_driver_name (hal_ctx, udi);
+ g_return_val_if_fail (driver != NULL, NULL);
+
+ modem = MM_MODEM (mm_modem_zte_new (data_device, driver));
+
+ libhal_free_string (data_device);
+ libhal_free_string (driver);
+
+ return modem;
+}
+
+/*****************************************************************************/
+
+static void
+plugin_init (MMPlugin *plugin_class)
+{
+ /* interface implementation */
+ plugin_class->get_name = get_name;
+ plugin_class->list_supported_udis = list_supported_udis;
+ plugin_class->supports_udi = supports_udi;
+ plugin_class->create_modem = create_modem;
+}
+
+static void
+mm_plugin_zte_init (MMPluginZte *self)
+{
+}
+
+static void
+mm_plugin_zte_class_init (MMPluginZteClass *klass)
+{
+}
diff --git a/plugins/mm-plugin-zte.h b/plugins/mm-plugin-zte.h
new file mode 100644
index 00000000..9fe5b438
--- /dev/null
+++ b/plugins/mm-plugin-zte.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#ifndef MM_PLUGIN_ZTE_H
+#define MM_PLUGIN_ZTE_H
+
+#include "mm-plugin.h"
+
+#define MM_TYPE_PLUGIN_ZTE (mm_plugin_zte_get_type ())
+#define MM_PLUGIN_ZTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_ZTE, MMPluginZte))
+#define MM_PLUGIN_ZTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_ZTE, MMPluginZteClass))
+#define MM_IS_PLUGIN_ZTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_ZTE))
+#define MM_IS_PLUGIN_ZTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_ZTE))
+#define MM_PLUGIN_ZTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_ZTE, MMPluginZteClass))
+
+typedef struct {
+ GObject parent;
+} MMPluginZte;
+
+typedef struct {
+ GObjectClass parent;
+} MMPluginZteClass;
+
+GType mm_plugin_zte_get_type (void);
+
+G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
+
+#endif /* MM_PLUGIN_ZTE_H */