Implement Novatel plugin.

This commit is contained in:
Tambet Ingo
2009-01-26 11:54:10 +02:00
parent 6b14ebe6ab
commit 2226bb8752
5 changed files with 389 additions and 2 deletions

View File

@@ -3,8 +3,8 @@ pkglib_LTLIBRARIES = \
libmm-plugin-hso.la \
libmm-plugin-mbm.la \
libmm-plugin-option.la \
libmm-plugin-sierra.la
libmm-plugin-sierra.la \
libmm-plugin-novatel.la
# Huawei
@@ -84,6 +84,21 @@ libmm_plugin_sierra_la_CPPFLAGS = \
libmm_plugin_sierra_la_LDFLAGS = -module -avoid-version
# Novatel
libmm_plugin_novatel_la_SOURCES = \
mm-modem-novatel.c \
mm-modem-novatel.h \
mm-plugin-novatel.c \
mm-plugin-novatel.h
libmm_plugin_novatel_la_CPPFLAGS = \
$(MM_CFLAGS) \
-I$(top_srcdir)/src
libmm_plugin_novatel_la_LDFLAGS = -module -avoid-version
BUILT_SOURCES = \
mm-modem-gsm-hso-glue.h \
mm-modem-gsm-mbm-glue.h

170
plugins/mm-modem-novatel.c Normal file
View File

@@ -0,0 +1,170 @@
/* -*- 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-novatel.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
static gpointer mm_modem_novatel_parent_class = NULL;
MMModem *
mm_modem_novatel_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_NOVATEL,
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 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, novatel 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 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 (!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_novatel_init (MMModemNovatel *self)
{
}
static void
mm_modem_novatel_class_init (MMModemNovatelClass *klass)
{
mm_modem_novatel_parent_class = g_type_class_peek_parent (klass);
}
GType
mm_modem_novatel_get_type (void)
{
static GType modem_novatel_type = 0;
if (G_UNLIKELY (modem_novatel_type == 0)) {
static const GTypeInfo modem_novatel_type_info = {
sizeof (MMModemNovatelClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) mm_modem_novatel_class_init,
(GClassFinalizeFunc) NULL,
NULL, /* class_data */
sizeof (MMModemNovatel),
0, /* n_preallocs */
(GInstanceInitFunc) mm_modem_novatel_init,
};
static const GInterfaceInfo modem_iface_info = {
(GInterfaceInitFunc) modem_init
};
modem_novatel_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemNovatel", &modem_novatel_type_info, 0);
g_type_add_interface_static (modem_novatel_type, MM_TYPE_MODEM, &modem_iface_info);
}
return modem_novatel_type;
}

View File

@@ -0,0 +1,28 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef MM_MODEM_NOVATEL_H
#define MM_MODEM_NOVATEL_H
#include "mm-generic-gsm.h"
#define MM_TYPE_MODEM_NOVATEL (mm_modem_novatel_get_type ())
#define MM_MODEM_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_NOVATEL, MMModemNovatel))
#define MM_MODEM_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_NOVATEL, MMModemNovatelClass))
#define MM_IS_MODEM_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_NOVATEL))
#define MM_IS_MODEM_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_NOVATEL))
#define MM_MODEM_NOVATEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_NOVATEL, MMModemNovatelClass))
typedef struct {
MMGenericGsm parent;
} MMModemNovatel;
typedef struct {
MMGenericGsmClass parent;
} MMModemNovatelClass;
GType mm_modem_novatel_get_type (void);
MMModem *mm_modem_novatel_new (const char *data_device,
const char *driver);
#endif /* MM_MODEM_NOVATEL_H */

148
plugins/mm-plugin-novatel.c Normal file
View 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-novatel.h"
#include "mm-modem-novatel.h"
static void plugin_init (MMPlugin *plugin_class);
G_DEFINE_TYPE_EXTENDED (MMPluginNovatel, mm_plugin_novatel, 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_NOVATEL, NULL));
}
/*****************************************************************************/
static const char *
get_name (MMPlugin *plugin)
{
return "Novatel";
}
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 == 0x1410)
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_novatel_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_novatel_init (MMPluginNovatel *self)
{
}
static void
mm_plugin_novatel_class_init (MMPluginNovatelClass *klass)
{
}

View File

@@ -0,0 +1,26 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef MM_PLUGIN_NOVATEL_H
#define MM_PLUGIN_NOVATEL_H
#include "mm-plugin.h"
#include "mm-generic-gsm.h"
#define MM_TYPE_PLUGIN_NOVATEL (mm_plugin_novatel_get_type ())
#define MM_PLUGIN_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_NOVATEL, MMPluginNovatel))
#define MM_PLUGIN_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_NOVATEL, MMPluginNovatelClass))
#define MM_IS_PLUGIN_NOVATEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_NOVATEL))
#define MM_IS_PLUGIN_NOVATEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_NOVATEL))
#define MM_PLUGIN_NOVATEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_NOVATEL, MMPluginNovatelClass))
typedef struct {
GObject parent;
} MMPluginNovatel;
typedef struct {
GObjectClass parent;
} MMPluginNovatelClass;
GType mm_plugin_novatel_get_type (void);
#endif /* MM_PLUGIN_NOVATEL_H */