Implement plugin for Sierra Wireless modems.
For now, it only waits a bit after CFUN=1 call.
This commit is contained in:
@@ -2,7 +2,8 @@ pkglib_LTLIBRARIES = \
|
||||
libmm-plugin-huawei.la \
|
||||
libmm-plugin-hso.la \
|
||||
libmm-plugin-mbm.la \
|
||||
libmm-plugin-option.la
|
||||
libmm-plugin-option.la \
|
||||
libmm-plugin-sierra.la
|
||||
|
||||
|
||||
# Huawei
|
||||
@@ -69,6 +70,20 @@ libmm_plugin_option_la_CPPFLAGS = \
|
||||
|
||||
libmm_plugin_option_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
# Sierra
|
||||
|
||||
libmm_plugin_sierra_la_SOURCES = \
|
||||
mm-modem-sierra.c \
|
||||
mm-modem-sierra.h \
|
||||
mm-plugin-sierra.c \
|
||||
mm-plugin-sierra.h
|
||||
|
||||
libmm_plugin_sierra_la_CPPFLAGS = \
|
||||
$(MM_CFLAGS) \
|
||||
-I$(top_srcdir)/src
|
||||
|
||||
libmm_plugin_sierra_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
BUILT_SOURCES = \
|
||||
mm-modem-gsm-hso-glue.h \
|
||||
mm-modem-gsm-mbm-glue.h
|
||||
|
104
plugins/mm-modem-sierra.c
Normal file
104
plugins/mm-modem-sierra.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- 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-sierra.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
|
||||
static gpointer mm_modem_sierra_parent_class = NULL;
|
||||
|
||||
MMModem *
|
||||
mm_modem_sierra_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_SIERRA,
|
||||
MM_SERIAL_DEVICE, data_device,
|
||||
MM_MODEM_DRIVER, driver,
|
||||
NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
|
||||
if (error)
|
||||
info->error = g_error_copy (error);
|
||||
else if (GPOINTER_TO_INT (mm_callback_info_get_data (info, "sierra-enable"))) {
|
||||
/* Sierra returns OK on +CFUN=1 right away but needs some time
|
||||
to finish initialization */
|
||||
sleep (10);
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
enable (MMModem *modem,
|
||||
gboolean enable,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModem *parent_modem_iface;
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
mm_callback_info_set_data (info, "sierra-enable", GINT_TO_POINTER (enable), NULL);
|
||||
|
||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem));
|
||||
parent_modem_iface->enable (modem, enable, parent_enable_done, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
modem_init (MMModem *modem_class)
|
||||
{
|
||||
modem_class->enable = enable;
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_sierra_init (MMModemSierra *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_sierra_class_init (MMModemSierraClass *klass)
|
||||
{
|
||||
mm_modem_sierra_parent_class = g_type_class_peek_parent (klass);
|
||||
}
|
||||
|
||||
GType
|
||||
mm_modem_sierra_get_type (void)
|
||||
{
|
||||
static GType modem_sierra_type = 0;
|
||||
|
||||
if (G_UNLIKELY (modem_sierra_type == 0)) {
|
||||
static const GTypeInfo modem_sierra_type_info = {
|
||||
sizeof (MMModemSierraClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) mm_modem_sierra_class_init,
|
||||
(GClassFinalizeFunc) NULL,
|
||||
NULL, /* class_data */
|
||||
sizeof (MMModemSierra),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) mm_modem_sierra_init,
|
||||
};
|
||||
|
||||
static const GInterfaceInfo modem_iface_info = {
|
||||
(GInterfaceInitFunc) modem_init
|
||||
};
|
||||
|
||||
modem_sierra_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemSierra", &modem_sierra_type_info, 0);
|
||||
g_type_add_interface_static (modem_sierra_type, MM_TYPE_MODEM, &modem_iface_info);
|
||||
}
|
||||
|
||||
return modem_sierra_type;
|
||||
}
|
28
plugins/mm-modem-sierra.h
Normal file
28
plugins/mm-modem-sierra.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
|
||||
#ifndef MM_MODEM_SIERRA_H
|
||||
#define MM_MODEM_SIERRA_H
|
||||
|
||||
#include "mm-generic-gsm.h"
|
||||
|
||||
#define MM_TYPE_MODEM_SIERRA (mm_modem_sierra_get_type ())
|
||||
#define MM_MODEM_SIERRA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_SIERRA, MMModemSierra))
|
||||
#define MM_MODEM_SIERRA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_SIERRA, MMModemSierraClass))
|
||||
#define MM_IS_MODEM_SIERRA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_SIERRA))
|
||||
#define MM_IS_MODEM_SIERRA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_SIERRA))
|
||||
#define MM_MODEM_SIERRA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_SIERRA, MMModemSierraClass))
|
||||
|
||||
typedef struct {
|
||||
MMGenericGsm parent;
|
||||
} MMModemSierra;
|
||||
|
||||
typedef struct {
|
||||
MMGenericGsmClass parent;
|
||||
} MMModemSierraClass;
|
||||
|
||||
GType mm_modem_sierra_get_type (void);
|
||||
|
||||
MMModem *mm_modem_sierra_new (const char *data_device,
|
||||
const char *driver);
|
||||
|
||||
#endif /* MM_MODEM_SIERRA_H */
|
148
plugins/mm-plugin-sierra.c
Normal file
148
plugins/mm-plugin-sierra.c
Normal file
@@ -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-sierra.h"
|
||||
#include "mm-modem-sierra.h"
|
||||
|
||||
static void plugin_init (MMPlugin *plugin_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMPluginSierra, mm_plugin_sierra, 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_SIERRA, NULL));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
get_name (MMPlugin *plugin)
|
||||
{
|
||||
return "Sierra";
|
||||
}
|
||||
|
||||
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 == 0x1199)
|
||||
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_sierra_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_sierra_init (MMPluginSierra *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_sierra_class_init (MMPluginSierraClass *klass)
|
||||
{
|
||||
}
|
26
plugins/mm-plugin-sierra.h
Normal file
26
plugins/mm-plugin-sierra.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
|
||||
#ifndef MM_PLUGIN_SIERRA_H
|
||||
#define MM_PLUGIN_SIERRA_H
|
||||
|
||||
#include "mm-plugin.h"
|
||||
#include "mm-generic-gsm.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 {
|
||||
GObject parent;
|
||||
} MMPluginSierra;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent;
|
||||
} MMPluginSierraClass;
|
||||
|
||||
GType mm_plugin_sierra_get_type (void);
|
||||
|
||||
#endif /* MM_PLUGIN_SIERRA_H */
|
Reference in New Issue
Block a user