linktop: add plugin for Linktop/Teracom LW273 (bgo #636438)

This commit is contained in:
Amit Mendapara
2010-12-08 11:05:28 -06:00
committed by Dan Williams
parent 26b96c515d
commit 067490960a
5 changed files with 477 additions and 1 deletions
+19 -1
View File
@@ -13,7 +13,8 @@ pkglib_LTLIBRARIES = \
libmm-plugin-longcheer.la \
libmm-plugin-anydata.la \
libmm-plugin-simtech.la \
libmm-plugin-x22x.la
libmm-plugin-x22x.la \
libmm-plugin-linktop.la
# Generic
@@ -294,6 +295,23 @@ libmm_plugin_x22x_la_LDFLAGS = \
-module \
-avoid-version
# Linktop
libmm_plugin_linktop_la_SOURCES = \
mm-plugin-linktop.c \
mm-plugin-linktop.h \
mm-modem-linktop.c \
mm-modem-linktop.h
libmm_plugin_linktop_la_CPPFLAGS = \
$(MM_CFLAGS) \
$(GUDEV_CFLAGS) \
-I$(top_srcdir)/src
libmm_plugin_linktop_la_LDFLAGS = \
$(GUDEV_LDFLAGS) \
-module \
-avoid-version
udevrulesdir = $(UDEV_BASE_DIR)/rules.d
udevrules_DATA = \
+208
View File
@@ -0,0 +1,208 @@
/* -*- 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-linktop.h"
#include "mm-serial-parsers.h"
#include "mm-errors.h"
#define LINKTOP_NETWORK_MODE_ANY 1
#define LINKTOP_NETWORK_MODE_2G 5
#define LINKTOP_NETWORK_MODE_3G 6
static void modem_init (MMModem *modem_class);
G_DEFINE_TYPE_EXTENDED (MMModemLinktop, mm_modem_linktop, MM_TYPE_GENERIC_GSM, 0,
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init))
MMModem *
mm_modem_linktop_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_LINKTOP,
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 gboolean
grab_port (MMModem *modem,
const char *subsys,
const char *name,
MMPortType suggested_type,
gpointer user_data,
GError **error)
{
MMGenericGsm *gsm = MM_GENERIC_GSM (modem);
MMPortType ptype = MM_PORT_TYPE_IGNORED;
MMPort *port = NULL;
if (suggested_type == MM_PORT_TYPE_UNKNOWN) {
if (!mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY))
ptype = MM_PORT_TYPE_PRIMARY;
else if (!mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_SECONDARY))
ptype = MM_PORT_TYPE_SECONDARY;
} else
ptype = suggested_type;
port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error);
if (port && MM_IS_AT_SERIAL_PORT (port)) {
mm_at_serial_port_set_response_parser (MM_AT_SERIAL_PORT (port),
mm_serial_parser_v1_e1_parse,
mm_serial_parser_v1_e1_new (),
mm_serial_parser_v1_e1_destroy);
}
return !!port;
}
static int
linktop_parse_allowed_mode (MMModemGsmAllowedMode network_mode)
{
switch (network_mode) {
case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY:
return LINKTOP_NETWORK_MODE_2G;
case MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY:
return LINKTOP_NETWORK_MODE_3G;
default:
return LINKTOP_NETWORK_MODE_ANY;
}
}
static void
linktop_set_allowed_mode_done (MMAtSerialPort *port,
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
set_allowed_mode (MMGenericGsm *gsm,
MMModemGsmAllowedMode mode,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *command;
MMAtSerialPort *port;
info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data);
port = mm_generic_gsm_get_best_at_port (gsm, &info->error);
if (!port) {
mm_callback_info_schedule (info);
return;
}
command = g_strdup_printf ("+CFUN=%d", linktop_parse_allowed_mode (mode));
mm_at_serial_port_queue_command (port, command, 3, linktop_set_allowed_mode_done, info);
g_free (command);
}
static void
get_allowed_mode_done (MMAtSerialPort *port,
GString *response,
GError *error,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
gboolean parsed = FALSE;
if (error)
info->error = g_error_copy (error);
else if (!g_str_has_prefix (response->str, "CFUN: ")) {
MMModemGsmAllowedMode mode = MM_MODEM_GSM_ALLOWED_MODE_ANY;
int a;
a = atoi (response->str + 6);
if (a == LINKTOP_NETWORK_MODE_2G)
mode = MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY;
else if (a == LINKTOP_NETWORK_MODE_3G)
mode = MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY;
mm_callback_info_set_result (info, GUINT_TO_POINTER (mode), NULL);
parsed = TRUE;
}
if (!error && !parsed)
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Could not parse allowed mode results");
mm_callback_info_schedule (info);
}
static void
get_allowed_mode (MMGenericGsm *gsm,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
MMAtSerialPort *port;
info = mm_callback_info_uint_new (MM_MODEM (gsm), callback, user_data);
port = mm_generic_gsm_get_best_at_port (gsm, &info->error);
if (!port) {
mm_callback_info_schedule (info);
return;
}
mm_at_serial_port_queue_command (port, "+CFUN?", 3, get_allowed_mode_done, info);
}
/*****************************************************************************/
static void
modem_init (MMModem *modem_class)
{
modem_class->grab_port = grab_port;
}
static void
mm_modem_linktop_init (MMModemLinktop *self)
{
}
static void
mm_modem_linktop_class_init (MMModemLinktopClass *klass)
{
MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass);
gsm_class->get_allowed_mode = get_allowed_mode;
gsm_class->set_allowed_mode = set_allowed_mode;
}
+45
View File
@@ -0,0 +1,45 @@
/* -*- 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_LINKTOP_H
#define MM_MODEM_LINKTOP_H
#include "mm-generic-gsm.h"
#define MM_TYPE_MODEM_LINKTOP (mm_modem_linktop_get_type ())
#define MM_MODEM_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_LINKTOP, MMModemLinktop))
#define MM_MODEM_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_LINKTOP, MMModemLinktopClass))
#define MM_IS_MODEM_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_LINKTOP))
#define MM_IS_MODEM_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_LINKTOP))
#define MM_MODEM_LINKTOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_LINKTOP, MMModemLinktopClass))
typedef struct {
MMGenericGsm parent;
} MMModemLinktop;
typedef struct {
MMGenericGsmClass parent;
} MMModemLinktopClass;
GType mm_modem_linktop_get_type (void);
MMModem *mm_modem_linktop_new (const char *data,
const char *driver,
const char *plugin,
guint32 vendor,
guint32 product);
#endif /* MM_MODEM_LINKTOP_H */
+164
View File
@@ -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:
*
* Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 Red Hat, Inc.
*/
#include <string.h>
#include <gmodule.h>
#include "mm-plugin-linktop.h"
#include "mm-modem-linktop.h"
G_DEFINE_TYPE (MMPluginLinktop, mm_plugin_linktop, 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_LINKTOP,
MM_PLUGIN_BASE_NAME, "Linktop",
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;
if (vendor != 0x230d)
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, 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, *devfile, *sysfs_path;
guint32 caps;
guint16 vendor = 0, product = 0;
port = mm_plugin_base_supports_task_get_port (task);
g_assert (port);
devfile = g_udev_device_get_device_file (port);
if (!devfile) {
g_set_error (error, 0, 0, "Could not get port's sysfs file.");
return NULL;
}
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_linktop_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_linktop_init (MMPluginLinktop *self)
{
g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL);
}
static void
mm_plugin_linktop_class_init (MMPluginLinktopClass *klass)
{
MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
pb_class->supports_port = supports_port;
pb_class->grab_port = grab_port;
}
+41
View File
@@ -0,0 +1,41 @@
/* -*- 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_LINKTOP_H
#define MM_PLUGIN_LINKTOP_H
#include "mm-plugin-base.h"
#define MM_TYPE_PLUGIN_LINKTOP (mm_plugin_linktop_get_type ())
#define MM_PLUGIN_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktop))
#define MM_PLUGIN_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktopClass))
#define MM_IS_PLUGIN_LINKTOP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_LINKTOP))
#define MM_IS_PLUGIN_LINKTOP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_LINKTOP))
#define MM_PLUGIN_LINKTOP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_LINKTOP, MMPluginLinktopClass))
typedef struct {
MMPluginBase parent;
} MMPluginLinktop;
typedef struct {
MMPluginBaseClass parent;
} MMPluginLinktopClass;
GType mm_plugin_linktop_get_type (void);
G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
#endif /* MM_PLUGIN_LINKTOP_H */