Merge commit 'origin/anydata'
This commit is contained in:
@@ -10,7 +10,8 @@ pkglib_LTLIBRARIES = \
|
||||
libmm-plugin-nokia.la \
|
||||
libmm-plugin-zte.la \
|
||||
libmm-plugin-mbm.la \
|
||||
libmm-plugin-longcheer.la
|
||||
libmm-plugin-longcheer.la \
|
||||
libmm-plugin-anydata.la
|
||||
|
||||
# Generic
|
||||
|
||||
@@ -232,6 +233,24 @@ libmm_plugin_longcheer_la_LDFLAGS = \
|
||||
-module \
|
||||
-avoid-version
|
||||
|
||||
# AnyData CDMA
|
||||
|
||||
libmm_plugin_anydata_la_SOURCES = \
|
||||
mm-plugin-anydata.c \
|
||||
mm-plugin-anydata.h \
|
||||
mm-modem-anydata-cdma.c \
|
||||
mm-modem-anydata-cdma.h
|
||||
|
||||
libmm_plugin_anydata_la_CPPFLAGS = \
|
||||
$(MM_CFLAGS) \
|
||||
$(GUDEV_CFLAGS) \
|
||||
-I$(top_srcdir)/src
|
||||
|
||||
libmm_plugin_anydata_la_LDFLAGS = \
|
||||
$(GUDEV_LDFLAGS) \
|
||||
-module \
|
||||
-avoid-version
|
||||
|
||||
|
||||
udevrulesdir = $(UDEV_BASE_DIR)/rules.d
|
||||
udevrules_DATA = \
|
||||
|
384
plugins/mm-modem-anydata-cdma.c
Normal file
384
plugins/mm-modem-anydata-cdma.c
Normal file
@@ -0,0 +1,384 @@
|
||||
/* -*- 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "mm-modem-anydata-cdma.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
#include "mm-serial-port.h"
|
||||
#include "mm-serial-parsers.h"
|
||||
|
||||
static void modem_init (MMModem *modem_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMModemAnydataCdma, mm_modem_anydata_cdma, MM_TYPE_GENERIC_CDMA, 0,
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init))
|
||||
|
||||
MMModem *
|
||||
mm_modem_anydata_cdma_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin,
|
||||
gboolean evdo_rev0,
|
||||
gboolean evdo_revA)
|
||||
{
|
||||
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_ANYDATA_CDMA,
|
||||
MM_MODEM_MASTER_DEVICE, device,
|
||||
MM_MODEM_DRIVER, driver,
|
||||
MM_MODEM_PLUGIN, plugin,
|
||||
MM_GENERIC_CDMA_EVDO_REV0, evdo_rev0,
|
||||
MM_GENERIC_CDMA_EVDO_REVA, evdo_revA,
|
||||
MM_GENERIC_CDMA_REGISTRATION_TRY_CSS, FALSE,
|
||||
NULL));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static const char *
|
||||
strip_response (const char *resp, const char *cmd)
|
||||
{
|
||||
const char *p = resp;
|
||||
|
||||
if (p) {
|
||||
if (!strncmp (p, cmd, strlen (cmd)))
|
||||
p += strlen (cmd);
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
uint_from_match_item (GMatchInfo *match_info, guint32 num, guint32 *val)
|
||||
{
|
||||
long int tmp;
|
||||
char *str;
|
||||
gboolean success = FALSE;
|
||||
|
||||
str = g_match_info_fetch (match_info, num);
|
||||
g_return_val_if_fail (str != NULL, FALSE);
|
||||
|
||||
errno = 0;
|
||||
tmp = strtol (str, NULL, 10);
|
||||
if (errno == 0 && tmp >= 0 && tmp <= G_MAXUINT) {
|
||||
*val = (guint32) tmp;
|
||||
success = TRUE;
|
||||
}
|
||||
g_free (str);
|
||||
return success;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
int_from_match_item (GMatchInfo *match_info, guint32 num, gint *val)
|
||||
{
|
||||
long int tmp;
|
||||
char *str;
|
||||
gboolean success = FALSE;
|
||||
|
||||
str = g_match_info_fetch (match_info, num);
|
||||
g_return_val_if_fail (str != NULL, FALSE);
|
||||
|
||||
errno = 0;
|
||||
tmp = strtol (str, NULL, 10);
|
||||
if (errno == 0 && tmp >= G_MININT && tmp <= G_MAXINT) {
|
||||
*val = (gint) tmp;
|
||||
success = TRUE;
|
||||
}
|
||||
g_free (str);
|
||||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
evdo_state_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemCdmaRegistrationState reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
|
||||
const char *reply;
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error) {
|
||||
if (info->modem) {
|
||||
/* If HSTATE returned an error, assume the device is not EVDO capable
|
||||
* or EVDO is not registered.
|
||||
*/
|
||||
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
reply = strip_response (response->str, "*HSTATE:");
|
||||
|
||||
/* Format is "<at state>,<session state>,<channel>,<pn>,<EcIo>,<rssi>,..." */
|
||||
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,\\s*([^,\\)]*)\\s*,.*",
|
||||
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
if (!r) {
|
||||
/* Parse error; warn about it and assume EVDO is not available */
|
||||
g_warning ("AnyData(%s): failed to create EVDO state regex: (%d) %s",
|
||||
__func__,
|
||||
error ? error->code : -1,
|
||||
error && error->message ? error->message : "(unknown)");
|
||||
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
g_regex_match (r, reply, 0, &match_info);
|
||||
if (g_match_info_get_match_count (match_info) >= 6) {
|
||||
guint32 val = 0;
|
||||
gint dbm = 0;
|
||||
|
||||
/* dBm is between -106 (worst) and -20.7 (best) */
|
||||
int_from_match_item (match_info, 6, &dbm);
|
||||
|
||||
/* Parse the EVDO radio state */
|
||||
if (uint_from_match_item (match_info, 1, &val)) {
|
||||
switch (val) {
|
||||
case 3: /* IDLE */
|
||||
/* If IDLE and the EVDO dBm is -105 or lower, assume no service.
|
||||
* It may be that IDLE actually means NO SERVICE too; not sure.
|
||||
*/
|
||||
if (dbm > -105)
|
||||
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
|
||||
break;
|
||||
case 4: /* ACCESS */
|
||||
case 5: /* CONNECT */
|
||||
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
|
||||
break;
|
||||
default:
|
||||
g_message ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
|
||||
/* fall through */
|
||||
case 0: /* NO SERVICE */
|
||||
case 1: /* ACQUISITION */
|
||||
case 2: /* SYNC */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, reg_state);
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
state_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemCdmaRegistrationState reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
|
||||
const char *reply;
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (info->error) {
|
||||
if (info->modem) {
|
||||
/* Assume if we got this far, we're registered even if an error
|
||||
* occurred. We're not sure if all AnyData CDMA modems support
|
||||
* the *STATE and *HSTATE commands.
|
||||
*/
|
||||
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED);
|
||||
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
reply = strip_response (response->str, "*STATE:");
|
||||
|
||||
/* Format is "<channel>,<pn>,<sid>,<nid>,<state>,<rssi>,..." */
|
||||
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,.*",
|
||||
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
if (!r) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR,
|
||||
MM_MODEM_ERROR_GENERAL,
|
||||
"Could not parse sysinfo results (regex creation failed).");
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
g_regex_match (r, reply, 0, &match_info);
|
||||
if (g_match_info_get_match_count (match_info) >= 6) {
|
||||
guint32 val = 0;
|
||||
gint dbm = 0;
|
||||
|
||||
/* dBm is between -106 (worst) and -20.7 (best) */
|
||||
int_from_match_item (match_info, 6, &dbm);
|
||||
|
||||
/* Parse the 1x radio state */
|
||||
if (uint_from_match_item (match_info, 5, &val)) {
|
||||
switch (val) {
|
||||
case 1: /* IDLE */
|
||||
/* If IDLE and the 1X dBm is -105 or lower, assume no service.
|
||||
* It may be that IDLE actually means NO SERVICE too; not sure.
|
||||
*/
|
||||
if (dbm > -105)
|
||||
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
|
||||
break;
|
||||
case 2: /* ACCESS */
|
||||
case 3: /* PAGING */
|
||||
case 4: /* TRAFFIC */
|
||||
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
|
||||
break;
|
||||
default:
|
||||
g_message ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
|
||||
/* fall through */
|
||||
case 0: /* NO SERVICE */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state);
|
||||
|
||||
/* Try for EVDO state too */
|
||||
mm_serial_port_queue_command (port, "*HSTATE?", 3, evdo_state_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
query_registration_state (MMGenericCdma *cdma,
|
||||
MMModemCdmaRegistrationStateFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMSerialPort *primary, *secondary, *port;
|
||||
|
||||
port = primary = mm_generic_cdma_get_port (cdma, MM_PORT_TYPE_PRIMARY);
|
||||
secondary = mm_generic_cdma_get_port (cdma, MM_PORT_TYPE_SECONDARY);
|
||||
|
||||
info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, callback, user_data);
|
||||
|
||||
if (mm_port_get_connected (MM_PORT (primary))) {
|
||||
if (!secondary) {
|
||||
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_CONNECTED,
|
||||
"Cannot get query registration state while connected");
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Use secondary port if primary is connected */
|
||||
port = secondary;
|
||||
}
|
||||
|
||||
mm_serial_port_queue_command (port, "*STATE?", 3, state_done, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
grab_port (MMModem *modem,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType suggested_type,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
MMPort *port = NULL;
|
||||
GRegex *regex;
|
||||
|
||||
port = mm_generic_cdma_grab_port (MM_GENERIC_CDMA (modem), subsys, name, suggested_type, user_data, error);
|
||||
if (port && MM_IS_SERIAL_PORT (port)) {
|
||||
/* Data state notifications */
|
||||
|
||||
/* Data call has connected */
|
||||
regex = g_regex_new ("\\r\\n\\*ACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
/* Data call disconnected */
|
||||
regex = g_regex_new ("\\r\\n\\*INACTIVE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
/* Modem is now dormant */
|
||||
regex = g_regex_new ("\\r\\n\\*DORMANT:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
/* Abnomral state notifications
|
||||
*
|
||||
* FIXME: set 1X/EVDO registration state to UNKNOWN when these
|
||||
* notifications are received?
|
||||
*/
|
||||
|
||||
/* Network acquisition fail */
|
||||
regex = g_regex_new ("\\r\\n\\*OFFLINE:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
/* Registration fail */
|
||||
regex = g_regex_new ("\\r\\n\\*REGREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
/* Authentication fail */
|
||||
regex = g_regex_new ("\\r\\n\\*AUTHREQ:(.*)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
|
||||
return !!port;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
modem_init (MMModem *modem_class)
|
||||
{
|
||||
modem_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_anydata_cdma_init (MMModemAnydataCdma *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_anydata_cdma_class_init (MMModemAnydataCdmaClass *klass)
|
||||
{
|
||||
MMGenericCdmaClass *cdma_class = MM_GENERIC_CDMA_CLASS (klass);
|
||||
|
||||
mm_modem_anydata_cdma_parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
cdma_class->query_registration_state = query_registration_state;
|
||||
|
||||
#if 0
|
||||
/* FIXME: maybe use AT*SLEEP=0/1 to disable/enable slotted mode for powersave */
|
||||
cdma_class->post_enable = post_enable;
|
||||
cdma_class->post_enable = post_disable;
|
||||
#endif
|
||||
}
|
||||
|
45
plugins/mm-modem-anydata-cdma.h
Normal file
45
plugins/mm-modem-anydata-cdma.h
Normal 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 - 2010 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_ANYDATA_CDMA_H
|
||||
#define MM_MODEM_ANYDATA_CDMA_H
|
||||
|
||||
#include "mm-generic-cdma.h"
|
||||
|
||||
#define MM_TYPE_MODEM_ANYDATA_CDMA (mm_modem_anydata_cdma_get_type ())
|
||||
#define MM_MODEM_ANYDATA_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_ANYDATA_CDMA, MMModemAnydataCdma))
|
||||
#define MM_MODEM_ANYDATA_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_ANYDATA_CDMA, MMModemAnydataCdmaClass))
|
||||
#define MM_IS_MODEM_ANYDATA_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_ANYDATA_CDMA))
|
||||
#define MM_IS_MODEM_ANYDATA_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_ANYDATA_CDMA))
|
||||
#define MM_MODEM_ANYDATA_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_ANYDATA_CDMA, MMModemAnydataCdmaClass))
|
||||
|
||||
typedef struct {
|
||||
MMGenericCdma parent;
|
||||
} MMModemAnydataCdma;
|
||||
|
||||
typedef struct {
|
||||
MMGenericCdmaClass parent;
|
||||
} MMModemAnydataCdmaClass;
|
||||
|
||||
GType mm_modem_anydata_cdma_get_type (void);
|
||||
|
||||
MMModem *mm_modem_anydata_cdma_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin,
|
||||
gboolean evdo_rev0,
|
||||
gboolean evdo_revA);
|
||||
|
||||
#endif /* MM_MODEM_ANYDATA_CDMA_H */
|
179
plugins/mm-plugin-anydata.c
Normal file
179
plugins/mm-plugin-anydata.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/* -*- 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-anydata.h"
|
||||
#include "mm-modem-anydata-cdma.h"
|
||||
|
||||
G_DEFINE_TYPE (MMPluginAnydata, mm_plugin_anydata, 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_ANYDATA,
|
||||
MM_PLUGIN_BASE_NAME, "AnyData",
|
||||
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)
|
||||
{
|
||||
/* Only CDMA for now */
|
||||
if (capabilities & CAP_CDMA)
|
||||
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 != 0x16d5)
|
||||
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, *physdev = NULL;
|
||||
MMModem *modem = NULL;
|
||||
const char *name, *subsys, *devfile, *sysfs_path;
|
||||
guint32 caps;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
physdev = mm_plugin_base_supports_task_get_physdev (task);
|
||||
g_assert (physdev);
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
subsys = g_udev_device_get_subsystem (port);
|
||||
name = g_udev_device_get_name (port);
|
||||
|
||||
caps = mm_plugin_base_supports_task_get_probed_capabilities (task);
|
||||
if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) {
|
||||
g_set_error (error, 0, 0, "Only CDMA modems are currently supported by this plugin.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!existing) {
|
||||
if (caps & CAP_CDMA) {
|
||||
modem = mm_modem_anydata_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, MM_PORT_TYPE_UNKNOWN, NULL, error)) {
|
||||
g_object_unref (modem);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (caps & CAP_CDMA) {
|
||||
modem = existing;
|
||||
if (!mm_modem_grab_port (modem, subsys, name, MM_PORT_TYPE_UNKNOWN, NULL, error))
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return modem;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_plugin_anydata_init (MMPluginAnydata *self)
|
||||
{
|
||||
g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_anydata_class_init (MMPluginAnydataClass *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-anydata.h
Normal file
41
plugins/mm-plugin-anydata.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_ANYDATA_H
|
||||
#define MM_PLUGIN_ANYDATA_H
|
||||
|
||||
#include "mm-plugin-base.h"
|
||||
|
||||
#define MM_TYPE_PLUGIN_ANYDATA (mm_plugin_anydata_get_type ())
|
||||
#define MM_PLUGIN_ANYDATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_ANYDATA, MMPluginAnydata))
|
||||
#define MM_PLUGIN_ANYDATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_ANYDATA, MMPluginAnydataClass))
|
||||
#define MM_IS_PLUGIN_ANYDATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_ANYDATA))
|
||||
#define MM_IS_PLUGIN_ANYDATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_ANYDATA))
|
||||
#define MM_PLUGIN_ANYDATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_ANYDATA, MMPluginAnydataClass))
|
||||
|
||||
typedef struct {
|
||||
MMPluginBase parent;
|
||||
} MMPluginAnydata;
|
||||
|
||||
typedef struct {
|
||||
MMPluginBaseClass parent;
|
||||
} MMPluginAnydataClass;
|
||||
|
||||
GType mm_plugin_anydata_get_type (void);
|
||||
|
||||
G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
|
||||
|
||||
#endif /* MM_PLUGIN_ANYDATA_H */
|
@@ -57,6 +57,7 @@ typedef struct {
|
||||
gboolean valid;
|
||||
gboolean evdo_rev0;
|
||||
gboolean evdo_revA;
|
||||
gboolean reg_try_css;
|
||||
|
||||
MMModemCdmaRegistrationState cdma_1x_reg_state;
|
||||
MMModemCdmaRegistrationState evdo_reg_state;
|
||||
@@ -75,6 +76,7 @@ enum {
|
||||
PROP_0,
|
||||
PROP_EVDO_REV0,
|
||||
PROP_EVDO_REVA,
|
||||
PROP_REG_TRY_CSS,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
@@ -1246,6 +1248,26 @@ reg_state_query_done (MMModemCdma *cdma,
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
static void
|
||||
query_subclass_registration_state (MMGenericCdma *self, MMCallbackInfo *info)
|
||||
{
|
||||
/* Let subclasses figure out roaming and detailed registration state */
|
||||
if (MM_GENERIC_CDMA_GET_CLASS (self)->query_registration_state) {
|
||||
MM_GENERIC_CDMA_GET_CLASS (self)->query_registration_state (self,
|
||||
reg_state_query_done,
|
||||
info);
|
||||
} else {
|
||||
/* Or if the subclass doesn't implement more specific checking,
|
||||
* assume we're registered.
|
||||
*/
|
||||
reg_state_query_done (MM_MODEM_CDMA (self),
|
||||
MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED,
|
||||
MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED,
|
||||
NULL,
|
||||
info);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
reg_state_css_response (MMModemCdma *cdma,
|
||||
guint32 class,
|
||||
@@ -1255,7 +1277,6 @@ reg_state_css_response (MMModemCdma *cdma,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModem *modem = info->modem;
|
||||
|
||||
/* We'll get an error if the SID isn't valid, so detect that and
|
||||
* report unknown registration state.
|
||||
@@ -1273,19 +1294,7 @@ reg_state_css_response (MMModemCdma *cdma,
|
||||
return;
|
||||
}
|
||||
|
||||
/* SID is valid; let subclasses figure out roaming and detailed registration */
|
||||
if (MM_GENERIC_CDMA_GET_CLASS (modem)->query_registration_state) {
|
||||
MM_GENERIC_CDMA_GET_CLASS (modem)->query_registration_state (MM_GENERIC_CDMA (modem),
|
||||
reg_state_query_done,
|
||||
info);
|
||||
} else {
|
||||
/* Otherwise, success; we're registered */
|
||||
reg_state_query_done (cdma,
|
||||
MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED,
|
||||
MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED,
|
||||
NULL,
|
||||
info);
|
||||
}
|
||||
query_subclass_registration_state (MM_GENERIC_CDMA (info->modem), info);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1316,12 +1325,28 @@ get_analog_digital_done (MMSerialPort *port,
|
||||
}
|
||||
|
||||
if (int_cad == 1) { /* 1 == CDMA service */
|
||||
MMGenericCdmaPrivate *priv = MM_GENERIC_CDMA_GET_PRIVATE (info->modem);
|
||||
|
||||
/* Now that we have some sort of service, check if the the device is
|
||||
* registered on the network.
|
||||
*/
|
||||
get_serving_system (MM_MODEM_CDMA (info->modem),
|
||||
reg_state_css_response,
|
||||
info);
|
||||
|
||||
/* Some devices key the AT+CSS? response off the 1X state, but if the
|
||||
* device has EVDO service but no 1X service, then reading AT+CSS? will
|
||||
* error out too early. Let subclasses that know that their AT+CSS?
|
||||
* response is wrong in this case handle more specific registration
|
||||
* themselves; if they do, they'll set priv->reg_try_css to FALSE.
|
||||
*/
|
||||
if (priv->reg_try_css) {
|
||||
get_serving_system (MM_MODEM_CDMA (info->modem),
|
||||
reg_state_css_response,
|
||||
info);
|
||||
} else {
|
||||
/* Subclass knows that AT+CSS? will respond incorrectly to EVDO
|
||||
* state, so skip AT+CSS? query.
|
||||
*/
|
||||
query_subclass_registration_state (MM_GENERIC_CDMA (info->modem), info);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
/* No service */
|
||||
@@ -1703,6 +1728,9 @@ set_property (GObject *object, guint prop_id,
|
||||
case PROP_EVDO_REVA:
|
||||
priv->evdo_revA = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_REG_TRY_CSS:
|
||||
priv->reg_try_css = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -1731,6 +1759,9 @@ get_property (GObject *object, guint prop_id,
|
||||
case PROP_EVDO_REVA:
|
||||
g_value_set_boolean (value, priv->evdo_revA);
|
||||
break;
|
||||
case PROP_REG_TRY_CSS:
|
||||
g_value_set_boolean (value, priv->reg_try_css);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -1788,5 +1819,13 @@ mm_generic_cdma_class_init (MMGenericCdmaClass *klass)
|
||||
"Supports EVDO revA",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_REG_TRY_CSS,
|
||||
g_param_spec_boolean (MM_GENERIC_CDMA_REGISTRATION_TRY_CSS,
|
||||
"RegistrationTryCss",
|
||||
"Use Serving System response when checking modem"
|
||||
" registration state.",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,10 @@
|
||||
#define MM_IS_GENERIC_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_GENERIC_CDMA))
|
||||
#define MM_GENERIC_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_GENERIC_CDMA, MMGenericCdmaClass))
|
||||
|
||||
#define MM_GENERIC_CDMA_EVDO_REV0 "evdo-rev0"
|
||||
#define MM_GENERIC_CDMA_EVDO_REVA "evdo-revA"
|
||||
#define MM_GENERIC_CDMA_EVDO_REV0 "evdo-rev0"
|
||||
#define MM_GENERIC_CDMA_EVDO_REVA "evdo-revA"
|
||||
|
||||
#define MM_GENERIC_CDMA_REGISTRATION_TRY_CSS "registration-try-css"
|
||||
|
||||
typedef struct {
|
||||
MMModemBase parent;
|
||||
|
Reference in New Issue
Block a user