novatel: plugin fully ported

This commit is contained in:
Aleksander Morgado
2012-08-20 16:24:08 +02:00
parent 678972b63a
commit d26071325c
6 changed files with 0 additions and 1001 deletions

View File

@@ -1,310 +0,0 @@
/* -*- 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>
#include "mm-modem-novatel-cdma.h"
#include "mm-modem-helpers.h"
#include "libqcdm/src/commands.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
static void modem_cdma_init (MMModemCdma *cdma_class);
G_DEFINE_TYPE_EXTENDED (MMModemNovatelCdma, mm_modem_novatel_cdma, MM_TYPE_GENERIC_CDMA, 0,
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_CDMA, modem_cdma_init))
MMModem *
mm_modem_novatel_cdma_new (const char *device,
const char *driver,
const char *plugin,
gboolean evdo_rev0,
gboolean evdo_revA,
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_NOVATEL_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,
NULL));
}
/*****************************************************************************/
static void
parent_csq_done (MMModem *modem,
guint32 result,
GError *error,
gpointer user_data)
{
MMCallbackInfo *info = user_data;
if (error)
info->error = g_error_copy (error);
else
mm_callback_info_set_result (info, GUINT_TO_POINTER (result), NULL);
mm_callback_info_schedule (info);
}
static int
get_one_qual (const char *reply, const char *tag)
{
int qual = -1;
const char *p;
long int dbm;
gboolean success = FALSE;
p = strstr (reply, tag);
if (!p)
return -1;
/* Skip the tag */
p += strlen (tag);
/* Skip spaces */
while (isspace (*p))
p++;
errno = 0;
dbm = strtol (p, NULL, 10);
if (errno == 0) {
if (*p == '-') {
/* Some cards appear to use RX0/RX1 and output RSSI in negative dBm */
if (dbm < 0)
success = TRUE;
} else if (isdigit (*p) && (dbm > 0) && (dbm < 115)) {
/* S720 appears to use "1x RSSI" and print RSSI in dBm without '-' */
dbm *= -1;
success = TRUE;
}
}
if (success) {
dbm = CLAMP (dbm, -113, -51);
qual = 100 - ((dbm + 51) * 100 / (-113 + 51));
}
return qual;
}
static void
get_rssi_done (MMAtSerialPort *port,
GString *response,
GError *error,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
MMModemCdma *parent_iface;
int qual;
/* If the modem has already been removed, return without
* scheduling callback */
if (mm_callback_info_check_modem_removed (info))
return;
if (error) {
/* Fallback to parent's method */
parent_iface = g_type_interface_peek_parent (MM_MODEM_CDMA_GET_INTERFACE (info->modem));
parent_iface->get_signal_quality (MM_MODEM_CDMA (info->modem), parent_csq_done, info);
return;
}
/* Parse the signal quality */
qual = get_one_qual (response->str, "RX0=");
if (qual < 0)
qual = get_one_qual (response->str, "1x RSSI=");
if (qual < 0)
qual = get_one_qual (response->str, "RX1=");
if (qual >= 0) {
mm_callback_info_set_result (info, GUINT_TO_POINTER ((guint32) qual), NULL);
mm_generic_cdma_update_cdma1x_quality (MM_GENERIC_CDMA (info->modem), (guint32) qual);
} else {
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Could not parse signal quality results");
}
mm_callback_info_schedule (info);
}
static void
get_signal_quality (MMModemCdma *modem,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
MMAtSerialPort *port;
MMModemCdma *parent_iface;
port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), NULL);
if (!port) {
/* Let the superclass handle it */
parent_iface = g_type_interface_peek_parent (MM_MODEM_CDMA_GET_INTERFACE (modem));
parent_iface->get_signal_quality (MM_MODEM_CDMA (modem), callback, user_data);
return;
}
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
/* Many Novatel CDMA cards don't report CSQ in standard 0 - 31 and the CSQ
* reply doesn't appear to be in positive dBm either; instead try the custom
* Novatel command for it.
*/
mm_at_serial_port_queue_command (port, "$NWRSSI", 3, get_rssi_done, info);
}
/*****************************************************************************/
static void
parse_modem_snapshot (MMCallbackInfo *info, QcdmResult *result)
{
MMModemCdmaRegistrationState evdo_state, cdma1x_state, new_state;
guint8 eri = 0;
g_return_if_fail (info != NULL);
g_return_if_fail (result != NULL);
evdo_state = mm_generic_cdma_query_reg_state_get_callback_evdo_state (info);
cdma1x_state = mm_generic_cdma_query_reg_state_get_callback_1x_state (info);
/* Roaming? */
if (qcdm_result_get_u8 (result, QCDM_CMD_NW_SUBSYS_MODEM_SNAPSHOT_CDMA_ITEM_ERI, &eri)) {
char *str;
gboolean roaming = FALSE;
str = g_strdup_printf ("%u", eri);
if (mm_cdma_parse_eri (str, &roaming, NULL, NULL)) {
new_state = roaming ? MM_MODEM_CDMA_REGISTRATION_STATE_HOME : MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING;
if (cdma1x_state != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN)
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, new_state);
if (evdo_state != MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN)
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, new_state);
}
g_free (str);
}
}
static void
reg_nwsnap_6500_cb (MMQcdmSerialPort *port,
GByteArray *response,
GError *error,
gpointer user_data)
{
MMCallbackInfo *info = user_data;
QcdmResult *result;
if (!error) {
result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const char *) response->data, response->len, NULL);
if (result) {
parse_modem_snapshot (info, result);
qcdm_result_unref (result);
}
}
mm_callback_info_schedule (info);
}
static void
reg_nwsnap_6800_cb (MMQcdmSerialPort *port,
GByteArray *response,
GError *error,
gpointer user_data)
{
MMCallbackInfo *info = user_data;
QcdmResult *result;
GByteArray *nwsnap;
if (error)
goto done;
/* Parse the response */
result = qcdm_cmd_nw_subsys_modem_snapshot_cdma_result ((const char *) response->data, response->len, NULL);
if (!result) {
/* Try for MSM6500 */
nwsnap = g_byte_array_sized_new (25);
nwsnap->len = qcdm_cmd_nw_subsys_modem_snapshot_cdma_new ((char *) nwsnap->data, 25, QCDM_NW_CHIPSET_6500);
g_assert (nwsnap->len);
mm_qcdm_serial_port_queue_command (port, nwsnap, 3, reg_nwsnap_6500_cb, info);
return;
}
parse_modem_snapshot (info, result);
qcdm_result_unref (result);
done:
mm_callback_info_schedule (info);
}
static void
query_registration_state (MMGenericCdma *cdma,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
MMQcdmSerialPort *port;
GByteArray *nwsnap;
info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, cur_cdma_state, cur_evdo_state, callback, user_data);
port = mm_generic_cdma_get_best_qcdm_port (cdma, &info->error);
if (!port) {
mm_callback_info_schedule (info);
return;
}
/* Try MSM6800 first since newer cards use that */
nwsnap = g_byte_array_sized_new (25);
nwsnap->len = qcdm_cmd_nw_subsys_modem_snapshot_cdma_new ((char *) nwsnap->data, 25, QCDM_NW_CHIPSET_6800);
g_assert (nwsnap->len);
mm_qcdm_serial_port_queue_command (port, nwsnap, 3, reg_nwsnap_6800_cb, info);
}
/*****************************************************************************/
static void
modem_cdma_init (MMModemCdma *cdma_class)
{
cdma_class->get_signal_quality = get_signal_quality;
}
static void
mm_modem_novatel_cdma_init (MMModemNovatelCdma *self)
{
}
static void
mm_modem_novatel_cdma_class_init (MMModemNovatelCdmaClass *klass)
{
MMGenericCdmaClass *generic_class = MM_GENERIC_CDMA_CLASS (klass);
mm_modem_novatel_cdma_parent_class = g_type_class_peek_parent (klass);
generic_class->query_registration_state = query_registration_state;
}

