diff options
author | Dan Williams <dcbw@redhat.com> | 2009-06-18 23:32:08 -0400 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2009-06-18 23:32:08 -0400 |
commit | 10b8674e5c4550517bd1e1ae887b5dc495112d88 (patch) | |
tree | 0a628afcc438eee982c820ec57c5f13c161cfb0b | |
parent | 983e3c994750e1fdeb439ce6dd9d430e2f6f3f84 (diff) |
gobi: add plugin for Qualcomm Gobi devices
-rw-r--r-- | plugins/Makefile.am | 19 | ||||
-rw-r--r-- | plugins/mm-modem-gobi-gsm.c | 177 | ||||
-rw-r--r-- | plugins/mm-modem-gobi-gsm.h | 43 | ||||
-rw-r--r-- | plugins/mm-plugin-gobi.c | 343 | ||||
-rw-r--r-- | plugins/mm-plugin-gobi.h | 42 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 1 |
6 files changed, 625 insertions, 0 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index a164b4c2..49457c34 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,6 +1,7 @@ pkglib_LTLIBRARIES = \ libmm-plugin-generic.la \ libmm-plugin-moto-c.la \ + libmm-plugin-gobi.la \ libmm-plugin-huawei.la \ libmm-plugin-hso.la \ libmm-plugin-mbm.la \ @@ -44,6 +45,24 @@ libmm_plugin_moto_c_la_LDFLAGS = \ -module \ -avoid-version +# Qualcomm Gobi + +libmm_plugin_gobi_la_SOURCES = \ + mm-plugin-gobi.c \ + mm-plugin-gobi.h \ + mm-modem-gobi-gsm.c \ + mm-modem-gobi-gsm.h + +libmm_plugin_gobi_la_CPPFLAGS = \ + $(MM_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -I$(top_srcdir)/src + +libmm_plugin_gobi_la_LDFLAGS = \ + $(GUDEV_LDFLAGS) \ + -module \ + -avoid-version + # Huawei libmm_plugin_huawei_la_SOURCES = \ diff --git a/plugins/mm-modem-gobi-gsm.c b/plugins/mm-modem-gobi-gsm.c new file mode 100644 index 00000000..f245c565 --- /dev/null +++ b/plugins/mm-modem-gobi-gsm.c @@ -0,0 +1,177 @@ +/* -*- 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 <unistd.h> + +#include "mm-modem-gobi-gsm.h" +#include "mm-errors.h" +#include "mm-callback-info.h" +#include "mm-modem-gsm-card.h" + +static gpointer mm_modem_gobi_gsm_parent_class = NULL; + +MMModem * +mm_modem_gobi_gsm_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_GOBI_GSM, + MM_MODEM_MASTER_DEVICE, device, + MM_MODEM_DRIVER, driver, + MM_MODEM_PLUGIN, plugin, + NULL)); +} + +/*****************************************************************************/ + +static void +get_string_done (MMSerialPort *port, + GString *response, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (error && response && !strcmp (response->str, "ERROR")) { + info->error = g_error_new_literal (MM_MOBILE_ERROR, + MM_MOBILE_ERROR_SIM_NOT_INSERTED, + "Unable to read IMSI"); + } else if (error) + info->error = g_error_copy (error); + else + mm_callback_info_set_result (info, g_strdup (response->str), g_free); + + mm_callback_info_schedule (info); +} + +static void +get_imsi (MMModemGsmCard *modem, + MMModemStringFn callback, + gpointer user_data) +{ + MMSerialPort *primary; + MMCallbackInfo *info; + GError *error = NULL; + + info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data); + primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY); + if (primary) + mm_serial_port_queue_command_cached (primary, "+CIMI", 3, get_string_done, info); + else { + g_set_error (&error, MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED, + "Operation not supported; primary port unusable"); + get_string_done (primary, NULL, error, user_data); + g_clear_error (&error); + } +} + +static void +modem_gsm_card_init (MMModemGsmCard *class) +{ + class->get_imsi = get_imsi; +} + +/*****************************************************************************/ + +static void +modem_init (MMModem *modem_class) +{ +} + +static void +mm_modem_gobi_gsm_init (MMModemGobiGsm *self) +{ +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + + /* These devices just don't implement AT+CFUN */ + + switch (prop_id) { + case MM_GENERIC_GSM_PROP_INIT_CMD: + g_value_set_string (value, "Z E0 V1 +CMEE=1"); + break; + default: + break; + } +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ +} + +static void +mm_modem_gobi_gsm_class_init (MMModemGobiGsmClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + mm_modem_gobi_gsm_parent_class = g_type_class_peek_parent (klass); + + object_class->get_property = get_property; + object_class->set_property = set_property; + + g_object_class_override_property (object_class, + MM_GENERIC_GSM_PROP_INIT_CMD, + MM_GENERIC_GSM_INIT_CMD); +} + +GType +mm_modem_gobi_gsm_get_type (void) +{ + static GType modem_gobi_gsm_type = 0; + + if (G_UNLIKELY (modem_gobi_gsm_type == 0)) { + static const GTypeInfo modem_gobi_gsm_type_info = { + sizeof (MMModemGobiGsmClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) mm_modem_gobi_gsm_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (MMModemGobiGsm), + 0, /* n_preallocs */ + (GInstanceInitFunc) mm_modem_gobi_gsm_init, + }; + + static const GInterfaceInfo modem_iface_info = { + (GInterfaceInitFunc) modem_init + }; + + static const GInterfaceInfo modem_gsm_card_info = { + (GInterfaceInitFunc) modem_gsm_card_init + }; + + modem_gobi_gsm_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemGobiGsm", + &modem_gobi_gsm_type_info, 0); + + g_type_add_interface_static (modem_gobi_gsm_type, MM_TYPE_MODEM, &modem_iface_info); + g_type_add_interface_static (modem_gobi_gsm_type, MM_TYPE_MODEM_GSM_CARD, &modem_gsm_card_info); + } + + return modem_gobi_gsm_type; +} diff --git a/plugins/mm-modem-gobi-gsm.h b/plugins/mm-modem-gobi-gsm.h new file mode 100644 index 00000000..4bd262fb --- /dev/null +++ b/plugins/mm-modem-gobi-gsm.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_GOBI_GSM_H +#define MM_MODEM_GOBI_GSM_H + +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_GOBI_GSM (mm_modem_gobi_gsm_get_type ()) +#define MM_MODEM_GOBI_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_GOBI_GSM, MMModemGobiGsm)) +#define MM_MODEM_GOBI_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_GOBI_GSM, MMModemGobiGsmClass)) +#define MM_IS_MODEM_GOBI_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_GOBI_GSM)) +#define MM_IS_MODEM_GOBI_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_GOBI_GSM)) +#define MM_MODEM_GOBI_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_GOBI_GSM, MMModemGobiGsmClass)) + +typedef struct { + MMGenericGsm parent; +} MMModemGobiGsm; + +typedef struct { + MMGenericGsmClass parent; +} MMModemGobiGsmClass; + +GType mm_modem_gobi_gsm_get_type (void); + +MMModem *mm_modem_gobi_gsm_new (const char *device, + const char *driver, + const char *plugin_name); + +#endif /* MM_MODEM_GOBI_GSM_H */ diff --git a/plugins/mm-plugin-gobi.c b/plugins/mm-plugin-gobi.c new file mode 100644 index 00000000..5d3c22ca --- /dev/null +++ b/plugins/mm-plugin-gobi.c @@ -0,0 +1,343 @@ +/* -*- 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 <string.h> +#include <gmodule.h> +#define G_UDEV_API_IS_SUBJECT_TO_CHANGE +#include <gudev/gudev.h> + +#include "mm-plugin-gobi.h" +#include "mm-modem-gobi-gsm.h" +#include "mm-generic-cdma.h" + +static void plugin_init (MMPlugin *plugin_class); + +G_DEFINE_TYPE_EXTENDED (MMPluginGobi, mm_plugin_gobi, 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; + +#define MM_PLUGIN_GOBI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PLUGIN_GOBI, MMPluginGobiPrivate)) + +typedef struct { + GUdevClient *client; + GHashTable *modems; +} MMPluginGobiPrivate; + + +G_MODULE_EXPORT MMPlugin * +mm_plugin_create (void) +{ + return MM_PLUGIN (g_object_new (MM_TYPE_PLUGIN_GOBI, NULL)); +} + +/*****************************************************************************/ + +static char * +get_driver_name (GUdevDevice *device) +{ + GUdevDevice *parent = NULL; + const char *driver; + char *ret = NULL; + + driver = g_udev_device_get_driver (device); + if (!driver) { + parent = g_udev_device_get_parent (device); + if (parent) + driver = g_udev_device_get_driver (parent); + } + + if (driver) + ret = g_strdup (driver); + if (parent) + g_object_unref (parent); + + return ret; +} + +static GUdevDevice * +find_physical_device (GUdevDevice *child) +{ + GUdevDevice *iter, *old = NULL; + const char *bus, *type; + + g_return_val_if_fail (child != NULL, NULL); + + bus = g_udev_device_get_property (child, "ID_BUS"); + if (!bus) + return NULL; + + if (strcmp (bus, "usb")) + return NULL; + + /* Walk the parents to find the 'usb_device' for this device. */ + iter = g_object_ref (child); + while (iter) { + type = g_udev_device_get_devtype (iter); + if (type && !strcmp (type, "usb_device")) + return iter; + + old = iter; + iter = g_udev_device_get_parent (old); + g_object_unref (old); + } + g_object_unref (child); + + return NULL; +} + +#define PROP_GSM "ID_MM_MODEM_GSM" +#define PROP_CDMA "ID_MM_MODEM_IS707_A" +#define PROP_EVDO1 "ID_MM_MODEM_IS856" +#define PROP_EVDOA "ID_MM_MODEM_IS856_A" + +static GUdevDevice * +get_device_type (MMPlugin *plugin, + const char *subsys, + const char *name, + gboolean *gsm, + gboolean *cdma) +{ + MMPluginGobiPrivate *priv = MM_PLUGIN_GOBI_GET_PRIVATE (plugin); + GUdevDevice *device; + + g_return_val_if_fail (plugin != NULL, NULL); + g_return_val_if_fail (MM_IS_PLUGIN (plugin), NULL); + g_return_val_if_fail (subsys != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + device = g_udev_client_query_by_subsystem_and_name (priv->client, subsys, name); + if (!device) + return NULL; + + if (g_udev_device_get_property_as_boolean (device, PROP_GSM)) + *gsm = TRUE; + if ( g_udev_device_get_property_as_boolean (device, PROP_CDMA) + || g_udev_device_get_property_as_boolean (device, PROP_EVDO1) + || g_udev_device_get_property_as_boolean (device, PROP_EVDOA)) + *cdma = TRUE; + + return device; +} + +static guint32 +supports_port (MMPlugin *plugin, + const char *subsys, + const char *name) +{ + GUdevDevice *device, *physdev = NULL; + guint32 level = 0; + gboolean gsm = FALSE, cdma = FALSE; + char *driver = NULL; + + g_return_val_if_fail (plugin != NULL, 0); + g_return_val_if_fail (MM_IS_PLUGIN (plugin), 0); + g_return_val_if_fail (subsys != NULL, 0); + g_return_val_if_fail (name != NULL, 0); + + /* Can't do anything with non-serial ports */ + if (strcmp (subsys, "tty")) + return 0; + + device = get_device_type (plugin, subsys, name, &gsm, &cdma); + if (!device) + return 0; + + if (!gsm && !cdma) + goto out; + + driver = get_driver_name (device); + if (!driver || strcmp (driver, "qcserial")) + goto out; + + physdev = find_physical_device (device); + if (!physdev) + goto out; + g_object_unref (physdev); + level = 10; + +out: + g_object_unref (device); + return level; +} + +typedef struct { + char *key; + gpointer modem; +} FindInfo; + +static void +find_modem (gpointer key, gpointer data, gpointer user_data) +{ + FindInfo *info = user_data; + + if (!info->key && data == info->modem) + info->key = g_strdup ((const char *) key); +} + +static void +modem_destroyed (gpointer data, GObject *modem) +{ + MMPluginGobi *self = MM_PLUGIN_GOBI (data); + MMPluginGobiPrivate *priv = MM_PLUGIN_GOBI_GET_PRIVATE (self); + FindInfo info = { NULL, modem }; + + g_hash_table_foreach (priv->modems, find_modem, &info); + if (info.key) + g_hash_table_remove (priv->modems, info.key); + g_free (info.key); +} + +static MMModem * +grab_port (MMPlugin *plugin, + const char *subsys, + const char *name, + GError **error) +{ + MMPluginGobi *self = MM_PLUGIN_GOBI (plugin); + MMPluginGobiPrivate *priv = MM_PLUGIN_GOBI_GET_PRIVATE (plugin); + GUdevDevice *device = NULL, *physdev = NULL; + const char *devfile, *sysfs_path; + char *driver = NULL; + MMModem *modem = NULL; + gboolean gsm = FALSE, cdma = FALSE; + + g_return_val_if_fail (subsys != NULL, NULL); + g_return_val_if_fail (name != NULL, NULL); + + /* Can't do anything with non-serial ports */ + if (strcmp (subsys, "tty")) + return NULL; + + device = get_device_type (plugin, subsys, name, &gsm, &cdma); + if (!device) { + g_set_error (error, 0, 0, "Could not get port's udev device."); + return NULL; + } + + if (!gsm && !cdma) { + g_set_error (error, 0, 0, "Modem unsupported (not GSM or CDMA)."); + goto out; + } + + physdev = find_physical_device (device); + if (!physdev) { + g_set_error (error, 0, 0, "Could not get ports's physical device."); + goto out; + } + + devfile = g_udev_device_get_device_file (device); + if (!devfile) { + g_set_error (error, 0, 0, "Could not get port's sysfs file."); + goto out; + } + + driver = get_driver_name (device); + if (!driver) { + g_set_error (error, 0, 0, "Could not get port's driver name."); + goto out; + } + + sysfs_path = g_udev_device_get_sysfs_path (physdev); + if (!devfile) { + g_set_error (error, 0, 0, "Could not get port's physical device sysfs path."); + goto out; + } + + modem = g_hash_table_lookup (priv->modems, sysfs_path); + if (!modem) { + if (gsm) { + modem = mm_modem_gobi_gsm_new (sysfs_path, + driver, + mm_plugin_get_name (plugin)); + } else if (cdma) { + modem = mm_generic_cdma_new (sysfs_path, + driver, + mm_plugin_get_name (plugin)); + } + + if (modem) { + if (!mm_modem_grab_port (modem, subsys, name, error)) { + g_object_unref (modem); + modem = NULL; + } + } + + if (modem) { + g_object_weak_ref (G_OBJECT (modem), modem_destroyed, self); + g_hash_table_insert (priv->modems, g_strdup (sysfs_path), modem); + } + } else { + if (gsm || cdma) { + if (!mm_modem_grab_port (modem, subsys, name, error)) + modem = NULL; + } + } + +out: + g_free (driver); + g_object_unref (device); + g_object_unref (physdev); + return modem; +} + +static const char * +get_name (MMPlugin *plugin) +{ + return "Gobi"; +} + +/*****************************************************************************/ + +static void +plugin_init (MMPlugin *plugin_class) +{ + /* interface implementation */ + plugin_class->get_name = get_name; + plugin_class->supports_port = supports_port; + plugin_class->grab_port = grab_port; +} + +static void +mm_plugin_gobi_init (MMPluginGobi *self) +{ + MMPluginGobiPrivate *priv = MM_PLUGIN_GOBI_GET_PRIVATE (self); + const char *subsys[2] = { "tty", NULL }; + + priv->modems = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + + priv->client = g_udev_client_new (subsys); +} + +static void +dispose (GObject *object) +{ + MMPluginGobiPrivate *priv = MM_PLUGIN_GOBI_GET_PRIVATE (object); + + g_hash_table_destroy (priv->modems); + g_object_unref (priv->client); +} + +static void +mm_plugin_gobi_class_init (MMPluginGobiClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (MMPluginGobiPrivate)); + + object_class->dispose = dispose; +} diff --git a/plugins/mm-plugin-gobi.h b/plugins/mm-plugin-gobi.h new file mode 100644 index 00000000..fd820741 --- /dev/null +++ b/plugins/mm-plugin-gobi.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 Red Hat, Inc. + */ + +#ifndef MM_PLUGIN_GOBI_H +#define MM_PLUGIN_GOBI_H + +#include "mm-plugin.h" +#include "mm-generic-gsm.h" + +#define MM_TYPE_PLUGIN_GOBI (mm_plugin_gobi_get_type ()) +#define MM_PLUGIN_GOBI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_GOBI, MMPluginGobi)) +#define MM_PLUGIN_GOBI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_GOBI, MMPluginGobiClass)) +#define MM_IS_PLUGIN_GOBI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_GOBI)) +#define MM_IS_PLUGIN_GOBI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_GOBI)) +#define MM_PLUGIN_GOBI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_GOBI, MMPluginGobiClass)) + +typedef struct { + GObject parent; +} MMPluginGobi; + +typedef struct { + GObjectClass parent; +} MMPluginGobiClass; + +GType mm_plugin_gobi_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_GOBI_H */ diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index 0397614c..9c0a6a51 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -1730,6 +1730,7 @@ set_property (GObject *object, guint prop_id, case MM_MODEM_PROP_VALID: case MM_GENERIC_GSM_PROP_POWER_UP_CMD: case MM_GENERIC_GSM_PROP_POWER_DOWN_CMD: + case MM_GENERIC_GSM_PROP_INIT_CMD: break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |