diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-04-13 16:26:51 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2011-06-06 17:20:16 +0200 |
commit | c6060e8c0f4c384c49b1e0effb0e149ce9bf15c9 (patch) | |
tree | bb3294a6631f69d561b135fede7e95c041780ff2 | |
parent | 668726dbd7063ef8c17bd27054acfd37343b2f29 (diff) |
cinterion: add initial dummy plugin
-rw-r--r-- | plugins/Makefile.am | 21 | ||||
-rw-r--r-- | plugins/mm-modem-cinterion-gsm.c | 62 | ||||
-rw-r--r-- | plugins/mm-modem-cinterion-gsm.h | 44 | ||||
-rw-r--r-- | plugins/mm-plugin-cinterion.c | 164 | ||||
-rw-r--r-- | plugins/mm-plugin-cinterion.h | 47 |
5 files changed, 337 insertions, 1 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 8eaffb42..c7a7a3d3 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -37,7 +37,8 @@ pkglib_LTLIBRARIES = \ libmm-plugin-x22x.la \ libmm-plugin-linktop.la \ libmm-plugin-samsung.la \ - libmm-plugin-wavecom.la + libmm-plugin-wavecom.la \ + libmm-plugin-cinterion.la # Generic @@ -375,6 +376,24 @@ libmm_plugin_samsung_la_LDFLAGS = \ -module \ -avoid-version +# Cinterion (previously Siemens) modem + +libmm_plugin_cinterion_la_SOURCES = \ + mm-plugin-cinterion.c \ + mm-plugin-cinterion.h \ + mm-modem-cinterion-gsm.c \ + mm-modem-cinterion-gsm.h + +libmm_plugin_cinterion_la_CPPFLAGS = \ + $(MM_CFLAGS) \ + $(GUDEV_CFLAGS) \ + -I$(top_srcdir)/src + +libmm_plugin_cinterion_la_LDFLAGS = \ + $(GUDEV_LDFLAGS) \ + -module \ + -avoid-version + udevrulesdir = $(UDEV_BASE_DIR)/rules.d udevrules_DATA = \ 77-mm-ericsson-mbm.rules \ diff --git a/plugins/mm-modem-cinterion-gsm.c b/plugins/mm-modem-cinterion-gsm.c new file mode 100644 index 00000000..07bc864e --- /dev/null +++ b/plugins/mm-modem-cinterion-gsm.c @@ -0,0 +1,62 @@ +/* -*- 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) 2011 Aleksander Morgado <aleksander@lanedo.com> + */ + +#include <config.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include "mm-errors.h" +#include "mm-modem-helpers.h" +#include "mm-modem-cinterion-gsm.h" +#include "mm-serial-parsers.h" +#include "mm-log.h" + +G_DEFINE_TYPE (MMModemCinterionGsm, mm_modem_cinterion_gsm, MM_TYPE_GENERIC_GSM); + +MMModem * +mm_modem_cinterion_gsm_new (const char *device, + const char *driver, + const char *plugin, + guint32 vendor, + guint32 product) +{ + 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_CINTERION_GSM, + MM_MODEM_MASTER_DEVICE, device, + MM_MODEM_DRIVER, driver, + MM_MODEM_PLUGIN, plugin, + MM_MODEM_HW_VID, vendor, + MM_MODEM_HW_PID, product, + NULL)); +} + +/*****************************************************************************/ + +static void +mm_modem_cinterion_gsm_init (MMModemCinterionGsm *self) +{ +} + +static void +mm_modem_cinterion_gsm_class_init (MMModemCinterionGsmClass *klass) +{ +} + diff --git a/plugins/mm-modem-cinterion-gsm.h b/plugins/mm-modem-cinterion-gsm.h new file mode 100644 index 00000000..e1238016 --- /dev/null +++ b/plugins/mm-modem-cinterion-gsm.h @@ -0,0 +1,44 @@ +/* -*- 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) 2011 Aleksander Morgado <aleksander@lanedo.com> + */ + +#ifndef MM_MODEM_CINTERION_GSM_H +#define MM_MODEM_CINTERION_GSM_H + +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_CINTERION_GSM (mm_modem_cinterion_gsm_get_type ()) +#define MM_MODEM_CINTERION_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_CINTERION_GSM, MMModemCinterionGsm)) +#define MM_MODEM_CINTERION_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_CINTERION_AIRLINK_GSM, MMModemCinterionGsmClass)) +#define MM_IS_MODEM_CINTERION_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_CINTERION_AIRLINK_GSM)) +#define MM_IS_MODEM_CINTERION_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_CINTERION_AIRLINK_GSM)) +#define MM_MODEM_CINTERION_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_CINTERION_AIRLINK_GSM, MMModemCinterionGsmClass)) + +typedef struct { + MMGenericGsm parent; +} MMModemCinterionGsm; + +typedef struct { + MMGenericGsmClass parent; +} MMModemCinterionGsmClass; + +GType mm_modem_cinterion_gsm_get_type (void); + +MMModem *mm_modem_cinterion_gsm_new (const char *device, + const char *driver, + const char *plugin_name, + guint32 vendor, + guint32 product); + +#endif /* MM_MODEM_CINTERION_GSM_H */ diff --git a/plugins/mm-plugin-cinterion.c b/plugins/mm-plugin-cinterion.c new file mode 100644 index 00000000..3595fec2 --- /dev/null +++ b/plugins/mm-plugin-cinterion.c @@ -0,0 +1,164 @@ +/* -*- 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) 2011 Aleksander Morgado <aleksander@lanedo.com> + */ + +#include <string.h> +#include <gmodule.h> +#include "mm-plugin-cinterion.h" +#include "mm-modem-cinterion-gsm.h" + +G_DEFINE_TYPE (MMPluginCinterion, mm_plugin_cinterion, MM_TYPE_PLUGIN_BASE) + +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_CINTERION, + MM_PLUGIN_BASE_NAME, "Cinterion", + NULL)); +} + +static guint32 +get_level_for_capabilities (guint32 capabilities) +{ + if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM) + return 10; + return 0; +} + +static void +probe_result (MMPluginBase *base, + MMPluginBaseSupportsTask *task, + guint32 capabilities, + gpointer user_data) +{ + mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities)); +} + +static MMPluginSupportsResult +supports_port (MMPluginBase *base, + MMModem *existing, + MMPluginBaseSupportsTask *task) +{ + GUdevDevice *port; + guint32 cached = 0, level; + const char *subsys, *name; + guint16 vendor = 0; + + /* Can't do anything with non-serial ports */ + port = mm_plugin_base_supports_task_get_port (task); + if (strcmp (g_udev_device_get_subsystem (port), "tty")) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + subsys = g_udev_device_get_subsystem (port); + name = g_udev_device_get_name (port); + + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, NULL)) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + /* Vendors: Cinterion (0x1e2d) + * Siemens (0x0681) + */ + if (vendor != 0x1e2d && vendor != 0x0681) + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + + if (mm_plugin_base_get_cached_port_capabilities (base, port, &cached)) { + level = get_level_for_capabilities (cached); + if (level) { + mm_plugin_base_supports_task_complete (task, level); + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + } + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; + } + + /* Otherwise kick off a probe */ + if (mm_plugin_base_probe_port (base, task, 100000, NULL)) + return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; + + return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED; +} + +static MMModem * +grab_port (MMPluginBase *base, + MMModem *existing, + MMPluginBaseSupportsTask *task, + GError **error) +{ + GUdevDevice *port = NULL; + MMModem *modem = NULL; + const char *name, *subsys, *sysfs_path; + guint32 caps; + guint16 vendor = 0, product = 0; + + port = mm_plugin_base_supports_task_get_port (task); + g_assert (port); + + subsys = g_udev_device_get_subsystem (port); + name = g_udev_device_get_name (port); + + if (!mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product)) { + g_set_error (error, 0, 0, "Could not get modem product ID."); + return NULL; + } + + caps = mm_plugin_base_supports_task_get_probed_capabilities (task); + sysfs_path = mm_plugin_base_supports_task_get_physdev_path (task); + if (!existing) { + if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) { + modem = mm_modem_cinterion_gsm_new (sysfs_path, + mm_plugin_base_supports_task_get_driver (task), + mm_plugin_get_name (MM_PLUGIN (base)), + vendor, + product); + } + + if (modem) { + if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error)) { + g_object_unref (modem); + return NULL; + } + } + } else if (get_level_for_capabilities (caps)) { + modem = existing; + if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error)) + return NULL; + } + + return modem; +} + +/*****************************************************************************/ + +static void +mm_plugin_cinterion_init (MMPluginCinterion *self) +{ + g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL); +} + +static void +mm_plugin_cinterion_class_init (MMPluginCinterionClass *klass) +{ + MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass); + + pb_class->supports_port = supports_port; + pb_class->grab_port = grab_port; +} diff --git a/plugins/mm-plugin-cinterion.h b/plugins/mm-plugin-cinterion.h new file mode 100644 index 00000000..4c9b51a5 --- /dev/null +++ b/plugins/mm-plugin-cinterion.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) 2011 Aleksander Morgado <aleksander@lanedo.com> + */ + +#ifndef MM_PLUGIN_CINTERION_H +#define MM_PLUGIN_CINTERION_H + +#include "mm-plugin-base.h" +#include "mm-generic-gsm.h" + +#define MM_TYPE_PLUGIN_CINTERION (mm_plugin_cinterion_get_type ()) +#define MM_PLUGIN_CINTERION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_CINTERION, MMPluginCinterion)) +#define MM_PLUGIN_CINTERION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_CINTERION, MMPluginCinterionClass)) +#define MM_IS_PLUGIN_CINTERION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_CINTERION)) +#define MM_IS_PLUGIN_CINTERION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_CINTERION)) +#define MM_PLUGIN_CINTERION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_CINTERION, MMPluginCinterionClass)) + +typedef struct { + MMPluginBase parent; +} MMPluginCinterion; + +typedef struct { + MMPluginBaseClass parent; +} MMPluginCinterionClass; + +GType mm_plugin_cinterion_get_type (void); + +G_MODULE_EXPORT MMPlugin *mm_plugin_create (void); + +#endif /* MM_PLUGIN_CINTERION_H */ |