View File

@@ -1,47 +0,0 @@
/* -*- 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_NOVATEL_CDMA_H
#define MM_MODEM_NOVATEL_CDMA_H
#include "mm-generic-cdma.h"
#define MM_TYPE_MODEM_NOVATEL_CDMA (mm_modem_novatel_cdma_get_type ())
#define MM_MODEM_NOVATEL_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_NOVATEL_CDMA, MMModemNovatelCdma))
#define MM_MODEM_NOVATEL_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_NOVATEL_CDMA, MMModemNovatelCdmaClass))
#define MM_IS_MODEM_NOVATEL_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_NOVATEL_CDMA))
#define MM_IS_MODEM_NOVATEL_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_NOVATEL_CDMA))
#define MM_MODEM_NOVATEL_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_NOVATEL_CDMA, MMModemNovatelCdmaClass))
typedef struct {
MMGenericCdma parent;
} MMModemNovatelCdma;
typedef struct {
MMGenericCdmaClass parent;
} MMModemNovatelCdmaClass;
GType mm_modem_novatel_cdma_get_type (void);
MMModem *mm_modem_novatel_cdma_new (const char *device,
const char *driver,
const char *plugin,
gboolean evdo_rev0,
gboolean evdo_revA,
guint32 vendor,
guint32 product);
#endif /* MM_MODEM_NOVATEL_CDMA_H */

