diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 24 | ||||
-rw-r--r-- | plugins/mm-modem-mbm.c | 267 | ||||
-rw-r--r-- | plugins/mm-modem-mbm.h | 70 | ||||
-rw-r--r-- | plugins/mm-plugin-mbm.c | 244 | ||||
-rw-r--r-- | plugins/mm-plugin-mbm.h | 48 |
5 files changed, 651 insertions, 2 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ea67db03..d283caa8 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,6 +1,7 @@ pkglib_LTLIBRARIES = \ libmm-plugin-huawei.la \ - libmm-plugin-hso.la + libmm-plugin-hso.la \ + libmm-plugin-mbm.la # Huawei @@ -34,7 +35,26 @@ libmm_plugin_hso_la_CPPFLAGS = \ libmm_plugin_hso_la_LDFLAGS = -module -avoid-version +# MBM + +libmm_plugin_mbm_la_SOURCES = \ + mm-modem-gsm-mbm-glue.h \ + mm-modem-mbm.c \ + mm-modem-mbm.h \ + mm-plugin-mbm.c \ + mm-plugin-mbm.h + +mm-modem-gsm-mbm-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-mbm.xml + dbus-binding-tool --prefix=mm_modem_gsm_mbm --mode=glib-server --output=$@ $< + +libmm_plugin_mbm_la_CPPFLAGS = \ + $(MM_CFLAGS) \ + -I$(top_srcdir)/src + +libmm_plugin_mbm_la_LDFLAGS = -module -avoid-version + BUILT_SOURCES = \ - mm-modem-gsm-hso-glue.h + mm-modem-gsm-hso-glue.h \ + mm-modem-gsm-mbm-glue.h CLEANFILES = $(BUILT_SOURCES) diff --git a/plugins/mm-modem-mbm.c b/plugins/mm-modem-mbm.c new file mode 100644 index 00000000..711466e9 --- /dev/null +++ b/plugins/mm-modem-mbm.c @@ -0,0 +1,267 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Additions to NetworkManager, network-manager-applet and modemmanager + for supporting Ericsson modules like F3507g. + + Author: Per Hallsmark <per@hallsmark.se> + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> +#include <arpa/inet.h> +#include <dbus/dbus-glib.h> +#include "mm-modem-mbm.h" +#include "mm-serial.h" +#include "mm-errors.h" +#include "mm-callback-info.h" + +#include "mm-modem-gsm-mbm-glue.h" + +static gpointer mm_modem_mbm_parent_class = NULL; + +#define MM_MODEM_MBM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_MBM, MMModemMbmPrivate)) + +typedef struct { + char *network_device; +} MMModemMbmPrivate; + +enum { + PROP_0, + PROP_NETWORK_DEVICE, + + LAST_PROP +}; + +MMModem * +mm_modem_mbm_new (const char *serial_device, + const char *network_device, + const char *driver) +{ + g_return_val_if_fail (serial_device != NULL, NULL); + g_return_val_if_fail (network_device != NULL, NULL); + g_return_val_if_fail (driver != NULL, NULL); + + return MM_MODEM (g_object_new (MM_TYPE_MODEM_MBM, + MM_SERIAL_DEVICE, serial_device, + MM_SERIAL_SEND_DELAY, (guint64) 1000, + MM_MODEM_DRIVER, driver, + MM_MODEM_MBM_NETWORK_DEVICE, network_device, + NULL)); +} + +static void +mbm_enable_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 +mbm_enable (MMModemMbm *self, + gboolean enabled, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + char *command; + + info = mm_callback_info_new (MM_MODEM (self), callback, user_data); + + command = g_strdup_printf ("AT*ENAP=%d,%d", enabled ? 1 : 0, + mm_generic_gsm_get_cid (MM_GENERIC_GSM (self))); + + mm_serial_queue_command (MM_SERIAL (self), command, 3, mbm_enable_done, info); + g_free (command); +} + +/*****************************************************************************/ + +static void +modem_enable_done (MMModem *modem, GError *error, gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModem *parent_modem_iface; + + parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem)); + parent_modem_iface->enable (modem, + GPOINTER_TO_INT (mm_callback_info_get_data (info, "enable")), + (MMModemFn) mm_callback_info_get_data (info, "callback"), + mm_callback_info_get_data (info, "user-data")); +} + +static void +enable (MMModem *modem, + gboolean enable, + MMModemFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + + info = mm_callback_info_new (modem, modem_enable_done, NULL); + info->user_data = info; + mm_callback_info_set_data (info, "enable", GINT_TO_POINTER (enable), NULL); + mm_callback_info_set_data (info, "callback", callback, NULL); + mm_callback_info_set_data (info, "user-data", user_data, NULL); + + if (enable) + mm_callback_info_schedule (info); + else + mbm_enable (MM_MODEM_MBM (modem), FALSE, modem_enable_done, info); +} + +/*****************************************************************************/ + +static void +mm_modem_mbm_init (MMModemMbm *self) +{ +} + +static void +modem_init (MMModem *modem_class) +{ + modem_class->enable = enable; +} + +static GObject* +constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + MMModemMbmPrivate *priv; + + object = G_OBJECT_CLASS (mm_modem_mbm_parent_class)->constructor (type, + n_construct_params, + construct_params); + if (!object) + return NULL; + + priv = MM_MODEM_MBM_GET_PRIVATE (object); + + if (!priv->network_device) { + g_warning ("No network device provided"); + g_object_unref (object); + return NULL; + } + + return object; +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_NETWORK_DEVICE: + /* Construct only */ + priv->network_device = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_NETWORK_DEVICE: + g_value_set_string (value, priv->network_device); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} +static void +finalize (GObject *object) +{ + MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (object); + + g_free (priv->network_device); + + G_OBJECT_CLASS (mm_modem_mbm_parent_class)->finalize (object); +} + +static void +mm_modem_mbm_class_init (MMModemMbmClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + mm_modem_mbm_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (object_class, sizeof (MMModemMbmPrivate)); + + /* Virtual methods */ + object_class->constructor = constructor; + object_class->set_property = set_property; + object_class->get_property = get_property; + object_class->finalize = finalize; + /* Properties */ + g_object_class_install_property + (object_class, PROP_NETWORK_DEVICE, + g_param_spec_string (MM_MODEM_MBM_NETWORK_DEVICE, + "NetworkDevice", + "Network device", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + +GType +mm_modem_mbm_get_type (void) +{ + static GType modem_mbm_type = 0; + + if (G_UNLIKELY (modem_mbm_type == 0)) { + static const GTypeInfo modem_mbm_type_info = { + sizeof (MMModemMbmClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) mm_modem_mbm_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (MMModemMbm), + 0, /* n_preallocs */ + (GInstanceInitFunc) mm_modem_mbm_init, + }; + + static const GInterfaceInfo modem_iface_info = { + (GInterfaceInitFunc) modem_init + }; + + modem_mbm_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemMbm", &modem_mbm_type_info, 0); + g_type_add_interface_static (modem_mbm_type, MM_TYPE_MODEM, &modem_iface_info); + } + + return modem_mbm_type; +} diff --git a/plugins/mm-modem-mbm.h b/plugins/mm-modem-mbm.h new file mode 100644 index 00000000..7d2f4649 --- /dev/null +++ b/plugins/mm-modem-mbm.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Additions to NetworkManager, network-manager-applet and modemmanager + for supporting Ericsson modules like F3507g. + + Author: Per Hallsmark <per@hallsmark.se> + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef MM_MODEM_MBM_H +#define MM_MODEM_MBM_H + +#include "mm-generic-gsm.h" + +#define MM_TYPE_MODEM_MBM (mm_modem_mbm_get_type ()) +#define MM_MODEM_MBM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_MBM, MMModemMbm)) +#define MM_MODEM_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_MBM, MMModemMbmClass)) +#define MM_IS_MODEM_MBM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_MBM)) +#define MM_IS_MODEM_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_MBM)) +#define MM_MODEM_MBM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_MBM, MMModemMbmClass)) + +#define MM_MODEM_MBM_NETWORK_DEVICE "network-device" + +typedef struct { + MMGenericGsm parent; +} MMModemMbm; + +typedef struct { + MMGenericGsmClass parent; +} MMModemMbmClass; + +typedef void (*MMModemMbmIp4Fn) (MMModemMbm *modem, + guint32 address, + GArray *dns, + GError *error, + gpointer user_data); + + +GType mm_modem_mbm_get_type (void); + +MMModem *mm_modem_mbm_new (const char *serial_device, + const char *network_device, + const char *driver); + +void mm_mbm_modem_authenticate (MMModemMbm *self, + const char *username, + const char *password, + MMModemFn callback, + gpointer user_data); + +void mm_mbm_modem_get_ip4_config (MMModemMbm *self, + MMModemMbmIp4Fn callback, + gpointer user_data); + +#endif /* MM_MODEM_MBM_H */ diff --git a/plugins/mm-plugin-mbm.c b/plugins/mm-plugin-mbm.c new file mode 100644 index 00000000..6f7373f8 --- /dev/null +++ b/plugins/mm-plugin-mbm.c @@ -0,0 +1,244 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Additions to NetworkManager, network-manager-applet and modemmanager + for supporting Ericsson modules like F3507g. + + Author: Per Hallsmark <per@hallsmark.se> + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <string.h> +#include <gmodule.h> +#include "mm-plugin-mbm.h" +#include "mm-modem-mbm.h" + +static void plugin_init (MMPlugin *plugin_class); + +G_DEFINE_TYPE_EXTENDED (MMPluginMbm, mm_plugin_mbm, 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_MBM, NULL)); +} + +/*****************************************************************************/ + +static const char * +get_name (MMPlugin *plugin) +{ + return "MBM"; +} + +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 char * +get_netdev (LibHalContext *ctx, const char *udi) +{ + char *serial_parent, *serial_parent_parent, *netdev = NULL; + char **netdevs; + int num, i; + + /* Get the origin udi, which is parent of our parent */ + serial_parent = libhal_device_get_property_string (ctx, udi, "info.parent", NULL); + if (!serial_parent) + return NULL; + /* Just attach to first cdc-acm interface */ + if (strncmp (serial_parent + strlen (serial_parent) - 4, "_if1", 4)) + return NULL; + serial_parent_parent = libhal_device_get_property_string (ctx, serial_parent, "info.parent", NULL); + if (!serial_parent_parent) + return NULL; + + /* Look for the originating device's netdev */ + netdevs = libhal_find_device_by_capability (ctx, "net", &num, NULL); + for (i = 0; netdevs && !netdev && (i < num); i++) { + char *netdev_parent, *netdev_parent_parent, *tmp; + + /* Get the origin udi, which also is parent of our parent */ + netdev_parent = libhal_device_get_property_string (ctx, netdevs[i], "info.parent", NULL); + if (!netdev_parent) + continue; + netdev_parent_parent = libhal_device_get_property_string (ctx, netdev_parent, "info.parent", NULL); + if (!netdev_parent_parent) + continue; + + if (!strcmp (netdev_parent_parent, serial_parent_parent)) { + /* We found it */ + tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.interface", NULL); + if (tmp) { + netdev = g_strdup (tmp); + libhal_free_string (tmp); + } + } + + libhal_free_string (netdev_parent); + libhal_free_string (netdev_parent_parent); + } + libhal_free_string_array (netdevs); + libhal_free_string (serial_parent); + libhal_free_string (serial_parent_parent); + + return netdev; +} + +static char * +get_driver (LibHalContext *ctx, const char *udi) +{ + char *serial_parent, *serial_parent_parent, *driver = NULL; + char **netdevs; + int num, i; + + /* Get the origin udi, which is parent of our parent */ + serial_parent = libhal_device_get_property_string (ctx, udi, "info.parent", NULL); + if (!serial_parent) + return NULL; + serial_parent_parent = libhal_device_get_property_string (ctx, serial_parent, "info.parent", NULL); + if (!serial_parent_parent) + return NULL; + + /* Look for the originating device's netdev */ + netdevs = libhal_find_device_by_capability (ctx, "net", &num, NULL); + for (i = 0; netdevs && !driver && (i < num); i++) { + char *netdev_parent, *netdev_parent_parent, *tmp; + + /* Get the origin udi, which also is parent of our parent */ + netdev_parent = libhal_device_get_property_string (ctx, netdevs[i], "info.parent", NULL); + if (!netdev_parent) + continue; + netdev_parent_parent = libhal_device_get_property_string (ctx, netdev_parent, "info.parent", NULL); + if (!netdev_parent_parent) + continue; + + if (!strcmp (netdev_parent_parent, serial_parent_parent)) { + /* We found it */ + tmp = libhal_device_get_property_string (ctx, + netdev_parent, "info.linux.driver", NULL); + if (tmp) { + driver = g_strdup (tmp); + libhal_free_string (tmp); + } + } + + libhal_free_string (netdev_parent); + libhal_free_string (netdev_parent_parent); + } + libhal_free_string_array (netdevs); + libhal_free_string (serial_parent); + libhal_free_string (serial_parent_parent); + + return driver; +} + +static gboolean +supports_udi (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi) +{ + gboolean supported = FALSE; + char *netdev = NULL; + + netdev = get_netdev (hal_ctx, udi); + + if (netdev) { + supported = TRUE; + libhal_free_string (netdev); + } + + return supported; +} + +static MMModem * +create_modem (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi) +{ + char *serial_device; + char *net_device; + char *driver; + MMModem *modem; + + serial_device = libhal_device_get_property_string (hal_ctx, udi, "serial.device", NULL); + g_return_val_if_fail (serial_device != NULL, NULL); + + net_device = get_netdev (hal_ctx, udi); + g_return_val_if_fail (net_device != NULL, NULL); + + driver = get_driver (hal_ctx, udi); + g_return_val_if_fail (driver != NULL, NULL); + + modem = MM_MODEM (mm_modem_mbm_new (serial_device, net_device, driver)); + + g_free (serial_device); + g_free (net_device); + + 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_mbm_init (MMPluginMbm *self) +{ +} + +static void +mm_plugin_mbm_class_init (MMPluginMbmClass *klass) +{ +} diff --git a/plugins/mm-plugin-mbm.h b/plugins/mm-plugin-mbm.h new file mode 100644 index 00000000..4c6a6d08 --- /dev/null +++ b/plugins/mm-plugin-mbm.h @@ -0,0 +1,48 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Additions to NetworkManager, network-manager-applet and modemmanager + for supporting Ericsson modules like F3507g. + + Author: Per Hallsmark <per@hallsmark.se> + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef MM_PLUGIN_MBM_H +#define MM_PLUGIN_MBM_H + +#include "mm-plugin.h" +#include "mm-generic-gsm.h" + +#define MM_TYPE_PLUGIN_MBM (mm_plugin_mbm_get_type ()) +#define MM_PLUGIN_MBM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_MBM, MMPluginMbm)) +#define MM_PLUGIN_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_MBM, MMPluginMbmClass)) +#define MM_IS_PLUGIN_MBM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_MBM)) +#define MM_IS_PLUGIN_MBM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_MBM)) +#define MM_PLUGIN_MBM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_MBM, MMPluginMbmClass)) + +typedef struct { + GObject parent; +} MMPluginMbm; + +typedef struct { + GObjectClass parent; +} MMPluginMbmClass; + +GType mm_plugin_mbm_get_type (void); + +#endif /* MM_PLUGIN_MBM_H */ |