Allow plugins to perform asynchronous port detection, and to defer port detection until later. This moves the prober bits into MMPluginBase so that all plugins can take adavantage of it only when needed; the probing is not done at udev time. Furthermore, plugins like Novatel can flip the secondary ports over the AT mode through deferred detection, by deferring the secondary ports until the main port has been detected and AT$NWDMAT has been sent. This commit also finishes the port of the rest of the plugins (except mbm) over to the new port detection methods and plugin API.
642 lines
21 KiB
C
642 lines
21 KiB
C
/* -*- 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>
|
|
|
|
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
|
|
#include <gudev/gudev.h>
|
|
|
|
#include "mm-modem-huawei.h"
|
|
#include "mm-modem-gsm-network.h"
|
|
#include "mm-errors.h"
|
|
#include "mm-callback-info.h"
|
|
#include "mm-serial-port.h"
|
|
#include "mm-serial-parsers.h"
|
|
|
|
static gpointer mm_modem_huawei_parent_class = NULL;
|
|
|
|
#define MM_MODEM_HUAWEI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_HUAWEI, MMModemHuaweiPrivate))
|
|
|
|
typedef struct {
|
|
/* Cached state */
|
|
guint signal_quality;
|
|
MMModemGsmNetworkMode mode;
|
|
MMModemGsmNetworkBand band;
|
|
} MMModemHuaweiPrivate;
|
|
|
|
MMModem *
|
|
mm_modem_huawei_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_HUAWEI,
|
|
MM_MODEM_MASTER_DEVICE, device,
|
|
MM_MODEM_DRIVER, driver,
|
|
MM_MODEM_PLUGIN, plugin,
|
|
NULL));
|
|
}
|
|
|
|
static gboolean
|
|
parse_syscfg (MMModemHuawei *self,
|
|
const char *reply,
|
|
int *mode_a,
|
|
int *mode_b,
|
|
guint32 *band,
|
|
int *unknown1,
|
|
int *unknown2)
|
|
{
|
|
if (reply == NULL || strncmp (reply, "^SYSCFG:", 8))
|
|
return FALSE;
|
|
|
|
if (sscanf (reply + 8, "%d,%d,%x,%d,%d", mode_a, mode_b, band, unknown1, unknown2)) {
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (self);
|
|
|
|
/* Network mode */
|
|
if (*mode_a == 2 && *mode_b == 1)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_2G_PREFERRED;
|
|
else if (*mode_a == 2 && *mode_b == 2)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_3G_PREFERRED;
|
|
else if (*mode_a == 13 && *mode_b == 1)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_2G_ONLY;
|
|
else if (*mode_a == 14 && *mode_b == 2)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_3G_ONLY;
|
|
|
|
/* Band */
|
|
if (*band == 0x3FFFFFFF)
|
|
priv->band = MM_MODEM_GSM_NETWORK_BAND_ANY;
|
|
else if (*band == 0x400380)
|
|
priv->band = MM_MODEM_GSM_NETWORK_BAND_DCS;
|
|
else if (*band == 0x200000)
|
|
priv->band = MM_MODEM_GSM_NETWORK_BAND_PCS;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
static void
|
|
set_network_mode_done (MMSerialPort *port,
|
|
GString *response,
|
|
GError *error,
|
|
gpointer user_data)
|
|
{
|
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
|
MMModemHuawei *self = MM_MODEM_HUAWEI (info->modem);
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (self);
|
|
|
|
if (error)
|
|
info->error = g_error_copy (error);
|
|
else
|
|
/* Success, cache the value */
|
|
priv->mode = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "mode"));
|
|
|
|
mm_callback_info_schedule (info);
|
|
}
|
|
|
|
static void
|
|
set_network_mode_get_done (MMSerialPort *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);
|
|
} else {
|
|
int a, b, u1, u2;
|
|
guint32 band;
|
|
|
|
if (parse_syscfg (MM_MODEM_HUAWEI (info->modem), response->str, &a, &b, &band, &u1, &u2)) {
|
|
char *command;
|
|
|
|
switch (GPOINTER_TO_UINT (mm_callback_info_get_data (info, "mode"))) {
|
|
case MM_MODEM_GSM_NETWORK_MODE_GPRS:
|
|
case MM_MODEM_GSM_NETWORK_MODE_EDGE:
|
|
case MM_MODEM_GSM_NETWORK_MODE_2G_ONLY:
|
|
a = 13;
|
|
b = 1;
|
|
break;
|
|
case MM_MODEM_GSM_NETWORK_MODE_UMTS:
|
|
case MM_MODEM_GSM_NETWORK_MODE_HSDPA:
|
|
case MM_MODEM_GSM_NETWORK_MODE_HSUPA:
|
|
case MM_MODEM_GSM_NETWORK_MODE_HSPA:
|
|
case MM_MODEM_GSM_NETWORK_MODE_3G_ONLY:
|
|
a = 14;
|
|
b = 2;
|
|
break;
|
|
case MM_MODEM_GSM_NETWORK_MODE_2G_PREFERRED:
|
|
a = 2;
|
|
b = 1;
|
|
break;
|
|
case MM_MODEM_GSM_NETWORK_MODE_3G_PREFERRED:
|
|
a = 2;
|
|
b = 2;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
command = g_strdup_printf ("AT^SYSCFG=%d,%d,%X,%d,%d", a, b, band, u1, u2);
|
|
mm_serial_port_queue_command (port, command, 3, set_network_mode_done, info);
|
|
g_free (command);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
set_network_mode (MMModemGsmNetwork *modem,
|
|
MMModemGsmNetworkMode mode,
|
|
MMModemFn callback,
|
|
gpointer user_data)
|
|
{
|
|
MMCallbackInfo *info;
|
|
MMSerialPort *primary;
|
|
|
|
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
|
|
|
|
switch (mode) {
|
|
case MM_MODEM_GSM_NETWORK_MODE_ANY:
|
|
/* Do nothing */
|
|
break;
|
|
case MM_MODEM_GSM_NETWORK_MODE_GPRS:
|
|
case MM_MODEM_GSM_NETWORK_MODE_EDGE:
|
|
case MM_MODEM_GSM_NETWORK_MODE_UMTS:
|
|
case MM_MODEM_GSM_NETWORK_MODE_HSDPA:
|
|
case MM_MODEM_GSM_NETWORK_MODE_HSUPA:
|
|
case MM_MODEM_GSM_NETWORK_MODE_HSPA:
|
|
case MM_MODEM_GSM_NETWORK_MODE_2G_PREFERRED:
|
|
case MM_MODEM_GSM_NETWORK_MODE_3G_PREFERRED:
|
|
case MM_MODEM_GSM_NETWORK_MODE_2G_ONLY:
|
|
case MM_MODEM_GSM_NETWORK_MODE_3G_ONLY:
|
|
/* Allowed values */
|
|
mm_callback_info_set_data (info, "mode", GUINT_TO_POINTER (mode), NULL);
|
|
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
g_assert (primary);
|
|
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, set_network_mode_get_done, info);
|
|
return;
|
|
default:
|
|
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Invalid mode.");
|
|
break;
|
|
}
|
|
|
|
mm_callback_info_schedule (info);
|
|
}
|
|
|
|
static void
|
|
get_network_mode_done (MMSerialPort *port,
|
|
GString *response,
|
|
GError *error,
|
|
gpointer user_data)
|
|
{
|
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
|
MMModemHuawei *self = MM_MODEM_HUAWEI (info->modem);
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (self);
|
|
int mode_a, mode_b, u1, u2;
|
|
guint32 band;
|
|
|
|
if (error)
|
|
info->error = g_error_copy (error);
|
|
else if (parse_syscfg (self, response->str, &mode_a, &mode_b, &band, &u1, &u2))
|
|
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->mode), NULL);
|
|
|
|
mm_callback_info_schedule (info);
|
|
}
|
|
|
|
static void
|
|
get_network_mode (MMModemGsmNetwork *modem,
|
|
MMModemUIntFn callback,
|
|
gpointer user_data)
|
|
{
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (modem);
|
|
|
|
if (priv->mode != MM_MODEM_GSM_NETWORK_MODE_ANY) {
|
|
/* have cached mode (from an unsolicited message). Use that */
|
|
MMCallbackInfo *info;
|
|
|
|
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
|
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->mode), NULL);
|
|
mm_callback_info_schedule (info);
|
|
} else {
|
|
/* Get it from modem */
|
|
MMCallbackInfo *info;
|
|
MMSerialPort *primary;
|
|
|
|
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
|
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
g_assert (primary);
|
|
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, get_network_mode_done, info);
|
|
}
|
|
}
|
|
|
|
static void
|
|
set_band_done (MMSerialPort *port,
|
|
GString *response,
|
|
GError *error,
|
|
gpointer user_data)
|
|
{
|
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
|
MMModemHuawei *self = MM_MODEM_HUAWEI (info->modem);
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (self);
|
|
|
|
if (error)
|
|
info->error = g_error_copy (error);
|
|
else
|
|
/* Success, cache the value */
|
|
priv->band = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "band"));
|
|
|
|
mm_callback_info_schedule (info);
|
|
}
|
|
|
|
static void
|
|
set_band_get_done (MMSerialPort *port,
|
|
GString *response,
|
|
GError *error,
|
|
gpointer user_data)
|
|
{
|
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
|
MMModemHuawei *self = MM_MODEM_HUAWEI (info->modem);
|
|
|
|
if (error) {
|
|
info->error = g_error_copy (error);
|
|
mm_callback_info_schedule (info);
|
|
} else {
|
|
int a, b, u1, u2;
|
|
guint32 band;
|
|
|
|
if (parse_syscfg (self, response->str, &a, &b, &band, &u1, &u2)) {
|
|
char *command;
|
|
|
|
switch (GPOINTER_TO_UINT (mm_callback_info_get_data (info, "band"))) {
|
|
case MM_MODEM_GSM_NETWORK_BAND_ANY:
|
|
band = 0x3FFFFFFF;
|
|
break;
|
|
case MM_MODEM_GSM_NETWORK_BAND_EGSM:
|
|
case MM_MODEM_GSM_NETWORK_BAND_DCS:
|
|
case MM_MODEM_GSM_NETWORK_BAND_U2100:
|
|
band = 0x400380;
|
|
break;
|
|
case MM_MODEM_GSM_NETWORK_BAND_PCS:
|
|
band = 0x200000;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
command = g_strdup_printf ("AT^SYSCFG=%d,%d,%X,%d,%d", a, b, band, u1, u2);
|
|
mm_serial_port_queue_command (port, command, 3, set_band_done, info);
|
|
g_free (command);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
set_band (MMModemGsmNetwork *modem,
|
|
MMModemGsmNetworkBand band,
|
|
MMModemFn callback,
|
|
gpointer user_data)
|
|
{
|
|
MMCallbackInfo *info;
|
|
MMSerialPort *primary;
|
|
|
|
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
|
|
|
|
switch (band) {
|
|
case MM_MODEM_GSM_NETWORK_BAND_ANY:
|
|
case MM_MODEM_GSM_NETWORK_BAND_EGSM:
|
|
case MM_MODEM_GSM_NETWORK_BAND_DCS:
|
|
case MM_MODEM_GSM_NETWORK_BAND_U2100:
|
|
case MM_MODEM_GSM_NETWORK_BAND_PCS:
|
|
mm_callback_info_set_data (info, "band", GUINT_TO_POINTER (band), NULL);
|
|
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
g_assert (primary);
|
|
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, set_band_get_done, info);
|
|
return;
|
|
default:
|
|
info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "Invalid band.");
|
|
break;
|
|
}
|
|
|
|
mm_callback_info_schedule (info);
|
|
}
|
|
|
|
static void
|
|
get_band_done (MMSerialPort *port,
|
|
GString *response,
|
|
GError *error,
|
|
gpointer user_data)
|
|
{
|
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
|
MMModemHuawei *self = MM_MODEM_HUAWEI (info->modem);
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (self);
|
|
int mode_a, mode_b, u1, u2;
|
|
guint32 band;
|
|
|
|
if (error)
|
|
info->error = g_error_copy (error);
|
|
else if (parse_syscfg (self, response->str, &mode_a, &mode_b, &band, &u1, &u2))
|
|
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->band), NULL);
|
|
|
|
mm_callback_info_schedule (info);
|
|
}
|
|
|
|
static void
|
|
get_band (MMModemGsmNetwork *modem,
|
|
MMModemUIntFn callback,
|
|
gpointer user_data)
|
|
{
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (modem);
|
|
MMSerialPort *primary;
|
|
|
|
if (priv->band != MM_MODEM_GSM_NETWORK_BAND_ANY) {
|
|
/* have cached mode (from an unsolicited message). Use that */
|
|
MMCallbackInfo *info;
|
|
|
|
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
|
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->band), NULL);
|
|
mm_callback_info_schedule (info);
|
|
} else {
|
|
/* Get it from modem */
|
|
MMCallbackInfo *info;
|
|
|
|
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
|
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
g_assert (primary);
|
|
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, get_band_done, info);
|
|
}
|
|
}
|
|
|
|
static void
|
|
get_signal_quality (MMModemGsmNetwork *modem,
|
|
MMModemUIntFn callback,
|
|
gpointer user_data)
|
|
{
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (modem);
|
|
|
|
if (priv->signal_quality) {
|
|
/* have cached signal quality (from an unsolicited message). Use that */
|
|
MMCallbackInfo *info;
|
|
|
|
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
|
mm_callback_info_set_result (info, GUINT_TO_POINTER (priv->signal_quality), NULL);
|
|
mm_callback_info_schedule (info);
|
|
} else {
|
|
/* Use the generic implementation */
|
|
MMModemGsmNetwork *parent_gsm_network_iface;
|
|
|
|
parent_gsm_network_iface = g_type_interface_peek_parent (MM_MODEM_GSM_NETWORK_GET_INTERFACE (modem));
|
|
parent_gsm_network_iface->get_signal_quality (modem, callback, user_data);
|
|
}
|
|
}
|
|
|
|
/* Unsolicited message handlers */
|
|
|
|
static void
|
|
handle_signal_quality_change (MMSerialPort *port,
|
|
GMatchInfo *match_info,
|
|
gpointer user_data)
|
|
{
|
|
MMModemHuawei *self = MM_MODEM_HUAWEI (user_data);
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (self);
|
|
char *str;
|
|
int quality;
|
|
|
|
str = g_match_info_fetch (match_info, 1);
|
|
quality = atoi (str);
|
|
g_free (str);
|
|
|
|
if (quality == 99)
|
|
/* 99 means unknown */
|
|
quality = 0;
|
|
else
|
|
/* Normalize the quality */
|
|
quality = quality * 100 / 31;
|
|
|
|
g_debug ("Signal quality: %d", quality);
|
|
priv->signal_quality = (guint32) quality;
|
|
mm_modem_gsm_network_signal_quality (MM_MODEM_GSM_NETWORK (self), (guint32) quality);
|
|
}
|
|
|
|
static void
|
|
handle_mode_change (MMSerialPort *port,
|
|
GMatchInfo *match_info,
|
|
gpointer user_data)
|
|
{
|
|
MMModemHuawei *self = MM_MODEM_HUAWEI (user_data);
|
|
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (self);
|
|
char *str;
|
|
int a;
|
|
int b;
|
|
|
|
str = g_match_info_fetch (match_info, 1);
|
|
a = atoi (str);
|
|
g_free (str);
|
|
|
|
str = g_match_info_fetch (match_info, 2);
|
|
b = atoi (str);
|
|
g_free (str);
|
|
|
|
if (a == 3 && b == 2)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_GPRS;
|
|
else if (a == 3 && b == 3)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_EDGE;
|
|
else if (a == 5 && b == 4)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_UMTS;
|
|
else if (a == 5 && b == 5)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_HSDPA;
|
|
else if (a == 5 && b == 6)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_HSUPA;
|
|
else if (a == 5 && b == 7)
|
|
priv->mode = MM_MODEM_GSM_NETWORK_MODE_HSPA;
|
|
else {
|
|
g_warning ("Couldn't parse mode change value: '%s'", str);
|
|
return;
|
|
}
|
|
|
|
g_debug ("Mode: %d", priv->mode);
|
|
mm_modem_gsm_network_mode (MM_MODEM_GSM_NETWORK (self), priv->mode);
|
|
}
|
|
|
|
static void
|
|
handle_status_change (MMSerialPort *port,
|
|
GMatchInfo *match_info,
|
|
gpointer user_data)
|
|
{
|
|
char *str;
|
|
int n1, n2, n3, n4, n5, n6, n7;
|
|
|
|
str = g_match_info_fetch (match_info, 1);
|
|
if (sscanf (str, "%x,%x,%x,%x,%x,%x,%x", &n1, &n2, &n3, &n4, &n5, &n6, &n7)) {
|
|
g_debug ("Duration: %d Up: %d Kbps Down: %d Kbps Total: %d Total: %d\n",
|
|
n1, n2 * 8 / 1000, n3 * 8 / 1000, n4 / 1024, n5 / 1024);
|
|
}
|
|
g_free (str);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* user_data != NULL means the port is a secondary port */
|
|
static gboolean
|
|
grab_port (MMModem *modem,
|
|
const char *subsys,
|
|
const char *name,
|
|
gpointer user_data,
|
|
GError **error)
|
|
{
|
|
MMGenericGsm *gsm = MM_GENERIC_GSM (modem);
|
|
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
|
const char *sys[] = { "tty", NULL };
|
|
GUdevClient *client;
|
|
GUdevDevice *device = NULL;
|
|
MMPort *port = NULL;
|
|
int usbif;
|
|
|
|
client = g_udev_client_new (sys);
|
|
if (!client) {
|
|
g_set_error (error, 0, 0, "Could not get udev client.");
|
|
return FALSE;
|
|
}
|
|
|
|
device = g_udev_client_query_by_subsystem_and_name (client, subsys, name);
|
|
if (!device) {
|
|
g_set_error (error, 0, 0, "Could not get udev device.");
|
|
goto out;
|
|
}
|
|
|
|
usbif = g_udev_device_get_property_as_int (device, "ID_USB_INTERFACE_NUM");
|
|
if (usbif < 0) {
|
|
g_set_error (error, 0, 0, "Could not get USB device interface number.");
|
|
goto out;
|
|
}
|
|
|
|
if (usbif == 0) {
|
|
if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_PRIMARY))
|
|
ptype = MM_PORT_TYPE_PRIMARY;
|
|
} else if (user_data) {
|
|
if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_SECONDARY))
|
|
ptype = MM_PORT_TYPE_SECONDARY;
|
|
}
|
|
|
|
port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error);
|
|
if (!port)
|
|
goto out;
|
|
|
|
if (MM_IS_SERIAL_PORT (port)) {
|
|
g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
|
|
if (ptype == MM_PORT_TYPE_SECONDARY) {
|
|
GRegex *regex;
|
|
|
|
mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (modem), TRUE);
|
|
|
|
regex = g_regex_new ("\\r\\n\\^RSSI:(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
|
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_signal_quality_change, modem, NULL);
|
|
g_regex_unref (regex);
|
|
|
|
regex = g_regex_new ("\\r\\n\\^MODE:(\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
|
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_mode_change, modem, NULL);
|
|
g_regex_unref (regex);
|
|
|
|
regex = g_regex_new ("\\r\\n\\^DSFLOWRPT:(.+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
|
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_status_change, modem, NULL);
|
|
g_regex_unref (regex);
|
|
|
|
regex = g_regex_new ("\\r\\n\\^BOOT:.+\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
|
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, modem, NULL);
|
|
g_regex_unref (regex);
|
|
}
|
|
}
|
|
|
|
out:
|
|
if (device)
|
|
g_object_unref (device);
|
|
g_object_unref (client);
|
|
return !!port;
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
modem_init (MMModem *modem_class)
|
|
{
|
|
modem_class->grab_port = grab_port;
|
|
}
|
|
|
|
static void
|
|
modem_gsm_network_init (MMModemGsmNetwork *class)
|
|
{
|
|
class->set_network_mode = set_network_mode;
|
|
class->get_network_mode = get_network_mode;
|
|
class->set_band = set_band;
|
|
class->get_band = get_band;
|
|
class->get_signal_quality = get_signal_quality;
|
|
}
|
|
|
|
static void
|
|
mm_modem_huawei_init (MMModemHuawei *self)
|
|
{
|
|
}
|
|
|
|
static void
|
|
mm_modem_huawei_class_init (MMModemHuaweiClass *klass)
|
|
{
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
mm_modem_huawei_parent_class = g_type_class_peek_parent (klass);
|
|
g_type_class_add_private (object_class, sizeof (MMModemHuaweiPrivate));
|
|
}
|
|
|
|
GType
|
|
mm_modem_huawei_get_type (void)
|
|
{
|
|
static GType modem_huawei_type = 0;
|
|
|
|
if (G_UNLIKELY (modem_huawei_type == 0)) {
|
|
static const GTypeInfo modem_huawei_type_info = {
|
|
sizeof (MMModemHuaweiClass),
|
|
(GBaseInitFunc) NULL,
|
|
(GBaseFinalizeFunc) NULL,
|
|
(GClassInitFunc) mm_modem_huawei_class_init,
|
|
(GClassFinalizeFunc) NULL,
|
|
NULL, /* class_data */
|
|
sizeof (MMModemHuawei),
|
|
0, /* n_preallocs */
|
|
(GInstanceInitFunc) mm_modem_huawei_init,
|
|
};
|
|
|
|
static const GInterfaceInfo modem_iface_info = {
|
|
(GInterfaceInitFunc) modem_init
|
|
};
|
|
|
|
static const GInterfaceInfo modem_gsm_network_info = {
|
|
(GInterfaceInitFunc) modem_gsm_network_init
|
|
};
|
|
|
|
modem_huawei_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemHuawei", &modem_huawei_type_info, 0);
|
|
g_type_add_interface_static (modem_huawei_type, MM_TYPE_MODEM, &modem_iface_info);
|
|
g_type_add_interface_static (modem_huawei_type, MM_TYPE_MODEM_GSM_NETWORK, &modem_gsm_network_info);
|
|
}
|
|
|
|
return modem_huawei_type;
|
|
}
|