View File

@@ -1,366 +0,0 @@
/* -*- 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 "mm-modem-novatel-gsm.h"
#include "mm-errors.h"
#include "mm-callback-info.h"
#include "mm-modem-helpers.h"
G_DEFINE_TYPE (MMModemNovatelGsm, mm_modem_novatel_gsm, MM_TYPE_GENERIC_GSM)
#define MM_MODEM_NOVATEL_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_NOVATEL_GSM, MMModemNovatelGsmPrivate))
typedef struct {
gboolean dmat_sent;
} MMModemNovatelGsmPrivate;
MMModem *
mm_modem_novatel_gsm_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_NOVATEL_GSM,
MM_MODEM_MASTER_DEVICE, device,
MM_MODEM_DRIVER, driver,
MM_MODEM_PLUGIN, plugin,
MM_MODEM_HW_VID, vendor,
MM_MODEM_HW_PID, product,
NULL));
}
/*****************************************************************************/
/* Modem class override functions */
/*****************************************************************************/
static void
dmat_callback2 (MMAtSerialPort *port,
GString *response,
GError *error,
gpointer user_data)
{
mm_serial_port_close (MM_SERIAL_PORT (port));
}
static void
dmat_callback (MMAtSerialPort *port,
GString *response,
GError *error,
gpointer user_data)
{
if (error) {
/* Try it again */
if (mm_serial_port_open (MM_SERIAL_PORT (port), NULL))
mm_at_serial_port_queue_command (port, "$NWDMAT=1", 2, dmat_callback2, NULL);
}
mm_serial_port_close (MM_SERIAL_PORT (port));
}
static void
port_grabbed (MMGenericGsm *gsm,
MMPort *port,
MMAtPortFlags pflags,
gpointer user_data)
{
MMModemNovatelGsm *self = MM_MODEM_NOVATEL_GSM (gsm);
MMModemNovatelGsmPrivate *priv = MM_MODEM_NOVATEL_GSM_GET_PRIVATE (self);
if (MM_IS_AT_SERIAL_PORT (port) && !priv->dmat_sent) {
/* Flip secondary ports to AT mode */
if (mm_serial_port_open (MM_SERIAL_PORT (port), NULL)) {
mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port), "$NWDMAT=1", 2, dmat_callback, NULL);
priv->dmat_sent = TRUE;
}
}
}
/*****************************************************************************/
static void
set_allowed_mode_done (MMAtSerialPort *port,
GString *response,
GError *error,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
/* If the modem has already been removed, return without
* scheduling callback */
if (mm_callback_info_check_modem_removed (info))
return;
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;
MMAtSerialPort *port;
char *command;
int nw_mode = 0; /* 3G preferred */
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:
nw_mode = 1;
break;
case MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY:
nw_mode = 2;
break;
case MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED:
case MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED:
case MM_MODEM_GSM_ALLOWED_MODE_ANY:
default:
break;
}
command = g_strdup_printf ("$NWRAT=%d,2", nw_mode);
mm_at_serial_port_queue_command (port, command, 3, set_allowed_mode_done, info);
g_free (command);
}
static gboolean
parse_nwrat_response (GString *response,
MMModemGsmAllowedMode *out_mode,
GError **error)
{
GRegex *r;
GMatchInfo *match_info;
char *str;
gint mode = -1;
gboolean success = FALSE;
g_return_val_if_fail (response != NULL, FALSE);
g_return_val_if_fail (out_mode != NULL, FALSE);
r = g_regex_new ("\\$NWRAT:\\s*(\\d),(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
if (!r) {
g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Internal error parsing mode/tech response");
return FALSE;
}
if (!g_regex_match_full (r, response->str, response->len, 0, 0, &match_info, NULL)) {
g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Failed to parse mode/tech response");
goto out;
}
str = g_match_info_fetch (match_info, 1);
mode = atoi (str);
g_free (str);
if (mode < 0 || mode > 2) {
g_set_error_literal (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"Failed to parse mode/tech response");
goto out;
}
if (out_mode) {
if (mode == 0)
*out_mode = MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED;
else if (mode == 1)
*out_mode = MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY;
else if (mode == 2)
*out_mode = MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY;
else
*out_mode = MM_MODEM_GSM_ALLOWED_MODE_ANY;
}
success = TRUE;
out:
g_match_info_free (match_info);
g_regex_unref (r);
return success;
}
static void
get_allowed_mode_done (MMAtSerialPort *port,
GString *response,
GError *error,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
MMModemGsmAllowedMode mode = MM_MODEM_GSM_ALLOWED_MODE_ANY;
/* If the modem has already been removed, return without
* scheduling callback */
if (mm_callback_info_check_modem_removed (info))
return;
if (error)
info->error = g_error_copy (error);
else {
parse_nwrat_response (response, &mode, &info->error);
mm_callback_info_set_result (info, GUINT_TO_POINTER (mode), NULL);
}
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, "$NWRAT?", 3, get_allowed_mode_done, info);
}
static void
get_act_request_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;
/* If the modem has already been removed, return without
* scheduling callback */
if (mm_callback_info_check_modem_removed (info))
return;
if (error)
info->error = g_error_copy (error);
else {
p = mm_strip_tag (response->str, "$CNTI:");
p = strchr (p, ',');
if (p)
act = mm_gsm_string_to_access_tech (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, "$CNTI=0", 3, get_act_request_done, info);
}
/*****************************************************************************/
static void
mm_modem_novatel_gsm_init (MMModemNovatelGsm *self)
{
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
/* Do nothing... see set_property() in parent, which also does nothing */
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
switch (prop_id) {
case MM_GENERIC_GSM_PROP_SMS_INDICATION_ENABLE_CMD:
/* Many Qualcomm chipsets don't support mode=2 */
g_value_set_string (value, "+CNMI=1,1,2,1,0");
break;
case MM_GENERIC_GSM_PROP_SMS_STORAGE_LOCATION_CMD:
g_value_set_string (value, "+CPMS=\"SM\",\"SM\",\"SM\"");
break;
default:
break;
}
}
static void
mm_modem_novatel_gsm_class_init (MMModemNovatelGsmClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass);
mm_modem_novatel_gsm_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (object_class, sizeof (MMModemNovatelGsmPrivate));
object_class->get_property = get_property;
object_class->set_property = set_property;
gsm_class->port_grabbed = port_grabbed;
gsm_class->set_allowed_mode = set_allowed_mode;
gsm_class->get_allowed_mode = get_allowed_mode;
gsm_class->get_access_technology = get_access_technology;
g_object_class_override_property (object_class,
MM_GENERIC_GSM_PROP_SMS_INDICATION_ENABLE_CMD,
MM_GENERIC_GSM_SMS_INDICATION_ENABLE_CMD);
g_object_class_override_property (object_class,
MM_GENERIC_GSM_PROP_SMS_STORAGE_LOCATION_CMD,
MM_GENERIC_GSM_SMS_STORAGE_LOCATION_CMD);
}

