simtech: add plugin for Simtech-based modems (like A-Link 3GU)
This commit is contained in:
29
plugins/77-mm-simtech-port-types.rules
Normal file
29
plugins/77-mm-simtech-port-types.rules
Normal file
@@ -0,0 +1,29 @@
|
||||
# do not edit this file, it will be overwritten on update
|
||||
|
||||
# Simtech makes modules that other companies rebrand, like:
|
||||
#
|
||||
# A-LINK 3GU
|
||||
#
|
||||
# Most of these values were scraped from various SimTech-based Windows
|
||||
# driver .inf files. *mdm.inf lists the main command ports, while
|
||||
# *ser.inf lists the aux ports that may be used for PPP.
|
||||
|
||||
|
||||
ACTION!="add|change", GOTO="mm_simtech_port_types_end"
|
||||
SUBSYSTEM!="tty", GOTO="mm_simtech_port_types_end"
|
||||
|
||||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1e0e", GOTO="mm_alink_vendorcheck"
|
||||
GOTO="mm_simtech_port_types_end"
|
||||
|
||||
LABEL="mm_alink_vendorcheck"
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="?*", ENV{.MM_USBIFNUM}="$attr{bInterfaceNumber}"
|
||||
|
||||
ATTRS{idProduct}=="9200", ENV{.MM_USBIFNUM}=="03", ENV{ID_MM_SIMTECH_PORT_TYPE_MODEM}="1"
|
||||
ATTRS{idProduct}=="9200", ENV{.MM_USBIFNUM}=="01", ENV{ID_MM_SIMTECH_PORT_TYPE_AUX}="1"
|
||||
ATTRS{idProduct}=="9200", ENV{ID_MM_SIMTECH_TAGGED}="1"
|
||||
|
||||
GOTO="mm_simtech_port_types_end"
|
||||
|
||||
|
||||
LABEL="mm_simtech_port_types_end"
|
||||
|
@@ -255,12 +255,31 @@ libmm_plugin_anydata_la_LDFLAGS = \
|
||||
-module \
|
||||
-avoid-version
|
||||
|
||||
# SimTech
|
||||
|
||||
libmm_plugin_anydata_la_SOURCES = \
|
||||
mm-plugin-simtech.c \
|
||||
mm-plugin-simtech.h \
|
||||
mm-modem-simtech-gsm.c \
|
||||
mm-modem-simtech-gsm.h
|
||||
|
||||
libmm_plugin_simtech_la_CPPFLAGS = \
|
||||
$(MM_CFLAGS) \
|
||||
$(GUDEV_CFLAGS) \
|
||||
-I$(top_srcdir)/src
|
||||
|
||||
libmm_plugin_simtech_la_LDFLAGS = \
|
||||
$(GUDEV_LDFLAGS) \
|
||||
-module \
|
||||
-avoid-version
|
||||
|
||||
|
||||
udevrulesdir = $(UDEV_BASE_DIR)/rules.d
|
||||
udevrules_DATA = \
|
||||
77-mm-ericsson-mbm.rules \
|
||||
77-mm-zte-port-types.rules \
|
||||
77-mm-longcheer-port-types.rules
|
||||
77-mm-longcheer-port-types.rules \
|
||||
77-mm-simtech-port-types.rules
|
||||
|
||||
BUILT_SOURCES = \
|
||||
mm-modem-gsm-hso-glue.h
|
||||
|
471
plugins/mm-modem-simtech-gsm.c
Normal file
471
plugins/mm-modem-simtech-gsm.c
Normal file
@@ -0,0 +1,471 @@
|
||||
/* -*- 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 - 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include "mm-modem-simtech-gsm.h"
|
||||
#include "mm-at-serial-port.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
|
||||
static void modem_init (MMModem *modem_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMModemSimtechGsm, mm_modem_simtech_gsm, MM_TYPE_GENERIC_GSM, 0,
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init))
|
||||
|
||||
MMModem *
|
||||
mm_modem_simtech_gsm_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin)
|
||||
{
|
||||
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_SIMTECH_GSM,
|
||||
MM_MODEM_MASTER_DEVICE, device,
|
||||
MM_MODEM_DRIVER, driver,
|
||||
MM_MODEM_PLUGIN, plugin,
|
||||
NULL));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define ACQ_ORDER_TAG "acq-order"
|
||||
|
||||
static void
|
||||
get_mode_pref_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
const char *p;
|
||||
gint modepref = -1;
|
||||
guint32 acqord;
|
||||
MMModemGsmAllowedMode allowed = MM_MODEM_GSM_ALLOWED_MODE_ANY;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error)
|
||||
goto done;
|
||||
|
||||
p = mm_strip_tag (response->str, "+CNMP:");
|
||||
if (!p) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Failed to parse the mode preference response");
|
||||
goto done;
|
||||
}
|
||||
|
||||
acqord = GPOINTER_TO_UINT (mm_callback_info_get_data (info, ACQ_ORDER_TAG));
|
||||
modepref = atoi (p);
|
||||
|
||||
if (modepref == 2) {
|
||||
/* Automatic */
|
||||
if (acqord == 0)
|
||||
allowed = MM_MODEM_GSM_ALLOWED_MODE_ANY;
|
||||
else if (acqord == 1)
|
||||
allowed = MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED;
|
||||
else if (acqord == 2)
|
||||
allowed = MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED;
|
||||
else {
|
||||
info->error = g_error_new (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Unknown acqisition order preference %d",
|
||||
acqord);
|
||||
}
|
||||
} else if (modepref == 13) {
|
||||
/* GSM only */
|
||||
allowed = MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY;
|
||||
} else if (modepref == 14) {
|
||||
/* WCDMA only */
|
||||
allowed = MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY;
|
||||
} else {
|
||||
info->error = g_error_new (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Unknown mode preference %d",
|
||||
modepref);
|
||||
}
|
||||
|
||||
done:
|
||||
if (!info->error)
|
||||
mm_callback_info_set_result (info, GUINT_TO_POINTER (allowed), NULL);
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
get_acq_order_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
const char *p;
|
||||
gint acqord = -1;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error)
|
||||
goto done;
|
||||
|
||||
p = mm_strip_tag (response->str, "+CNAOP:");
|
||||
if (!p) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Failed to parse the acqisition order response");
|
||||
goto done;
|
||||
}
|
||||
|
||||
acqord = atoi (p);
|
||||
if (acqord < 0 || acqord > 2) {
|
||||
info->error = g_error_new (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Unknown acquisition order response %d",
|
||||
acqord);
|
||||
} else {
|
||||
/* Cache the acquisition preference */
|
||||
mm_callback_info_set_data (info, ACQ_ORDER_TAG, GUINT_TO_POINTER (acqord), NULL);
|
||||
}
|
||||
|
||||
done:
|
||||
if (info->error)
|
||||
mm_callback_info_schedule (info);
|
||||
else
|
||||
mm_at_serial_port_queue_command (port, "+CNMP?", 3, get_mode_pref_done, 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, "+CNAOP?", 3, get_acq_order_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
set_acq_order_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_mode_pref_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
guint32 naop;
|
||||
char *command;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
naop = GPOINTER_TO_UINT (mm_callback_info_get_data (info, ACQ_ORDER_TAG));
|
||||
command = g_strdup_printf ("+CNAOP=%u", naop);
|
||||
mm_at_serial_port_queue_command (port, command, 3, set_acq_order_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
static void
|
||||
set_allowed_mode (MMGenericGsm *gsm,
|
||||
MMModemGsmAllowedMode mode,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMAtSerialPort *port;
|
||||
char *command;
|
||||
guint32 nmp = 2; /* automatic mode preference */
|
||||
guint32 naop = 0; /* automatic acquisition order */
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY:
|
||||
nmp = 13;
|
||||
break;
|
||||
case MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY:
|
||||
nmp = 14;
|
||||
break;
|
||||
case MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED:
|
||||
naop = 2;
|
||||
break;
|
||||
case MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED:
|
||||
naop = 3;
|
||||
break;
|
||||
case MM_MODEM_GSM_ALLOWED_MODE_ANY:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
mm_callback_info_set_data (info, ACQ_ORDER_TAG, GUINT_TO_POINTER (naop), NULL);
|
||||
|
||||
command = g_strdup_printf ("+CNMP=%u", nmp);
|
||||
mm_at_serial_port_queue_command (port, command, 3, set_mode_pref_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
static MMModemGsmAccessTech
|
||||
simtech_act_to_mm_act (int nsmod)
|
||||
{
|
||||
if (nsmod == 1)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_GSM;
|
||||
else if (nsmod == 2)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_GPRS;
|
||||
else if (nsmod == 3)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_EDGE;
|
||||
else if (nsmod == 4)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_UMTS;
|
||||
else if (nsmod == 5)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_HSDPA;
|
||||
else if (nsmod == 6)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_HSUPA;
|
||||
else if (nsmod == 7)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_HSPA;
|
||||
|
||||
return MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
}
|
||||
|
||||
static void
|
||||
get_act_tech_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = user_data;
|
||||
MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
const char *p;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
p = mm_strip_tag (response->str, "+CNSMOD:");
|
||||
if (p)
|
||||
p = strchr (p, ',');
|
||||
|
||||
if (!p || !isdigit (*(p + 1))) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Failed to parse the access technology response");
|
||||
} else {
|
||||
act = simtech_act_to_mm_act (atoi (p + 1));
|
||||
mm_callback_info_set_result (info, GUINT_TO_POINTER (act), NULL);
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
get_access_technology (MMGenericGsm *modem,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMAtSerialPort *port;
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
||||
|
||||
port = mm_generic_gsm_get_best_at_port (modem, &info->error);
|
||||
if (!port) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
mm_at_serial_port_queue_command (port, "AT+CNSMOD?", 3, get_act_tech_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_act_change (MMAtSerialPort *port,
|
||||
GMatchInfo *match_info,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemSimtechGsm *self = MM_MODEM_SIMTECH_GSM (user_data);
|
||||
MMModemGsmAccessTech act;
|
||||
char *str;
|
||||
|
||||
str = g_match_info_fetch (match_info, 2);
|
||||
if (str && strlen (str)) {
|
||||
act = simtech_act_to_mm_act (atoi (str));
|
||||
mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act);
|
||||
}
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
real_do_enable_power_up_done (MMGenericGsm *gsm,
|
||||
GString *response,
|
||||
GError *error,
|
||||
MMCallbackInfo *info)
|
||||
{
|
||||
if (!error) {
|
||||
MMAtSerialPort *primary;
|
||||
|
||||
/* Enable unsolicited result codes */
|
||||
primary = mm_generic_gsm_get_at_port (gsm, MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
/* Autoreport access technology changes */
|
||||
mm_at_serial_port_queue_command (primary, "+CNSMOD=1", 5, NULL, NULL);
|
||||
|
||||
/* Autoreport CSQ (first arg), and only report when it changes (second arg) */
|
||||
mm_at_serial_port_queue_command (primary, "+AUTOCSQ=1,1", 5, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Chain up to parent */
|
||||
MM_GENERIC_GSM_CLASS (mm_modem_simtech_gsm_parent_class)->do_enable_power_up_done (gsm, NULL, error, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
MMModem *modem;
|
||||
MMModemFn callback;
|
||||
gpointer user_data;
|
||||
} DisableInfo;
|
||||
|
||||
static void
|
||||
disable_unsolicited_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
|
||||
{
|
||||
MMModem *parent_modem_iface;
|
||||
DisableInfo *info = user_data;
|
||||
|
||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem));
|
||||
parent_modem_iface->disable (info->modem, info->callback, info->user_data);
|
||||
g_free (info);
|
||||
}
|
||||
|
||||
static void
|
||||
disable (MMModem *modem,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMAtSerialPort *primary;
|
||||
DisableInfo *info;
|
||||
|
||||
info = g_malloc0 (sizeof (DisableInfo));
|
||||
info->callback = callback;
|
||||
info->user_data = user_data;
|
||||
info->modem = modem;
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
/* Turn off unsolicited responses */
|
||||
mm_at_serial_port_queue_command (primary, "+CNSMOD=0;+AUTOCSQ=0", 5, disable_unsolicited_done, info);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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)) {
|
||||
GRegex *regex;
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\+CNSMOD:\\s*(\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (port), regex, handle_act_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
|
||||
return !!port;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
modem_init (MMModem *modem_class)
|
||||
{
|
||||
modem_class->disable = disable;
|
||||
modem_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_simtech_gsm_init (MMModemSimtechGsm *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_simtech_gsm_class_init (MMModemSimtechGsmClass *klass)
|
||||
{
|
||||
MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass);
|
||||
|
||||
mm_modem_simtech_gsm_parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
gsm_class->do_enable_power_up_done = real_do_enable_power_up_done;
|
||||
gsm_class->set_allowed_mode = set_allowed_mode;
|
||||
gsm_class->get_allowed_mode = get_allowed_mode;
|
||||
gsm_class->get_access_technology = get_access_technology;
|
||||
}
|
||||
|
43
plugins/mm-modem-simtech-gsm.h
Normal file
43
plugins/mm-modem-simtech-gsm.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* -*- 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 - 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_SIMTECH_GSM_H
|
||||
#define MM_MODEM_SIMTECH_GSM_H
|
||||
|
||||
#include "mm-generic-gsm.h"
|
||||
|
||||
#define MM_TYPE_MODEM_SIMTECH_GSM (mm_modem_simtech_gsm_get_type ())
|
||||
#define MM_MODEM_SIMTECH_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_SIMTECH_GSM, MMModemSimtechGsm))
|
||||
#define MM_MODEM_SIMTECH_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_SIMTECH_GSM, MMModemSimtechGsmClass))
|
||||
#define MM_IS_MODEM_SIMTECH_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_SIMTECH_GSM))
|
||||
#define MM_IS_MODEM_SIMTECH_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_SIMTECH_GSM))
|
||||
#define MM_MODEM_SIMTECH_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_SIMTECH_GSM, MMModemSimtechGsmClass))
|
||||
|
||||
typedef struct {
|
||||
MMGenericGsm parent;
|
||||
} MMModemSimtechGsm;
|
||||
|
||||
typedef struct {
|
||||
MMGenericGsmClass parent;
|
||||
} MMModemSimtechGsmClass;
|
||||
|
||||
GType mm_modem_simtech_gsm_get_type (void);
|
||||
|
||||
MMModem *mm_modem_simtech_gsm_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin);
|
||||
|
||||
#endif /* MM_MODEM_SIMTECH_H */
|
189
plugins/mm-plugin-simtech.c
Normal file
189
plugins/mm-plugin-simtech.c
Normal file
@@ -0,0 +1,189 @@
|
||||
/* -*- 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 - 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <gmodule.h>
|
||||
#include "mm-plugin-simtech.h"
|
||||
#include "mm-modem-simtech-gsm.h"
|
||||
#include "mm-generic-gsm.h"
|
||||
#include "mm-generic-cdma.h"
|
||||
|
||||
G_DEFINE_TYPE (MMPluginSimtech, mm_plugin_simtech, 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_SIMTECH,
|
||||
MM_PLUGIN_BASE_NAME, "SimTech",
|
||||
NULL));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define CAP_CDMA (MM_PLUGIN_BASE_PORT_CAP_IS707_A | \
|
||||
MM_PLUGIN_BASE_PORT_CAP_IS707_P | \
|
||||
MM_PLUGIN_BASE_PORT_CAP_IS856 | \
|
||||
MM_PLUGIN_BASE_PORT_CAP_IS856_A)
|
||||
|
||||
static guint32
|
||||
get_level_for_capabilities (guint32 capabilities)
|
||||
{
|
||||
if (capabilities & MM_PLUGIN_BASE_PORT_CAP_GSM)
|
||||
return 10;
|
||||
if (capabilities & CAP_CDMA)
|
||||
return 10;
|
||||
if (capabilities & MM_PLUGIN_BASE_PORT_CAP_QCDM)
|
||||
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;
|
||||
guint16 vendor = 0;
|
||||
const char *subsys, *name;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* A-Link (for now) */
|
||||
if (vendor != 0x1e0e)
|
||||
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, *sysfs_path;
|
||||
guint32 caps;
|
||||
MMPortType ptype = MM_PORT_TYPE_UNKNOWN;
|
||||
|
||||
port = mm_plugin_base_supports_task_get_port (task);
|
||||
g_assert (port);
|
||||
|
||||
/* Look for port type hints; just probing can't distinguish which port should
|
||||
* be the data/primary port on these devices. We have to tag them based on
|
||||
* what the Windows .INF files say the port layout should be.
|
||||
*/
|
||||
if (g_udev_device_get_property_as_boolean (port, "ID_MM_SIMTECH_PORT_TYPE_MODEM"))
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else if (g_udev_device_get_property_as_boolean (port, "ID_MM_SIMTECH_PORT_TYPE_AUX"))
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
|
||||
/* If the device was tagged by the udev rules, then ignore any other ports
|
||||
* to guard against race conditions if a device just happens to show up
|
||||
* with more than two AT-capable ports.
|
||||
*/
|
||||
if ( (ptype == MM_PORT_TYPE_UNKNOWN)
|
||||
&& g_udev_device_get_property_as_boolean (port, "ID_MM_SIMTECH_TAGGED"))
|
||||
ptype = MM_PORT_TYPE_IGNORED;
|
||||
|
||||
subsys = g_udev_device_get_subsystem (port);
|
||||
name = g_udev_device_get_name (port);
|
||||
|
||||
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_simtech_gsm_new (sysfs_path,
|
||||
mm_plugin_base_supports_task_get_driver (task),
|
||||
mm_plugin_get_name (MM_PLUGIN (base)));
|
||||
} else if (caps & CAP_CDMA) {
|
||||
modem = mm_generic_cdma_new (sysfs_path,
|
||||
mm_plugin_base_supports_task_get_driver (task),
|
||||
mm_plugin_get_name (MM_PLUGIN (base)),
|
||||
!!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856),
|
||||
!!(caps & MM_PLUGIN_BASE_PORT_CAP_IS856_A));
|
||||
}
|
||||
|
||||
if (modem) {
|
||||
if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error)) {
|
||||
g_object_unref (modem);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else if (get_level_for_capabilities (caps)) {
|
||||
if (caps & MM_PLUGIN_BASE_PORT_CAP_QCDM)
|
||||
ptype = MM_PORT_TYPE_QCDM;
|
||||
|
||||
modem = existing;
|
||||
if (!mm_modem_grab_port (modem, subsys, name, ptype, NULL, error))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return modem;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_plugin_simtech_init (MMPluginSimtech *self)
|
||||
{
|
||||
g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_simtech_class_init (MMPluginSimtechClass *klass)
|
||||
{
|
||||
MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
|
||||
|
||||
pb_class->supports_port = supports_port;
|
||||
pb_class->grab_port = grab_port;
|
||||
}
|
41
plugins/mm-plugin-simtech.h
Normal file
41
plugins/mm-plugin-simtech.h
Normal 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 - 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_PLUGIN_SIMTECH_H
|
||||
#define MM_PLUGIN_SIMTECH_H
|
||||
|
||||
#include "mm-plugin-base.h"
|
||||
|
||||
#define MM_TYPE_PLUGIN_SIMTECH (mm_plugin_simtech_get_type ())
|
||||
#define MM_PLUGIN_SIMTECH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_SIMTECH, MMPluginSimtech))
|
||||
#define MM_PLUGIN_SIMTECH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_SIMTECH, MMPluginSimtechClass))
|
||||
#define MM_IS_PLUGIN_SIMTECH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_SIMTECH))
|
||||
#define MM_IS_PLUGIN_SIMTECH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_SIMTECH))
|
||||
#define MM_PLUGIN_SIMTECH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_SIMTECH, MMPluginSimtechClass))
|
||||
|
||||
typedef struct {
|
||||
MMPluginBase parent;
|
||||
} MMPluginSimtech;
|
||||
|
||||
typedef struct {
|
||||
MMPluginBaseClass parent;
|
||||
} MMPluginSimtechClass;
|
||||
|
||||
GType mm_plugin_simtech_get_type (void);
|
||||
|
||||
G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
|
||||
|
||||
#endif /* MM_PLUGIN_SIMTECH_H */
|
Reference in New Issue
Block a user