View File

@@ -1,45 +0,0 @@
/* -*- 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_NOVATEL_GSM_H
#define MM_MODEM_NOVATEL_GSM_H
#include "mm-generic-gsm.h"
#define MM_TYPE_MODEM_NOVATEL_GSM (mm_modem_novatel_gsm_get_type ())
#define MM_MODEM_NOVATEL_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_NOVATEL_GSM, MMModemNovatelGsm))
#define MM_MODEM_NOVATEL_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_NOVATEL_GSM, MMModemNovatelGsmClass))
#define MM_IS_MODEM_NOVATEL_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_NOVATEL_GSM))
#define MM_IS_MODEM_NOVATEL_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_NOVATEL_GSM))
#define MM_MODEM_NOVATEL_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_NOVATEL_GSM, MMModemNovatelGsmClass))
typedef struct {
MMGenericGsm parent;
} MMModemNovatelGsm;
typedef struct {
MMGenericGsmClass parent;
} MMModemNovatelGsmClass;
GType mm_modem_novatel_gsm_get_type (void);
MMModem *mm_modem_novatel_gsm_new (const char *device,
const char *driver,
const char *plugin_name,
guint32 vendor,
guint32 product);
#endif /* MM_MODEM_NOVATEL_GSM_H */

View File

@@ -1,191 +0,0 @@
/* -*- 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-novatel.h"
#include "mm-modem-novatel-gsm.h"
#include "mm-modem-novatel-cdma.h"
G_DEFINE_TYPE (MMPluginNovatel, mm_plugin_novatel, 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_NOVATEL,
MM_PLUGIN_BASE_NAME, "Novatel",
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;
const char *subsys, *name, *driver;
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;
driver = mm_plugin_base_supports_task_get_driver (task);
if (!driver || (strcmp (driver, "option1") && strcmp (driver, "option")))
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
if (vendor != 0x1410 && vendor != 0x413c)
return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
/* Check if a previous probing was already launched in this port */
if (mm_plugin_base_supports_task_propagate_cached (task)) {
guint32 level;
/* A previous probing was already done, use its results */
level = get_level_for_capabilities (mm_plugin_base_supports_task_get_probed_capabilities (task));
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, 100000, 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;
MMPortType ptype;
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);
ptype = mm_plugin_base_probed_capabilities_to_port_type (caps);
if (!existing) {
if (caps & MM_PLUGIN_BASE_PORT_CAP_GSM) {
modem = mm_modem_novatel_gsm_new (sysfs_path,
mm_plugin_base_supports_task_get_driver (task),
mm_plugin_get_name (MM_PLUGIN (base)),
vendor,
product);
} else if (caps & CAP_CDMA) {
modem = mm_modem_novatel_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),
vendor,
product);
}
if (modem) {
if (!mm_modem_grab_port (modem, subsys, name, ptype, MM_AT_PORT_FLAG_NONE, 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, ptype, MM_AT_PORT_FLAG_NONE, NULL, error))
return NULL;
}
return modem;
}
/*****************************************************************************/
static void
mm_plugin_novatel_init (MMPluginNovatel *self)
{
g_signal_connect (self, "probe-result", G_CALLBACK (probe_result), NULL);
}
static void
mm_plugin_novatel_class_init (MMPluginNovatelClass *klass)
{
MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass);
pb_class->supports_port = supports_port;
pb_class->grab_port = grab_port;
}

View File

@@ -1,42 +0,0 @@
/* -*- 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_NOVATEL_H
#define MM_PLUGIN_NOVATEL_H
#include "mm-plugin-base.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 {
MMPluginBase parent;
} MMPluginNovatel;
typedef struct {
MMPluginBaseClass parent;
} MMPluginNovatelClass;
GType mm_plugin_novatel_get_type (void);
G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
#endif /* MM_PLUGIN_NOVATEL_H */