build: move plugins directory to src/plugins
We are going to allow including the plugin sources built within the ModemManager daemon binary; moving the sources within the daemon sources directory makes it easier.
This commit is contained in:
committed by
Aleksander Morgado
parent
072d7ac906
commit
e14b904cbd
@@ -0,0 +1,37 @@
|
||||
# do not edit this file, it will be overwritten on update
|
||||
ACTION!="add|change|move|bind", GOTO="mm_huawei_port_types_end"
|
||||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="12d1", GOTO="mm_huawei_port_types"
|
||||
GOTO="mm_huawei_port_types_end"
|
||||
|
||||
LABEL="mm_huawei_port_types"
|
||||
|
||||
# MU609 does not support getportmode (crashes modem with default firmware)
|
||||
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1573", ENV{ID_MM_HUAWEI_DISABLE_GETPORTMODE}="1"
|
||||
|
||||
# Mark the modem and at port flags for ModemManager
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="01", ATTRS{bInterfaceProtocol}=="01", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_AT_PPP}="1"
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="01", ATTRS{bInterfaceProtocol}=="02", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1"
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="02", ATTRS{bInterfaceProtocol}=="01", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_AT_PPP}="1"
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="02", ATTRS{bInterfaceProtocol}=="02", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_AT_PRIMARY}="1"
|
||||
|
||||
# GPS NMEA port on MU609
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="01", ATTRS{bInterfaceProtocol}=="05", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_GPS}="1"
|
||||
# GPS NMEA port on MU909
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="01", ATTRS{bInterfaceProtocol}=="14", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_GPS}="1"
|
||||
# GPS NMEA port on MU906e
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="ff", ATTRS{bInterfaceSubClass}=="06", ATTRS{bInterfaceProtocol}=="14", SUBSYSTEM=="tty", ENV{ID_MM_PORT_TYPE_GPS}="1"
|
||||
|
||||
# Only the standard ECM or NCM port can support dial-up with AT NDISDUP through AT port
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="02", ATTRS{bInterfaceSubClass}=="06",ATTRS{bInterfaceProtocol}=="00", ENV{ID_MM_HUAWEI_NDISDUP_SUPPORTED}="1"
|
||||
SUBSYSTEMS=="usb", ATTRS{bInterfaceClass}=="02", ATTRS{bInterfaceSubClass}=="0d",ATTRS{bInterfaceProtocol}=="00", ENV{ID_MM_HUAWEI_NDISDUP_SUPPORTED}="1"
|
||||
|
||||
# Airtel branded E3372h-607, using huawei-cdc-ncm driver but with unresponsive cdc-wdm port
|
||||
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1506", ENV{ID_MM_HUAWEI_NDISDUP_SUPPORTED}="1"
|
||||
|
||||
# R215, Disable CPOL based features
|
||||
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1588", ENV{ID_MM_PREFERRED_NETWORKS_CPOL_DISABLED}="1"
|
||||
|
||||
# E226, Disable CPOL based features
|
||||
ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1003", ENV{ID_MM_PREFERRED_NETWORKS_CPOL_DISABLED}="1"
|
||||
|
||||
LABEL="mm_huawei_port_types_end"
|
||||
@@ -0,0 +1,879 @@
|
||||
/* -*- 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) 2009 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012 Lanedo GmbH
|
||||
* Copyright (C) 2012 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Author: Franko fang <huanahu@huawei.com>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <ModemManager.h>
|
||||
#include "mm-base-modem-at.h"
|
||||
#include "mm-broadband-bearer-huawei.h"
|
||||
#include "mm-log-object.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-modem-helpers-huawei.h"
|
||||
#include "mm-daemon-enums-types.h"
|
||||
|
||||
G_DEFINE_TYPE (MMBroadbandBearerHuawei, mm_broadband_bearer_huawei, MM_TYPE_BROADBAND_BEARER)
|
||||
|
||||
struct _MMBroadbandBearerHuaweiPrivate {
|
||||
gpointer connect_pending;
|
||||
gpointer disconnect_pending;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static MMPortSerialAt *
|
||||
get_dial_port (MMBroadbandModemHuawei *modem,
|
||||
MMPort *data,
|
||||
MMPortSerialAt *primary)
|
||||
{
|
||||
MMPortSerialAt *dial_port;
|
||||
|
||||
/* See if we have a cdc-wdm AT port for the interface */
|
||||
dial_port = (mm_broadband_modem_huawei_peek_port_at_for_data (
|
||||
MM_BROADBAND_MODEM_HUAWEI (modem), data));
|
||||
if (dial_port)
|
||||
return g_object_ref (dial_port);
|
||||
|
||||
/* Otherwise, fallback to using the primary port for dialing */
|
||||
return g_object_ref (primary);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Connect 3GPP */
|
||||
|
||||
typedef enum {
|
||||
CONNECT_3GPP_CONTEXT_STEP_FIRST = 0,
|
||||
CONNECT_3GPP_CONTEXT_STEP_NDISDUP,
|
||||
CONNECT_3GPP_CONTEXT_STEP_NDISSTATQRY,
|
||||
CONNECT_3GPP_CONTEXT_STEP_IP_CONFIG,
|
||||
CONNECT_3GPP_CONTEXT_STEP_LAST
|
||||
} Connect3gppContextStep;
|
||||
|
||||
typedef struct {
|
||||
MMBaseModem *modem;
|
||||
MMPortSerialAt *primary;
|
||||
MMPort *data;
|
||||
Connect3gppContextStep step;
|
||||
guint check_count;
|
||||
guint failed_ndisstatqry_count;
|
||||
MMBearerIpConfig *ipv4_config;
|
||||
} Connect3gppContext;
|
||||
|
||||
static void
|
||||
connect_3gpp_context_free (Connect3gppContext *ctx)
|
||||
{
|
||||
g_object_unref (ctx->modem);
|
||||
|
||||
g_clear_object (&ctx->ipv4_config);
|
||||
g_clear_object (&ctx->data);
|
||||
g_clear_object (&ctx->primary);
|
||||
|
||||
g_slice_free (Connect3gppContext, ctx);
|
||||
}
|
||||
|
||||
static MMBearerConnectResult *
|
||||
connect_3gpp_finish (MMBroadbandBearer *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
}
|
||||
|
||||
static void connect_3gpp_context_step (GTask *task);
|
||||
|
||||
static void
|
||||
connect_dhcp_check_ready (MMBaseModem *modem,
|
||||
GAsyncResult *res,
|
||||
MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
GTask *task;
|
||||
Connect3gppContext *ctx;
|
||||
const gchar *response;
|
||||
GError *error = NULL;
|
||||
|
||||
task = self->priv->connect_pending;
|
||||
g_assert (task != NULL);
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* Balance refcount */
|
||||
g_object_unref (self);
|
||||
|
||||
/* Cache IPv4 details if available, otherwise clients will have to use DHCP */
|
||||
response = mm_base_modem_at_command_full_finish (modem, res, &error);
|
||||
if (response) {
|
||||
guint address = 0;
|
||||
guint prefix = 0;
|
||||
guint gateway = 0;
|
||||
guint dns1 = 0;
|
||||
guint dns2 = 0;
|
||||
|
||||
if (mm_huawei_parse_dhcp_response (response,
|
||||
&address,
|
||||
&prefix,
|
||||
&gateway,
|
||||
&dns1,
|
||||
&dns2,
|
||||
&error)) {
|
||||
GInetAddress *addr;
|
||||
gchar *strarr[3] = { NULL, NULL, NULL };
|
||||
guint n = 0;
|
||||
gchar *str;
|
||||
|
||||
mm_bearer_ip_config_set_method (ctx->ipv4_config, MM_BEARER_IP_METHOD_STATIC);
|
||||
|
||||
addr = g_inet_address_new_from_bytes ((guint8 *)&address, G_SOCKET_FAMILY_IPV4);
|
||||
str = g_inet_address_to_string (addr);
|
||||
mm_bearer_ip_config_set_address (ctx->ipv4_config, str);
|
||||
g_free (str);
|
||||
g_object_unref (addr);
|
||||
|
||||
/* Netmask */
|
||||
mm_bearer_ip_config_set_prefix (ctx->ipv4_config, prefix);
|
||||
|
||||
/* Gateway */
|
||||
addr = g_inet_address_new_from_bytes ((guint8 *)&gateway, G_SOCKET_FAMILY_IPV4);
|
||||
str = g_inet_address_to_string (addr);
|
||||
mm_bearer_ip_config_set_gateway (ctx->ipv4_config, str);
|
||||
g_free (str);
|
||||
g_object_unref (addr);
|
||||
|
||||
/* DNS */
|
||||
if (dns1) {
|
||||
addr = g_inet_address_new_from_bytes ((guint8 *)&dns1, G_SOCKET_FAMILY_IPV4);
|
||||
strarr[n++] = g_inet_address_to_string (addr);
|
||||
g_object_unref (addr);
|
||||
}
|
||||
if (dns2) {
|
||||
addr = g_inet_address_new_from_bytes ((guint8 *)&dns2, G_SOCKET_FAMILY_IPV4);
|
||||
strarr[n++] = g_inet_address_to_string (addr);
|
||||
g_object_unref (addr);
|
||||
}
|
||||
mm_bearer_ip_config_set_dns (ctx->ipv4_config, (const gchar **)strarr);
|
||||
g_free (strarr[0]);
|
||||
g_free (strarr[1]);
|
||||
} else {
|
||||
mm_obj_dbg (self, "unexpected response to ^DHCP command: %s", error->message);
|
||||
}
|
||||
}
|
||||
|
||||
g_clear_error (&error);
|
||||
ctx->step++;
|
||||
connect_3gpp_context_step (task);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
connect_retry_ndisstatqry_check_cb (MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
GTask *task;
|
||||
|
||||
/* Recover context */
|
||||
task = self->priv->connect_pending;
|
||||
g_assert (task != NULL);
|
||||
|
||||
/* Balance refcount */
|
||||
g_object_unref (self);
|
||||
|
||||
/* Retry same step */
|
||||
connect_3gpp_context_step (task);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
connect_ndisstatqry_check_ready (MMBaseModem *modem,
|
||||
GAsyncResult *res,
|
||||
MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
GTask *task;
|
||||
Connect3gppContext *ctx;
|
||||
const gchar *response;
|
||||
GError *error = NULL;
|
||||
gboolean ipv4_available = FALSE;
|
||||
gboolean ipv4_connected = FALSE;
|
||||
gboolean ipv6_available = FALSE;
|
||||
gboolean ipv6_connected = FALSE;
|
||||
|
||||
task = self->priv->connect_pending;
|
||||
g_assert (task != NULL);
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* Balance refcount */
|
||||
g_object_unref (self);
|
||||
|
||||
response = mm_base_modem_at_command_full_finish (modem, res, &error);
|
||||
if (!response ||
|
||||
!mm_huawei_parse_ndisstatqry_response (response,
|
||||
&ipv4_available,
|
||||
&ipv4_connected,
|
||||
&ipv6_available,
|
||||
&ipv6_connected,
|
||||
&error)) {
|
||||
ctx->failed_ndisstatqry_count++;
|
||||
mm_obj_dbg (self, "unexpected response to ^NDISSTATQRY command: %s (%u attempts so far)",
|
||||
error->message, ctx->failed_ndisstatqry_count);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
/* Connected in IPv4? */
|
||||
if (ipv4_available && ipv4_connected) {
|
||||
/* Success! */
|
||||
ctx->step++;
|
||||
connect_3gpp_context_step (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Setup timeout to retry the same step */
|
||||
g_timeout_add_seconds (1,
|
||||
(GSourceFunc)connect_retry_ndisstatqry_check_cb,
|
||||
g_object_ref (self));
|
||||
}
|
||||
|
||||
static void
|
||||
connect_ndisdup_ready (MMBaseModem *modem,
|
||||
GAsyncResult *res,
|
||||
MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
GTask *task;
|
||||
Connect3gppContext *ctx;
|
||||
GError *error = NULL;
|
||||
|
||||
task = self->priv->connect_pending;
|
||||
g_assert (task != NULL);
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* Balance refcount */
|
||||
g_object_unref (self);
|
||||
|
||||
if (!mm_base_modem_at_command_full_finish (modem, res, &error)) {
|
||||
/* Clear task */
|
||||
self->priv->connect_pending = NULL;
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Go to next step */
|
||||
ctx->step++;
|
||||
connect_3gpp_context_step (task);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
MM_BEARER_HUAWEI_AUTH_UNKNOWN = -1,
|
||||
MM_BEARER_HUAWEI_AUTH_NONE = 0,
|
||||
MM_BEARER_HUAWEI_AUTH_PAP = 1,
|
||||
MM_BEARER_HUAWEI_AUTH_CHAP = 2,
|
||||
MM_BEARER_HUAWEI_AUTH_MSCHAPV2 = 3,
|
||||
} MMBearerHuaweiAuthPref;
|
||||
|
||||
static gint
|
||||
huawei_parse_auth_type (MMBearerAllowedAuth mm_auth)
|
||||
{
|
||||
switch (mm_auth) {
|
||||
case MM_BEARER_ALLOWED_AUTH_NONE:
|
||||
return MM_BEARER_HUAWEI_AUTH_NONE;
|
||||
case MM_BEARER_ALLOWED_AUTH_PAP:
|
||||
return MM_BEARER_HUAWEI_AUTH_PAP;
|
||||
case MM_BEARER_ALLOWED_AUTH_CHAP:
|
||||
return MM_BEARER_HUAWEI_AUTH_CHAP;
|
||||
case MM_BEARER_ALLOWED_AUTH_MSCHAPV2:
|
||||
return MM_BEARER_HUAWEI_AUTH_MSCHAPV2;
|
||||
default:
|
||||
case MM_BEARER_ALLOWED_AUTH_UNKNOWN:
|
||||
case MM_BEARER_ALLOWED_AUTH_MSCHAP:
|
||||
case MM_BEARER_ALLOWED_AUTH_EAP:
|
||||
return MM_BEARER_HUAWEI_AUTH_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
connect_3gpp_context_step (GTask *task)
|
||||
{
|
||||
MMBroadbandBearerHuawei *self;
|
||||
Connect3gppContext *ctx;
|
||||
|
||||
self = g_task_get_source_object (task);
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* Check for cancellation */
|
||||
if (g_cancellable_is_cancelled (g_task_get_cancellable (task))) {
|
||||
/* Clear task */
|
||||
self->priv->connect_pending = NULL;
|
||||
|
||||
/* If we already sent the connetion command, send the disconnection one */
|
||||
if (ctx->step > CONNECT_3GPP_CONTEXT_STEP_NDISDUP)
|
||||
mm_base_modem_at_command_full (ctx->modem,
|
||||
ctx->primary,
|
||||
"^NDISDUP=1,0",
|
||||
MM_BASE_BEARER_DEFAULT_DISCONNECTION_TIMEOUT,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL, /* Do not care the AT response */
|
||||
NULL);
|
||||
|
||||
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_CANCELLED,
|
||||
"Huawei connection operation has been cancelled");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ctx->step) {
|
||||
case CONNECT_3GPP_CONTEXT_STEP_FIRST: {
|
||||
MMBearerIpFamily ip_family;
|
||||
|
||||
ip_family = mm_bearer_properties_get_ip_type (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
|
||||
mm_3gpp_normalize_ip_family (&ip_family);
|
||||
if (ip_family != MM_BEARER_IP_FAMILY_IPV4) {
|
||||
g_task_return_new_error (task,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Only IPv4 is supported by this modem");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Store the task */
|
||||
self->priv->connect_pending = task;
|
||||
|
||||
ctx->step++;
|
||||
} /* fall through */
|
||||
|
||||
case CONNECT_3GPP_CONTEXT_STEP_NDISDUP: {
|
||||
const gchar *apn;
|
||||
const gchar *user;
|
||||
const gchar *passwd;
|
||||
MMBearerAllowedAuth auth;
|
||||
gint encoded_auth = MM_BEARER_HUAWEI_AUTH_UNKNOWN;
|
||||
gchar *command;
|
||||
|
||||
apn = mm_bearer_properties_get_apn (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
|
||||
user = mm_bearer_properties_get_user (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
|
||||
passwd = mm_bearer_properties_get_password (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
|
||||
auth = mm_bearer_properties_get_allowed_auth (mm_base_bearer_peek_config (MM_BASE_BEARER (self)));
|
||||
encoded_auth = huawei_parse_auth_type (auth);
|
||||
|
||||
/* Default to no authentication if not specified */
|
||||
if (encoded_auth == MM_BEARER_HUAWEI_AUTH_UNKNOWN)
|
||||
encoded_auth = MM_BEARER_HUAWEI_AUTH_NONE;
|
||||
|
||||
if (!user && !passwd)
|
||||
command = g_strdup_printf ("AT^NDISDUP=1,1,\"%s\"",
|
||||
apn == NULL ? "" : apn);
|
||||
else {
|
||||
if (encoded_auth == MM_BEARER_HUAWEI_AUTH_NONE) {
|
||||
encoded_auth = MM_BEARER_HUAWEI_AUTH_CHAP;
|
||||
mm_obj_dbg (self, "using default (CHAP) authentication method");
|
||||
}
|
||||
command = g_strdup_printf ("AT^NDISDUP=1,1,\"%s\",\"%s\",\"%s\",%d",
|
||||
apn == NULL ? "" : apn,
|
||||
user == NULL ? "" : user,
|
||||
passwd == NULL ? "" : passwd,
|
||||
encoded_auth);
|
||||
}
|
||||
|
||||
mm_base_modem_at_command_full (ctx->modem,
|
||||
ctx->primary,
|
||||
command,
|
||||
3,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)connect_ndisdup_ready,
|
||||
g_object_ref (self));
|
||||
g_free (command);
|
||||
return;
|
||||
}
|
||||
|
||||
case CONNECT_3GPP_CONTEXT_STEP_NDISSTATQRY:
|
||||
/* Wait for dial up timeout, retries for 180 times
|
||||
* (1s between the retries, so it means 3 minutes).
|
||||
* If too many retries, failed
|
||||
*/
|
||||
if (ctx->check_count > MM_BASE_BEARER_DEFAULT_CONNECTION_TIMEOUT) {
|
||||
/* Clear context */
|
||||
self->priv->connect_pending = NULL;
|
||||
g_task_return_new_error (task,
|
||||
MM_MOBILE_EQUIPMENT_ERROR,
|
||||
MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT,
|
||||
"Connection attempt timed out");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Give up if too many unexpected responses to NIDSSTATQRY are encountered. */
|
||||
if (ctx->failed_ndisstatqry_count > 10) {
|
||||
/* Clear context */
|
||||
self->priv->connect_pending = NULL;
|
||||
g_task_return_new_error (task,
|
||||
MM_MOBILE_EQUIPMENT_ERROR,
|
||||
MM_MOBILE_EQUIPMENT_ERROR_NOT_SUPPORTED,
|
||||
"Connection attempt not supported.");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if connected */
|
||||
ctx->check_count++;
|
||||
mm_base_modem_at_command_full (ctx->modem,
|
||||
ctx->primary,
|
||||
"^NDISSTATQRY?",
|
||||
3,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)connect_ndisstatqry_check_ready,
|
||||
g_object_ref (self));
|
||||
return;
|
||||
|
||||
case CONNECT_3GPP_CONTEXT_STEP_IP_CONFIG:
|
||||
mm_base_modem_at_command_full (ctx->modem,
|
||||
ctx->primary,
|
||||
"^DHCP?",
|
||||
3,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)connect_dhcp_check_ready,
|
||||
g_object_ref (self));
|
||||
return;
|
||||
|
||||
case CONNECT_3GPP_CONTEXT_STEP_LAST:
|
||||
/* Clear context */
|
||||
self->priv->connect_pending = NULL;
|
||||
|
||||
/* Setup result */
|
||||
g_task_return_pointer (
|
||||
task,
|
||||
mm_bearer_connect_result_new (ctx->data, ctx->ipv4_config, NULL),
|
||||
(GDestroyNotify)mm_bearer_connect_result_unref);
|
||||
|
||||
g_object_unref (task);
|
||||
return;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
connect_3gpp (MMBroadbandBearer *_self,
|
||||
MMBroadbandModem *modem,
|
||||
MMPortSerialAt *primary,
|
||||
MMPortSerialAt *secondary,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMBroadbandBearerHuawei *self = MM_BROADBAND_BEARER_HUAWEI (_self);
|
||||
Connect3gppContext *ctx;
|
||||
GTask *task;
|
||||
MMPort *data;
|
||||
|
||||
g_assert (primary != NULL);
|
||||
|
||||
/* We need a net data port */
|
||||
data = mm_base_modem_peek_best_data_port (MM_BASE_MODEM (modem), MM_PORT_TYPE_NET);
|
||||
if (!data) {
|
||||
g_task_report_new_error (self,
|
||||
callback,
|
||||
user_data,
|
||||
connect_3gpp,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_NOT_FOUND,
|
||||
"No valid data port found to launch connection");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Setup connection context */
|
||||
ctx = g_slice_new0 (Connect3gppContext);
|
||||
ctx->modem = MM_BASE_MODEM (g_object_ref (modem));
|
||||
ctx->data = g_object_ref (data);
|
||||
ctx->step = CONNECT_3GPP_CONTEXT_STEP_FIRST;
|
||||
|
||||
g_assert (self->priv->connect_pending == NULL);
|
||||
g_assert (self->priv->disconnect_pending == NULL);
|
||||
|
||||
/* Get correct dial port to use */
|
||||
ctx->primary = get_dial_port (MM_BROADBAND_MODEM_HUAWEI (ctx->modem), ctx->data, primary);
|
||||
|
||||
|
||||
/* Default to automatic/DHCP addressing */
|
||||
ctx->ipv4_config = mm_bearer_ip_config_new ();
|
||||
mm_bearer_ip_config_set_method (ctx->ipv4_config, MM_BEARER_IP_METHOD_DHCP);
|
||||
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
g_task_set_task_data (task, ctx, (GDestroyNotify)connect_3gpp_context_free);
|
||||
g_task_set_check_cancellable (task, FALSE);
|
||||
|
||||
/* Run! */
|
||||
connect_3gpp_context_step (task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Disconnect 3GPP */
|
||||
|
||||
typedef enum {
|
||||
DISCONNECT_3GPP_CONTEXT_STEP_FIRST = 0,
|
||||
DISCONNECT_3GPP_CONTEXT_STEP_NDISDUP,
|
||||
DISCONNECT_3GPP_CONTEXT_STEP_NDISSTATQRY,
|
||||
DISCONNECT_3GPP_CONTEXT_STEP_LAST
|
||||
} Disconnect3gppContextStep;
|
||||
|
||||
typedef struct {
|
||||
MMBaseModem *modem;
|
||||
MMPortSerialAt *primary;
|
||||
Disconnect3gppContextStep step;
|
||||
guint check_count;
|
||||
guint failed_ndisstatqry_count;
|
||||
} Disconnect3gppContext;
|
||||
|
||||
static void
|
||||
disconnect_3gpp_context_free (Disconnect3gppContext *ctx)
|
||||
{
|
||||
g_object_unref (ctx->primary);
|
||||
g_object_unref (ctx->modem);
|
||||
g_slice_free (Disconnect3gppContext, ctx);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
disconnect_3gpp_finish (MMBroadbandBearer *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_boolean (G_TASK (res), error);
|
||||
}
|
||||
|
||||
static void disconnect_3gpp_context_step (GTask *task);
|
||||
|
||||
static gboolean
|
||||
disconnect_retry_ndisstatqry_check_cb (MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
GTask *task;
|
||||
|
||||
/* Recover context */
|
||||
task = self->priv->disconnect_pending;
|
||||
g_assert (task != NULL);
|
||||
|
||||
/* Balance refcount */
|
||||
g_object_unref (self);
|
||||
|
||||
/* Retry same step */
|
||||
disconnect_3gpp_context_step (task);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_ndisstatqry_check_ready (MMBaseModem *modem,
|
||||
GAsyncResult *res,
|
||||
MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
GTask *task;
|
||||
Disconnect3gppContext *ctx;
|
||||
const gchar *response;
|
||||
GError *error = NULL;
|
||||
gboolean ipv4_available = FALSE;
|
||||
gboolean ipv4_connected = FALSE;
|
||||
gboolean ipv6_available = FALSE;
|
||||
gboolean ipv6_connected = FALSE;
|
||||
|
||||
task = self->priv->disconnect_pending;
|
||||
g_assert (task != NULL);
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* Balance refcount */
|
||||
g_object_unref (self);
|
||||
|
||||
response = mm_base_modem_at_command_full_finish (modem, res, &error);
|
||||
if (!response ||
|
||||
!mm_huawei_parse_ndisstatqry_response (response,
|
||||
&ipv4_available,
|
||||
&ipv4_connected,
|
||||
&ipv6_available,
|
||||
&ipv6_connected,
|
||||
&error)) {
|
||||
ctx->failed_ndisstatqry_count++;
|
||||
mm_obj_dbg (self, "unexpected response to ^NDISSTATQRY command: %s (%u attempts so far)",
|
||||
error->message, ctx->failed_ndisstatqry_count);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
/* Disconnected IPv4? */
|
||||
if (ipv4_available && !ipv4_connected) {
|
||||
/* Success! */
|
||||
ctx->step++;
|
||||
disconnect_3gpp_context_step (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Setup timeout to retry the same step */
|
||||
g_timeout_add_seconds (1,
|
||||
(GSourceFunc)disconnect_retry_ndisstatqry_check_cb,
|
||||
g_object_ref (self));
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_ndisdup_ready (MMBaseModem *modem,
|
||||
GAsyncResult *res,
|
||||
MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
GTask *task;
|
||||
Disconnect3gppContext *ctx;
|
||||
|
||||
task = self->priv->disconnect_pending;
|
||||
g_assert (task != NULL);
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* Balance refcount */
|
||||
g_object_unref (self);
|
||||
|
||||
/* Running NDISDUP=1,0 on an already disconnected bearer/context will
|
||||
* return ERROR! Ignore errors in the NDISDUP disconnection command,
|
||||
* because we're anyway going to check the bearer/context status
|
||||
* afterwards. */
|
||||
mm_base_modem_at_command_full_finish (modem, res, NULL);
|
||||
|
||||
/* Go to next step */
|
||||
ctx->step++;
|
||||
disconnect_3gpp_context_step (task);
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_3gpp_context_step (GTask *task)
|
||||
{
|
||||
MMBroadbandBearerHuawei *self;
|
||||
Disconnect3gppContext *ctx;
|
||||
|
||||
self = g_task_get_source_object (task);
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
switch (ctx->step) {
|
||||
case DISCONNECT_3GPP_CONTEXT_STEP_FIRST:
|
||||
/* Store the task */
|
||||
self->priv->disconnect_pending = task;
|
||||
ctx->step++;
|
||||
/* fall through */
|
||||
|
||||
case DISCONNECT_3GPP_CONTEXT_STEP_NDISDUP:
|
||||
mm_base_modem_at_command_full (ctx->modem,
|
||||
ctx->primary,
|
||||
"^NDISDUP=1,0",
|
||||
3,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)disconnect_ndisdup_ready,
|
||||
g_object_ref (self));
|
||||
return;
|
||||
|
||||
case DISCONNECT_3GPP_CONTEXT_STEP_NDISSTATQRY:
|
||||
/* If too many retries (1s of wait between the retries), failed */
|
||||
if (ctx->check_count > MM_BASE_BEARER_DEFAULT_DISCONNECTION_TIMEOUT) {
|
||||
/* Clear task */
|
||||
self->priv->disconnect_pending = NULL;
|
||||
g_task_return_new_error (task,
|
||||
MM_MOBILE_EQUIPMENT_ERROR,
|
||||
MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT,
|
||||
"Disconnection attempt timed out");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Give up if too many unexpected responses to NIDSSTATQRY are encountered. */
|
||||
if (ctx->failed_ndisstatqry_count > 10) {
|
||||
/* Clear task */
|
||||
self->priv->disconnect_pending = NULL;
|
||||
g_task_return_new_error (task,
|
||||
MM_MOBILE_EQUIPMENT_ERROR,
|
||||
MM_MOBILE_EQUIPMENT_ERROR_NOT_SUPPORTED,
|
||||
"Disconnection attempt not supported.");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if disconnected */
|
||||
ctx->check_count++;
|
||||
mm_base_modem_at_command_full (ctx->modem,
|
||||
ctx->primary,
|
||||
"^NDISSTATQRY?",
|
||||
3,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)disconnect_ndisstatqry_check_ready,
|
||||
g_object_ref (self));
|
||||
return;
|
||||
|
||||
case DISCONNECT_3GPP_CONTEXT_STEP_LAST:
|
||||
/* Clear task */
|
||||
self->priv->disconnect_pending = NULL;
|
||||
/* Set data port as result */
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
disconnect_3gpp (MMBroadbandBearer *_self,
|
||||
MMBroadbandModem *modem,
|
||||
MMPortSerialAt *primary,
|
||||
MMPortSerialAt *secondary,
|
||||
MMPort *data,
|
||||
guint cid,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMBroadbandBearerHuawei *self = MM_BROADBAND_BEARER_HUAWEI (_self);
|
||||
Disconnect3gppContext *ctx;
|
||||
GTask *task;
|
||||
|
||||
g_assert (primary != NULL);
|
||||
|
||||
ctx = g_slice_new0 (Disconnect3gppContext);
|
||||
ctx->modem = MM_BASE_MODEM (g_object_ref (modem));
|
||||
ctx->step = DISCONNECT_3GPP_CONTEXT_STEP_FIRST;
|
||||
|
||||
g_assert (self->priv->connect_pending == NULL);
|
||||
g_assert (self->priv->disconnect_pending == NULL);
|
||||
|
||||
/* Get correct dial port to use */
|
||||
ctx->primary = get_dial_port (MM_BROADBAND_MODEM_HUAWEI (ctx->modem), data, primary);
|
||||
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
g_task_set_task_data (task, ctx, (GDestroyNotify)disconnect_3gpp_context_free);
|
||||
|
||||
/* Start! */
|
||||
disconnect_3gpp_context_step (task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
report_connection_status (MMBaseBearer *bearer,
|
||||
MMBearerConnectionStatus status,
|
||||
const GError *connection_error)
|
||||
{
|
||||
MMBroadbandBearerHuawei *self = MM_BROADBAND_BEARER_HUAWEI (bearer);
|
||||
|
||||
g_assert (status == MM_BEARER_CONNECTION_STATUS_CONNECTED ||
|
||||
status == MM_BEARER_CONNECTION_STATUS_DISCONNECTING ||
|
||||
status == MM_BEARER_CONNECTION_STATUS_DISCONNECTED);
|
||||
|
||||
/* When a pending connection / disconnection attempt is in progress, we use
|
||||
* ^NDISSTATQRY? to check the connection status and thus temporarily ignore
|
||||
* ^NDISSTAT unsolicited messages */
|
||||
if (self->priv->connect_pending || self->priv->disconnect_pending)
|
||||
return;
|
||||
|
||||
mm_obj_dbg (self, "received spontaneous ^NDISSTAT (%s)", mm_bearer_connection_status_get_string (status));
|
||||
|
||||
/* Ignore 'CONNECTED' */
|
||||
if (status == MM_BEARER_CONNECTION_STATUS_CONNECTED)
|
||||
return;
|
||||
|
||||
/* Report disconnected right away */
|
||||
MM_BASE_BEARER_CLASS (mm_broadband_bearer_huawei_parent_class)->report_connection_status (
|
||||
bearer,
|
||||
MM_BEARER_CONNECTION_STATUS_DISCONNECTED,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMBaseBearer *
|
||||
mm_broadband_bearer_huawei_new_finish (GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
GObject *bearer;
|
||||
GObject *source;
|
||||
|
||||
source = g_async_result_get_source_object (res);
|
||||
bearer = g_async_initable_new_finish (G_ASYNC_INITABLE (source), res, error);
|
||||
g_object_unref (source);
|
||||
|
||||
if (!bearer)
|
||||
return NULL;
|
||||
|
||||
/* Only export valid bearers */
|
||||
mm_base_bearer_export (MM_BASE_BEARER (bearer));
|
||||
|
||||
return MM_BASE_BEARER (bearer);
|
||||
}
|
||||
|
||||
void
|
||||
mm_broadband_bearer_huawei_new (MMBroadbandModemHuawei *modem,
|
||||
MMBearerProperties *config,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_async_initable_new_async (
|
||||
MM_TYPE_BROADBAND_BEARER_HUAWEI,
|
||||
G_PRIORITY_DEFAULT,
|
||||
cancellable,
|
||||
callback,
|
||||
user_data,
|
||||
MM_BASE_BEARER_MODEM, modem,
|
||||
MM_BASE_BEARER_CONFIG, config,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_broadband_bearer_huawei_init (MMBroadbandBearerHuawei *self)
|
||||
{
|
||||
/* Initialize private data */
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
||||
MM_TYPE_BROADBAND_BEARER_HUAWEI,
|
||||
MMBroadbandBearerHuaweiPrivate);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_broadband_bearer_huawei_class_init (MMBroadbandBearerHuaweiClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
MMBaseBearerClass *base_bearer_class = MM_BASE_BEARER_CLASS (klass);
|
||||
MMBroadbandBearerClass *broadband_bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (MMBroadbandBearerHuaweiPrivate));
|
||||
|
||||
base_bearer_class->report_connection_status = report_connection_status;
|
||||
base_bearer_class->load_connection_status = NULL;
|
||||
base_bearer_class->load_connection_status_finish = NULL;
|
||||
#if defined WITH_SUSPEND_RESUME
|
||||
base_bearer_class->reload_connection_status = NULL;
|
||||
base_bearer_class->reload_connection_status_finish = NULL;
|
||||
#endif
|
||||
|
||||
broadband_bearer_class->connect_3gpp = connect_3gpp;
|
||||
broadband_bearer_class->connect_3gpp_finish = connect_3gpp_finish;
|
||||
broadband_bearer_class->disconnect_3gpp = disconnect_3gpp;
|
||||
broadband_bearer_class->disconnect_3gpp_finish = disconnect_3gpp_finish;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/* -*- 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) 2009 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012 Lanedo GmbH
|
||||
* Copyright (C) 2012 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Author: Franko Fang <huananhu@huawei.com>
|
||||
*/
|
||||
|
||||
#ifndef MM_BROADBAND_BEARER_HUAWEI_H
|
||||
#define MM_BROADBAND_BEARER_HUAWEI_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "mm-broadband-bearer.h"
|
||||
#include "mm-broadband-modem-huawei.h"
|
||||
|
||||
#define MM_TYPE_BROADBAND_BEARER_HUAWEI (mm_broadband_bearer_huawei_get_type ())
|
||||
#define MM_BROADBAND_BEARER_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_BEARER_HUAWEI, MMBroadbandBearerHuawei))
|
||||
#define MM_BROADBAND_BEARER_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_BEARER_HUAWEI, MMBroadbandBearerHuaweiClass))
|
||||
#define MM_IS_BROADBAND_BEARER_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_BEARER_HUAWEI))
|
||||
#define MM_IS_BROADBAND_BEARER_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_BEARER_HUAWEI))
|
||||
#define MM_BROADBAND_BEARER_HUAWEI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_BEARER_HUAWEI, MMBroadbandBearerHuaweiClass))
|
||||
|
||||
typedef struct _MMBroadbandBearerHuawei MMBroadbandBearerHuawei;
|
||||
typedef struct _MMBroadbandBearerHuaweiClass MMBroadbandBearerHuaweiClass;
|
||||
typedef struct _MMBroadbandBearerHuaweiPrivate MMBroadbandBearerHuaweiPrivate;
|
||||
|
||||
struct _MMBroadbandBearerHuawei {
|
||||
MMBroadbandBearer parent;
|
||||
MMBroadbandBearerHuaweiPrivate *priv;
|
||||
};
|
||||
|
||||
struct _MMBroadbandBearerHuaweiClass {
|
||||
MMBroadbandBearerClass parent;
|
||||
};
|
||||
|
||||
GType mm_broadband_bearer_huawei_get_type (void);
|
||||
|
||||
void mm_broadband_bearer_huawei_new (MMBroadbandModemHuawei *modem,
|
||||
MMBearerProperties *config,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
MMBaseBearer *mm_broadband_bearer_huawei_new_finish (GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_BROADBAND_BEARER_HUAWEI_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
/* -*- 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 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org>
|
||||
*/
|
||||
|
||||
#ifndef MM_BROADBAND_MODEM_HUAWEI_H
|
||||
#define MM_BROADBAND_MODEM_HUAWEI_H
|
||||
|
||||
#include "mm-broadband-modem.h"
|
||||
|
||||
#define MM_TYPE_BROADBAND_MODEM_HUAWEI (mm_broadband_modem_huawei_get_type ())
|
||||
#define MM_BROADBAND_MODEM_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_MODEM_HUAWEI, MMBroadbandModemHuawei))
|
||||
#define MM_BROADBAND_MODEM_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_MODEM_HUAWEI, MMBroadbandModemHuaweiClass))
|
||||
#define MM_IS_BROADBAND_MODEM_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_MODEM_HUAWEI))
|
||||
#define MM_IS_BROADBAND_MODEM_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_MODEM_HUAWEI))
|
||||
#define MM_BROADBAND_MODEM_HUAWEI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_MODEM_HUAWEI, MMBroadbandModemHuaweiClass))
|
||||
|
||||
typedef struct _MMBroadbandModemHuawei MMBroadbandModemHuawei;
|
||||
typedef struct _MMBroadbandModemHuaweiClass MMBroadbandModemHuaweiClass;
|
||||
typedef struct _MMBroadbandModemHuaweiPrivate MMBroadbandModemHuaweiPrivate;
|
||||
|
||||
struct _MMBroadbandModemHuawei {
|
||||
MMBroadbandModem parent;
|
||||
MMBroadbandModemHuaweiPrivate *priv;
|
||||
};
|
||||
|
||||
struct _MMBroadbandModemHuaweiClass{
|
||||
MMBroadbandModemClass parent;
|
||||
};
|
||||
|
||||
GType mm_broadband_modem_huawei_get_type (void);
|
||||
|
||||
MMBroadbandModemHuawei *mm_broadband_modem_huawei_new (const gchar *device,
|
||||
const gchar **driver,
|
||||
const gchar *plugin,
|
||||
guint16 vendor_id,
|
||||
guint16 product_id);
|
||||
|
||||
MMPortSerialAt *mm_broadband_modem_huawei_peek_port_at_for_data (MMBroadbandModemHuawei *self,
|
||||
MMPort *port);
|
||||
GList *mm_broadband_modem_huawei_get_at_port_list (MMBroadbandModemHuawei *self);
|
||||
|
||||
#endif /* MM_BROADBAND_MODEM_HUAWEI_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,193 @@
|
||||
/* -*- 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) 2013 Huawei Technologies Co., Ltd
|
||||
* Copyright (C) 2013 Aleksander Morgado <aleksander@gnu.org>
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_HELPERS_HUAWEI_H
|
||||
#define MM_MODEM_HELPERS_HUAWEI_H
|
||||
|
||||
#include <ModemManager.h>
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^NDISSTAT / ^NDISSTATQRY response parser */
|
||||
gboolean mm_huawei_parse_ndisstatqry_response (const gchar *response,
|
||||
gboolean *ipv4_available,
|
||||
gboolean *ipv4_connected,
|
||||
gboolean *ipv6_available,
|
||||
gboolean *ipv6_connected,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^DHCP response parser */
|
||||
gboolean mm_huawei_parse_dhcp_response (const char *reply,
|
||||
guint *out_address,
|
||||
guint *out_prefix,
|
||||
guint *out_gateway,
|
||||
guint *out_dns1,
|
||||
guint *out_dns2,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSINFO response parser */
|
||||
gboolean mm_huawei_parse_sysinfo_response (const char *reply,
|
||||
guint *out_srv_status,
|
||||
guint *out_srv_domain,
|
||||
guint *out_roam_status,
|
||||
guint *out_sys_mode,
|
||||
guint *out_sim_state,
|
||||
gboolean *out_sys_submode_valid,
|
||||
guint *out_sys_submode,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSINFOEX response parser */
|
||||
gboolean mm_huawei_parse_sysinfoex_response (const char *reply,
|
||||
guint *out_srv_status,
|
||||
guint *out_srv_domain,
|
||||
guint *out_roam_status,
|
||||
guint *out_sim_state,
|
||||
guint *out_sys_mode,
|
||||
guint *out_sys_submode,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^PREFMODE test parser */
|
||||
|
||||
typedef struct {
|
||||
guint prefmode;
|
||||
MMModemMode allowed;
|
||||
MMModemMode preferred;
|
||||
} MMHuaweiPrefmodeCombination;
|
||||
|
||||
GArray *mm_huawei_parse_prefmode_test (const gchar *response,
|
||||
gpointer log_object,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^PREFMODE response parser */
|
||||
|
||||
const MMHuaweiPrefmodeCombination *mm_huawei_parse_prefmode_response (const gchar *response,
|
||||
const GArray *supported_mode_combinations,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSCFG test parser */
|
||||
|
||||
/* This is the default string we use as fallback when the modem gives
|
||||
* an empty response to AT^SYSCFG=? */
|
||||
#define MM_HUAWEI_DEFAULT_SYSCFG_FMT "^SYSCFG:(2,13,14,16),(0-3),,,"
|
||||
|
||||
typedef struct {
|
||||
guint mode;
|
||||
guint acqorder;
|
||||
MMModemMode allowed;
|
||||
MMModemMode preferred;
|
||||
} MMHuaweiSyscfgCombination;
|
||||
|
||||
GArray *mm_huawei_parse_syscfg_test (const gchar *response,
|
||||
gpointer log_object,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSCFG response parser */
|
||||
|
||||
const MMHuaweiSyscfgCombination *mm_huawei_parse_syscfg_response (const gchar *response,
|
||||
const GArray *supported_mode_combinations,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSCFGEX test parser */
|
||||
|
||||
typedef struct {
|
||||
gchar *mode_str;
|
||||
MMModemMode allowed;
|
||||
MMModemMode preferred;
|
||||
} MMHuaweiSyscfgexCombination;
|
||||
|
||||
GArray *mm_huawei_parse_syscfgex_test (const gchar *response,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SYSCFGEX response parser */
|
||||
|
||||
const MMHuaweiSyscfgexCombination *mm_huawei_parse_syscfgex_response (const gchar *response,
|
||||
const GArray *supported_mode_combinations,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^NWTIME response parser */
|
||||
|
||||
gboolean mm_huawei_parse_nwtime_response (const gchar *response,
|
||||
gchar **iso8601p,
|
||||
MMNetworkTimezone **tzp,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^TIME response parser */
|
||||
|
||||
gboolean mm_huawei_parse_time_response (const gchar *response,
|
||||
gchar **iso8601p,
|
||||
MMNetworkTimezone **tzp,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^HCSQ response parser */
|
||||
|
||||
gboolean mm_huawei_parse_hcsq_response (const gchar *response,
|
||||
MMModemAccessTechnology *out_act,
|
||||
guint *out_value1,
|
||||
guint *out_value2,
|
||||
guint *out_value3,
|
||||
guint *out_value4,
|
||||
guint *out_value5,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^CVOICE response parser */
|
||||
|
||||
gboolean mm_huawei_parse_cvoice_response (const gchar *response,
|
||||
guint *hz,
|
||||
guint *bits,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^GETPORTMODE response parser */
|
||||
|
||||
typedef enum { /*< underscore_name=mm_huawei_port_mode >*/
|
||||
MM_HUAWEI_PORT_MODE_NONE,
|
||||
MM_HUAWEI_PORT_MODE_PCUI,
|
||||
MM_HUAWEI_PORT_MODE_MODEM,
|
||||
MM_HUAWEI_PORT_MODE_DIAG,
|
||||
MM_HUAWEI_PORT_MODE_GPS,
|
||||
MM_HUAWEI_PORT_MODE_NET,
|
||||
MM_HUAWEI_PORT_MODE_CDROM,
|
||||
MM_HUAWEI_PORT_MODE_SD,
|
||||
MM_HUAWEI_PORT_MODE_BT,
|
||||
MM_HUAWEI_PORT_MODE_SHELL,
|
||||
} MMHuaweiPortMode;
|
||||
|
||||
#define MM_HUAWEI_PORT_MODE_IS_SERIAL(mode) \
|
||||
(mode == MM_HUAWEI_PORT_MODE_PCUI || \
|
||||
mode == MM_HUAWEI_PORT_MODE_MODEM || \
|
||||
mode == MM_HUAWEI_PORT_MODE_DIAG || \
|
||||
mode == MM_HUAWEI_PORT_MODE_GPS || \
|
||||
mode == MM_HUAWEI_PORT_MODE_SHELL)
|
||||
|
||||
GArray *mm_huawei_parse_getportmode_response (const gchar *response,
|
||||
gpointer log_object,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_MODEM_HELPERS_HUAWEI_H */
|
||||
@@ -0,0 +1,735 @@
|
||||
/* -*- 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 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org>
|
||||
*/
|
||||
|
||||
#include <gmodule.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include <ModemManager-tags.h>
|
||||
#include "mm-port-enums-types.h"
|
||||
#include "mm-log.h"
|
||||
#include "mm-plugin-huawei.h"
|
||||
#include "mm-broadband-modem-huawei.h"
|
||||
#include "mm-modem-helpers-huawei.h"
|
||||
#include "mm-huawei-enums-types.h"
|
||||
|
||||
#if defined WITH_QMI
|
||||
#include "mm-broadband-modem-qmi.h"
|
||||
#endif
|
||||
|
||||
#if defined WITH_MBIM
|
||||
#include "mm-broadband-modem-mbim.h"
|
||||
#endif
|
||||
|
||||
G_DEFINE_TYPE (MMPluginHuawei, mm_plugin_huawei, MM_TYPE_PLUGIN)
|
||||
|
||||
MM_PLUGIN_DEFINE_MAJOR_VERSION
|
||||
MM_PLUGIN_DEFINE_MINOR_VERSION
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Custom init */
|
||||
|
||||
#define TAG_FIRST_INTERFACE_CONTEXT "first-interface-context"
|
||||
|
||||
/* Maximum time to wait for the first interface 0 to appear and get probed.
|
||||
* If it doesn't appear in this time, we'll decide which will be considered the
|
||||
* first interface. */
|
||||
#define MAX_WAIT_TIME 5
|
||||
|
||||
typedef struct {
|
||||
MMPortProbe *probe;
|
||||
gint first_usbif;
|
||||
guint timeout_id;
|
||||
gboolean custom_init_run;
|
||||
} FirstInterfaceContext;
|
||||
|
||||
static void
|
||||
first_interface_context_free (FirstInterfaceContext *ctx)
|
||||
{
|
||||
if (ctx->timeout_id)
|
||||
g_source_remove (ctx->timeout_id);
|
||||
g_object_unref (ctx->probe);
|
||||
g_slice_free (FirstInterfaceContext, ctx);
|
||||
}
|
||||
|
||||
#define TAG_GETPORTMODE_RESULT "getportmode-result"
|
||||
#define TAG_AT_PORT_FLAGS "at-port-flags"
|
||||
|
||||
typedef struct {
|
||||
MMPortSerialAt *port;
|
||||
gboolean curc_done;
|
||||
guint curc_retries;
|
||||
gboolean getportmode_done;
|
||||
guint getportmode_retries;
|
||||
} HuaweiCustomInitContext;
|
||||
|
||||
static void
|
||||
huawei_custom_init_context_free (HuaweiCustomInitContext *ctx)
|
||||
{
|
||||
g_object_unref (ctx->port);
|
||||
g_slice_free (HuaweiCustomInitContext, ctx);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
huawei_custom_init_finish (MMPortProbe *probe,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void huawei_custom_init_step (GTask *task);
|
||||
|
||||
static void
|
||||
getportmode_ready (MMPortSerialAt *port,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
MMDevice *device;
|
||||
MMPortProbe *probe;
|
||||
HuaweiCustomInitContext *ctx;
|
||||
const gchar *response;
|
||||
GArray *modes;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
probe = g_task_get_source_object (task);
|
||||
ctx = g_task_get_task_data (task);
|
||||
device = mm_port_probe_peek_device (probe);
|
||||
|
||||
response = mm_port_serial_at_command_finish (port, res, &error);
|
||||
if (error) {
|
||||
mm_obj_dbg (probe, "couldn't get port mode: '%s'", error->message);
|
||||
|
||||
/* If any error occurred that was not ERROR or COMMAND NOT SUPPORT then
|
||||
* retry the command.
|
||||
*/
|
||||
if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_UNKNOWN))
|
||||
ctx->getportmode_done = TRUE;
|
||||
huawei_custom_init_step (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Mark port as being AT already */
|
||||
mm_port_probe_set_result_at (probe, TRUE);
|
||||
|
||||
/* Flag as GETPORTMODE already done */
|
||||
ctx->getportmode_done = TRUE;
|
||||
|
||||
modes = mm_huawei_parse_getportmode_response (response, probe, &error);
|
||||
if (!modes)
|
||||
mm_obj_warn (probe, "failed to parse ^GETPORTMODE response: %s", error->message);
|
||||
else
|
||||
g_object_set_data_full (G_OBJECT (device), TAG_GETPORTMODE_RESULT, modes, (GDestroyNotify) g_array_unref);
|
||||
huawei_custom_init_step (task);
|
||||
}
|
||||
|
||||
static void
|
||||
curc_ready (MMPortSerialAt *port,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
MMPortProbe *probe;
|
||||
HuaweiCustomInitContext *ctx;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
probe = g_task_get_source_object (task);
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
mm_port_serial_at_command_finish (port, res, &error);
|
||||
if (error) {
|
||||
/* Retry if we get a timeout error */
|
||||
if (g_error_matches (error,
|
||||
MM_SERIAL_ERROR,
|
||||
MM_SERIAL_ERROR_RESPONSE_TIMEOUT))
|
||||
goto out;
|
||||
|
||||
mm_obj_dbg (probe, "couldn't turn off unsolicited messages in secondary ports: %s", error->message);
|
||||
}
|
||||
|
||||
mm_obj_dbg (probe, "unsolicited messages in secondary ports turned off");
|
||||
|
||||
ctx->curc_done = TRUE;
|
||||
|
||||
out:
|
||||
huawei_custom_init_step (task);
|
||||
}
|
||||
|
||||
static void
|
||||
try_next_usbif (MMPortProbe *probe,
|
||||
MMDevice *device)
|
||||
{
|
||||
FirstInterfaceContext *fi_ctx;
|
||||
GList *l;
|
||||
gint closest;
|
||||
|
||||
fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT);
|
||||
g_assert (fi_ctx != NULL);
|
||||
|
||||
/* Look for the next closest one among the list of interfaces in the device,
|
||||
* and enable that one as being first */
|
||||
closest = G_MAXINT;
|
||||
for (l = mm_device_peek_port_probe_list (device); l; l = g_list_next (l)) {
|
||||
MMPortProbe *iter = MM_PORT_PROBE (l->data);
|
||||
|
||||
/* Only expect ttys for next probing attempt */
|
||||
if (g_str_equal (mm_port_probe_get_port_subsys (iter), "tty")) {
|
||||
gint usbif;
|
||||
|
||||
usbif = mm_kernel_device_get_interface_number (mm_port_probe_peek_port (iter));
|
||||
if (usbif == fi_ctx->first_usbif) {
|
||||
/* This is the one we just probed, which wasn't yet removed, so just skip it */
|
||||
} else if (usbif > fi_ctx->first_usbif &&
|
||||
usbif < closest) {
|
||||
closest = usbif;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (closest == G_MAXINT) {
|
||||
/* No more ttys to try! Just return something */
|
||||
closest = 0;
|
||||
mm_obj_dbg (probe, "no more ports to run initial probing");
|
||||
} else
|
||||
mm_obj_dbg (probe, "will try initial probing with interface '%d' instead", closest);
|
||||
|
||||
fi_ctx->first_usbif = closest;
|
||||
}
|
||||
|
||||
static void
|
||||
huawei_custom_init_step (GTask *task)
|
||||
{
|
||||
MMPortProbe *probe;
|
||||
HuaweiCustomInitContext *ctx;
|
||||
FirstInterfaceContext *fi_ctx;
|
||||
MMKernelDevice *port;
|
||||
|
||||
probe = g_task_get_source_object (task);
|
||||
ctx = g_task_get_task_data (task);
|
||||
|
||||
/* If cancelled, end */
|
||||
if (g_task_return_error_if_cancelled (task)) {
|
||||
mm_obj_dbg (probe, "no need to keep on running custom init");
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ctx->curc_done) {
|
||||
if (ctx->curc_retries == 0) {
|
||||
/* All retries consumed, probably not an AT port */
|
||||
mm_port_probe_set_result_at (probe, FALSE);
|
||||
/* Try with next */
|
||||
try_next_usbif (probe, mm_port_probe_peek_device (probe));
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->curc_retries--;
|
||||
/* Turn off unsolicited messages on secondary ports until needed */
|
||||
mm_port_serial_at_command (
|
||||
ctx->port,
|
||||
"AT^CURC=0",
|
||||
3,
|
||||
FALSE, /* raw */
|
||||
FALSE, /* allow_cached */
|
||||
g_task_get_cancellable (task),
|
||||
(GAsyncReadyCallback)curc_ready,
|
||||
task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Try to get a port map from the modem */
|
||||
port = mm_port_probe_peek_port (probe);
|
||||
if (!ctx->getportmode_done && !mm_kernel_device_get_global_property_as_boolean (port, "ID_MM_HUAWEI_DISABLE_GETPORTMODE")) {
|
||||
if (ctx->getportmode_retries == 0) {
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->getportmode_retries--;
|
||||
mm_port_serial_at_command (
|
||||
ctx->port,
|
||||
"AT^GETPORTMODE",
|
||||
3,
|
||||
FALSE, /* raw */
|
||||
FALSE, /* allow_cached */
|
||||
g_task_get_cancellable (task),
|
||||
(GAsyncReadyCallback)getportmode_ready,
|
||||
task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* All done it seems */
|
||||
fi_ctx = g_object_get_data (G_OBJECT (mm_port_probe_peek_device (probe)), TAG_FIRST_INTERFACE_CONTEXT);
|
||||
g_assert (fi_ctx != NULL);
|
||||
fi_ctx->custom_init_run = TRUE;
|
||||
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
first_interface_missing_timeout_cb (MMDevice *device)
|
||||
{
|
||||
FirstInterfaceContext *fi_ctx;
|
||||
|
||||
fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT);
|
||||
g_assert (fi_ctx != NULL);
|
||||
try_next_usbif (fi_ctx->probe, device);
|
||||
|
||||
/* Reload the timeout, just in case we end up not having the next interface to probe...
|
||||
* which is anyway very unlikely as we got it by looking at the real probe list, but anyway... */
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
static void
|
||||
huawei_custom_init (MMPortProbe *probe,
|
||||
MMPortSerialAt *port,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMDevice *device;
|
||||
FirstInterfaceContext *fi_ctx;
|
||||
HuaweiCustomInitContext *ctx;
|
||||
GTask *task;
|
||||
|
||||
device = mm_port_probe_peek_device (probe);
|
||||
|
||||
/* The primary port (called the "modem" port in the Windows drivers) is
|
||||
* always USB interface 0, and we need to detect that interface first for
|
||||
* two reasons: (1) to disable unsolicited messages on other ports that
|
||||
* may fill up the buffer and crash the device, and (2) to attempt to get
|
||||
* the port layout for hints about what the secondary port is (called the
|
||||
* "pcui" port in Windows). Thus we probe USB interface 0 first and defer
|
||||
* probing other interfaces until we've got if0, at which point we allow
|
||||
* the other ports to be probed too.
|
||||
*/
|
||||
fi_ctx = g_object_get_data (G_OBJECT (device), TAG_FIRST_INTERFACE_CONTEXT);
|
||||
if (!fi_ctx) {
|
||||
/* This is the first time we ask for the context. Set it up. */
|
||||
fi_ctx = g_slice_new0 (FirstInterfaceContext);
|
||||
fi_ctx->probe = g_object_ref (probe);
|
||||
g_object_set_data_full (G_OBJECT (device),
|
||||
TAG_FIRST_INTERFACE_CONTEXT,
|
||||
fi_ctx,
|
||||
(GDestroyNotify)first_interface_context_free);
|
||||
/* The timeout is controlled in the data set in 'device', and therefore
|
||||
* it should be safe to assume that the timeout will not get fired after
|
||||
* having disposed 'device' */
|
||||
fi_ctx->timeout_id = g_timeout_add_seconds (MAX_WAIT_TIME,
|
||||
(GSourceFunc)first_interface_missing_timeout_cb,
|
||||
device);
|
||||
|
||||
/* By default, we'll ask the Huawei plugin to start probing usbif 0 */
|
||||
fi_ctx->first_usbif = 0;
|
||||
|
||||
/* Custom init of the Huawei plugin is to be run only in the first
|
||||
* interface. We'll control here whether we did run it already or not. */
|
||||
fi_ctx->custom_init_run = FALSE;
|
||||
}
|
||||
|
||||
ctx = g_slice_new (HuaweiCustomInitContext);
|
||||
ctx->port = g_object_ref (port);
|
||||
ctx->curc_done = FALSE;
|
||||
ctx->curc_retries = 3;
|
||||
ctx->getportmode_done = FALSE;
|
||||
ctx->getportmode_retries = 3;
|
||||
|
||||
task = g_task_new (probe, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, ctx, (GDestroyNotify)huawei_custom_init_context_free);
|
||||
|
||||
/* Custom init only to be run in the first interface */
|
||||
if (mm_kernel_device_get_interface_number (mm_port_probe_peek_port (probe)) != fi_ctx->first_usbif) {
|
||||
if (fi_ctx->custom_init_run)
|
||||
/* If custom init was run already, we can consider this as successfully run */
|
||||
g_task_return_boolean (task, TRUE);
|
||||
else
|
||||
/* Otherwise, we'll need to defer the probing a bit more */
|
||||
g_task_return_new_error (task,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_RETRY,
|
||||
"Defer needed");
|
||||
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
/* We can run custom init in the first interface! clear the timeout as it is no longer needed */
|
||||
if (fi_ctx->timeout_id) {
|
||||
g_source_remove (fi_ctx->timeout_id);
|
||||
fi_ctx->timeout_id = 0;
|
||||
}
|
||||
|
||||
huawei_custom_init_step (task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gint
|
||||
probe_cmp_by_usbif (MMPortProbe *a,
|
||||
MMPortProbe *b)
|
||||
{
|
||||
return (mm_kernel_device_get_interface_number (mm_port_probe_peek_port (a)) -
|
||||
mm_kernel_device_get_interface_number (mm_port_probe_peek_port (b)));
|
||||
}
|
||||
|
||||
static guint
|
||||
propagate_getportmode_hints (MMPlugin *self,
|
||||
GList *probes,
|
||||
gboolean *primary_flagged)
|
||||
{
|
||||
MMDevice *device;
|
||||
GArray *modes;
|
||||
GList *l;
|
||||
GList *tty_probes = NULL;
|
||||
guint n_ports_with_hints = 0;
|
||||
guint mode_i = 0;
|
||||
|
||||
g_assert (probes != NULL);
|
||||
device = mm_port_probe_peek_device (MM_PORT_PROBE (probes->data));
|
||||
modes = g_object_get_data (G_OBJECT (device), TAG_GETPORTMODE_RESULT);
|
||||
|
||||
/* Nothing to do if GETPORTMODE is flagged as not supported */
|
||||
if (!modes)
|
||||
return 0;
|
||||
|
||||
/* Build a list of TTY port probes (AT and not-AT) sorted by interface number */
|
||||
for (l = probes; l; l = g_list_next (l)) {
|
||||
MMPortProbe *probe;
|
||||
|
||||
probe = MM_PORT_PROBE (l->data);
|
||||
if (g_str_equal (mm_port_probe_get_port_subsys (probe), "tty"))
|
||||
tty_probes = g_list_insert_sorted (tty_probes, probe, (GCompareFunc) probe_cmp_by_usbif);
|
||||
}
|
||||
|
||||
/* Propagate the getportmode tags to the specific port probes */
|
||||
for (l = tty_probes, mode_i = 0; l; l = g_list_next (l)) {
|
||||
MMPortProbe *probe;
|
||||
MMPortSerialAtFlag at_port_flags = MM_PORT_SERIAL_AT_FLAG_NONE;
|
||||
MMHuaweiPortMode port_mode;
|
||||
|
||||
probe = MM_PORT_PROBE (l->data);
|
||||
|
||||
/* Look for the next serial port mode applicable */
|
||||
while (!MM_HUAWEI_PORT_MODE_IS_SERIAL (g_array_index (modes, MMHuaweiPortMode, mode_i)) && (mode_i < modes->len))
|
||||
mode_i++;
|
||||
if (mode_i == modes->len) {
|
||||
mm_obj_dbg (probe, "missing port mode hint");
|
||||
continue;
|
||||
}
|
||||
|
||||
port_mode = g_array_index (modes, MMHuaweiPortMode, mode_i);
|
||||
if (!mm_port_probe_is_at (probe)) {
|
||||
mm_obj_dbg (probe, "port mode hint for non-AT port: %s", mm_huawei_port_mode_get_string (port_mode));
|
||||
mode_i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
mm_obj_dbg (probe, "port mode hint for AT port: %s", mm_huawei_port_mode_get_string (port_mode));
|
||||
if (port_mode == MM_HUAWEI_PORT_MODE_PCUI)
|
||||
at_port_flags = MM_PORT_SERIAL_AT_FLAG_PRIMARY;
|
||||
else if (port_mode == MM_HUAWEI_PORT_MODE_MODEM)
|
||||
at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP;
|
||||
|
||||
if (at_port_flags != MM_PORT_SERIAL_AT_FLAG_NONE) {
|
||||
n_ports_with_hints++;
|
||||
g_object_set_data (G_OBJECT (probe), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (at_port_flags));
|
||||
}
|
||||
mode_i++;
|
||||
}
|
||||
|
||||
g_list_free (tty_probes);
|
||||
|
||||
return n_ports_with_hints;
|
||||
}
|
||||
|
||||
static guint
|
||||
propagate_description_hints (MMPlugin *self,
|
||||
GList *probes,
|
||||
gboolean *primary_flagged)
|
||||
{
|
||||
GList *l;
|
||||
guint n_ports_with_hints = 0;
|
||||
|
||||
for (l = probes; l; l = g_list_next (l)) {
|
||||
MMPortProbe *probe;
|
||||
MMPortSerialAtFlag at_port_flags = MM_PORT_SERIAL_AT_FLAG_NONE;
|
||||
const gchar *description;
|
||||
g_autofree gchar *lower_description = NULL;
|
||||
|
||||
probe = MM_PORT_PROBE (l->data);
|
||||
|
||||
if (!mm_port_probe_is_at (probe))
|
||||
continue;
|
||||
|
||||
description = mm_kernel_device_get_interface_description (mm_port_probe_peek_port (probe));
|
||||
if (!description)
|
||||
continue;
|
||||
|
||||
mm_obj_dbg (probe, "%s interface description: %s", mm_port_probe_get_port_name (probe), description);
|
||||
|
||||
lower_description = g_ascii_strdown (description, -1);
|
||||
if (strstr (lower_description, "modem"))
|
||||
at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP;
|
||||
else if (strstr (lower_description, "pcui")) {
|
||||
at_port_flags = MM_PORT_SERIAL_AT_FLAG_PRIMARY;
|
||||
*primary_flagged = TRUE;
|
||||
}
|
||||
|
||||
if (at_port_flags != MM_PORT_SERIAL_AT_FLAG_NONE) {
|
||||
n_ports_with_hints++;
|
||||
g_object_set_data (G_OBJECT (probe), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (at_port_flags));
|
||||
}
|
||||
}
|
||||
|
||||
return n_ports_with_hints;
|
||||
}
|
||||
|
||||
static guint
|
||||
propagate_generic_hints (MMPlugin *self,
|
||||
GList *probes,
|
||||
gboolean *primary_flagged)
|
||||
{
|
||||
GList *l;
|
||||
guint n_ports_with_hints = 0;
|
||||
|
||||
for (l = probes; l; l = g_list_next (l)) {
|
||||
MMPortProbe *probe;
|
||||
MMKernelDevice *kernel_device;
|
||||
MMPortSerialAtFlag at_port_flags = MM_PORT_SERIAL_AT_FLAG_NONE;
|
||||
|
||||
probe = MM_PORT_PROBE (l->data);
|
||||
|
||||
if (!mm_port_probe_is_at (probe))
|
||||
continue;
|
||||
|
||||
kernel_device = mm_port_probe_peek_port (probe);
|
||||
if (mm_kernel_device_get_property_as_boolean (kernel_device, ID_MM_PORT_TYPE_AT_PRIMARY)) {
|
||||
at_port_flags = MM_PORT_SERIAL_AT_FLAG_PRIMARY;
|
||||
*primary_flagged = TRUE;
|
||||
}
|
||||
else if (mm_kernel_device_get_property_as_boolean (kernel_device, ID_MM_PORT_TYPE_AT_SECONDARY))
|
||||
at_port_flags = MM_PORT_SERIAL_AT_FLAG_SECONDARY;
|
||||
else if (mm_kernel_device_get_property_as_boolean (kernel_device, ID_MM_PORT_TYPE_AT_PPP))
|
||||
at_port_flags = MM_PORT_SERIAL_AT_FLAG_PPP;
|
||||
|
||||
if (at_port_flags != MM_PORT_SERIAL_AT_FLAG_NONE) {
|
||||
n_ports_with_hints++;
|
||||
g_object_set_data (G_OBJECT (probe), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (at_port_flags));
|
||||
}
|
||||
}
|
||||
|
||||
return n_ports_with_hints;
|
||||
}
|
||||
|
||||
static guint
|
||||
fallback_primary_cdcwdm (MMPlugin *self,
|
||||
GList *probes)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = probes; l; l = g_list_next (l)) {
|
||||
MMPortProbe *probe;
|
||||
|
||||
probe = MM_PORT_PROBE (l->data);
|
||||
|
||||
if (!mm_port_probe_is_at (probe))
|
||||
continue;
|
||||
|
||||
if (g_str_equal (mm_port_probe_get_port_subsys (probe), "usbmisc")) {
|
||||
mm_obj_dbg (self, "fallback port type hint applied to first cdc-wmd port found");
|
||||
g_object_set_data (G_OBJECT (probe), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (MM_PORT_SERIAL_AT_FLAG_PRIMARY));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static guint
|
||||
fallback_usbif0 (MMPlugin *self,
|
||||
GList *probes)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = probes; l; l = g_list_next (l)) {
|
||||
MMPortProbe *probe;
|
||||
guint usbif;
|
||||
|
||||
probe = MM_PORT_PROBE (l->data);
|
||||
|
||||
if (!mm_port_probe_is_at (probe))
|
||||
continue;
|
||||
|
||||
usbif = mm_kernel_device_get_property_as_int_hex (mm_port_probe_peek_port (probe), "ID_USB_INTERFACE_NUM");
|
||||
if (usbif == 0) {
|
||||
mm_obj_dbg (self, "fallback port type hint applied to interface 0");
|
||||
g_object_set_data (G_OBJECT (probe), TAG_AT_PORT_FLAGS, GUINT_TO_POINTER (MM_PORT_SERIAL_AT_FLAG_PPP));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
propagate_port_type_hints (MMPlugin *self,
|
||||
GList *probes)
|
||||
{
|
||||
gboolean primary_flagged = FALSE;
|
||||
guint n_ports_with_hints;
|
||||
|
||||
g_assert (probes != NULL);
|
||||
|
||||
if ((n_ports_with_hints = propagate_getportmode_hints (self, probes, &primary_flagged)) > 0)
|
||||
mm_obj_dbg (self, "port type hints set by GETPORTMODE");
|
||||
else if ((n_ports_with_hints = propagate_description_hints (self, probes, &primary_flagged)) > 0)
|
||||
mm_obj_dbg (self, "port type hints set by interface descriptions");
|
||||
else if ((n_ports_with_hints = propagate_generic_hints (self, probes, &primary_flagged)) > 0)
|
||||
mm_obj_dbg (self, "port type hints set by generic udev tags");
|
||||
|
||||
/* Fallback hint for the first cdc-wdm port if no other port has been flagged as primary */
|
||||
if (!primary_flagged)
|
||||
n_ports_with_hints += fallback_primary_cdcwdm (self, probes);
|
||||
|
||||
/* If not a single port type hint available (not plugin-provided and not generic)
|
||||
* then we'll assume usbif 0 is the modem port */
|
||||
if (!n_ports_with_hints)
|
||||
n_ports_with_hints = fallback_usbif0 (self, probes);
|
||||
|
||||
mm_obj_dbg (self, "%u port hints have been set", n_ports_with_hints);
|
||||
}
|
||||
|
||||
static MMBaseModem *
|
||||
create_modem (MMPlugin *self,
|
||||
const gchar *uid,
|
||||
const gchar **drivers,
|
||||
guint16 vendor,
|
||||
guint16 product,
|
||||
guint16 subsystem_vendor,
|
||||
GList *probes,
|
||||
GError **error)
|
||||
{
|
||||
propagate_port_type_hints (self, probes);
|
||||
|
||||
#if defined WITH_QMI
|
||||
if (mm_port_probe_list_has_qmi_port (probes)) {
|
||||
mm_obj_dbg (self, "QMI-powered Huawei modem found...");
|
||||
return MM_BASE_MODEM (mm_broadband_modem_qmi_new (uid,
|
||||
drivers,
|
||||
mm_plugin_get_name (self),
|
||||
vendor,
|
||||
product));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined WITH_MBIM
|
||||
if (mm_port_probe_list_has_mbim_port (probes)) {
|
||||
mm_obj_dbg (self, "MBIM-powered Huawei modem found...");
|
||||
return MM_BASE_MODEM (mm_broadband_modem_mbim_new (uid,
|
||||
drivers,
|
||||
mm_plugin_get_name (self),
|
||||
vendor,
|
||||
product));
|
||||
}
|
||||
#endif
|
||||
|
||||
return MM_BASE_MODEM (mm_broadband_modem_huawei_new (uid,
|
||||
drivers,
|
||||
mm_plugin_get_name (self),
|
||||
vendor,
|
||||
product));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
grab_port (MMPlugin *self,
|
||||
MMBaseModem *modem,
|
||||
MMPortProbe *probe,
|
||||
GError **error)
|
||||
{
|
||||
MMPortSerialAtFlag pflags;
|
||||
MMKernelDevice *port;
|
||||
MMPortType port_type;
|
||||
|
||||
port_type = mm_port_probe_get_port_type (probe);
|
||||
port = mm_port_probe_peek_port (probe);
|
||||
|
||||
pflags = (MMPortSerialAtFlag) GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (probe), TAG_AT_PORT_FLAGS));
|
||||
if (pflags != MM_PORT_SERIAL_AT_FLAG_NONE) {
|
||||
gchar *str;
|
||||
|
||||
str = mm_port_serial_at_flag_build_string_from_mask (pflags);
|
||||
mm_obj_dbg (self, "(%s/%s) port will have AT flags '%s'",
|
||||
mm_port_probe_get_port_subsys (probe),
|
||||
mm_port_probe_get_port_name (probe),
|
||||
str);
|
||||
g_free (str);
|
||||
} else {
|
||||
/* The huawei plugin handles the generic udev tags itself, so explicitly request
|
||||
* to avoid processing them by the generic modem. */
|
||||
pflags = MM_PORT_SERIAL_AT_FLAG_NONE_NO_GENERIC;
|
||||
}
|
||||
|
||||
return mm_base_modem_grab_port (modem,
|
||||
port,
|
||||
port_type,
|
||||
pflags,
|
||||
error);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
G_MODULE_EXPORT MMPlugin *
|
||||
mm_plugin_create (void)
|
||||
{
|
||||
static const gchar *subsystems[] = { "tty", "net", "usbmisc", NULL };
|
||||
static const guint16 vendor_ids[] = { 0x12d1, 0 };
|
||||
static const MMAsyncMethod custom_init = {
|
||||
.async = G_CALLBACK (huawei_custom_init),
|
||||
.finish = G_CALLBACK (huawei_custom_init_finish),
|
||||
};
|
||||
|
||||
return MM_PLUGIN (
|
||||
g_object_new (MM_TYPE_PLUGIN_HUAWEI,
|
||||
MM_PLUGIN_NAME, MM_MODULE_NAME,
|
||||
MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems,
|
||||
MM_PLUGIN_ALLOWED_VENDOR_IDS, vendor_ids,
|
||||
MM_PLUGIN_ALLOWED_AT, TRUE,
|
||||
MM_PLUGIN_REQUIRED_QCDM, TRUE,
|
||||
MM_PLUGIN_ALLOWED_QMI, TRUE,
|
||||
MM_PLUGIN_ALLOWED_MBIM, TRUE,
|
||||
MM_PLUGIN_CUSTOM_INIT, &custom_init,
|
||||
NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_huawei_init (MMPluginHuawei *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_huawei_class_init (MMPluginHuaweiClass *klass)
|
||||
{
|
||||
MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass);
|
||||
|
||||
plugin_class->create_modem = create_modem;
|
||||
plugin_class->grab_port = grab_port;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/* -*- 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 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org
|
||||
*/
|
||||
|
||||
#ifndef MM_PLUGIN_HUAWEI_H
|
||||
#define MM_PLUGIN_HUAWEI_H
|
||||
|
||||
#include "mm-plugin.h"
|
||||
|
||||
#define MM_TYPE_PLUGIN_HUAWEI (mm_plugin_huawei_get_type ())
|
||||
#define MM_PLUGIN_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_HUAWEI, MMPluginHuawei))
|
||||
#define MM_PLUGIN_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_HUAWEI, MMPluginHuaweiClass))
|
||||
#define MM_IS_PLUGIN_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_HUAWEI))
|
||||
#define MM_IS_PLUGIN_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_HUAWEI))
|
||||
#define MM_PLUGIN_HUAWEI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_HUAWEI, MMPluginHuaweiClass))
|
||||
|
||||
typedef struct {
|
||||
MMPlugin parent;
|
||||
} MMPluginHuawei;
|
||||
|
||||
typedef struct {
|
||||
MMPluginClass parent;
|
||||
} MMPluginHuaweiClass;
|
||||
|
||||
GType mm_plugin_huawei_get_type (void);
|
||||
|
||||
G_MODULE_EXPORT MMPlugin *mm_plugin_create (void);
|
||||
|
||||
#endif /* MM_PLUGIN_HUAWEI_H */
|
||||
@@ -0,0 +1,167 @@
|
||||
/* -*- 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 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012 Lanedo GmbH
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <ModemManager.h>
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-base-modem-at.h"
|
||||
|
||||
#include "mm-sim-huawei.h"
|
||||
|
||||
G_DEFINE_TYPE (MMSimHuawei, mm_sim_huawei, MM_TYPE_BASE_SIM)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* SIM identifier loading */
|
||||
|
||||
static gchar *
|
||||
load_sim_identifier_finish (MMBaseSim *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
}
|
||||
|
||||
static void
|
||||
parent_load_sim_identifier_ready (MMSimHuawei *self,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gchar *simid;
|
||||
|
||||
simid = MM_BASE_SIM_CLASS (mm_sim_huawei_parent_class)->load_sim_identifier_finish (MM_BASE_SIM (self), res, &error);
|
||||
if (simid)
|
||||
g_task_return_pointer (task, simid, g_free);
|
||||
else
|
||||
g_task_return_error (task, error);
|
||||
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
iccid_read_ready (MMBaseModem *modem,
|
||||
GAsyncResult *res,
|
||||
GTask *task)
|
||||
{
|
||||
MMBaseSim *self;
|
||||
const gchar *response;
|
||||
const gchar *p;
|
||||
char *parsed;
|
||||
|
||||
response = mm_base_modem_at_command_finish (modem, res, NULL);
|
||||
if (!response)
|
||||
goto error;
|
||||
|
||||
p = mm_strip_tag (response, "^ICCID:");
|
||||
if (!p)
|
||||
goto error;
|
||||
|
||||
parsed = mm_3gpp_parse_iccid (p, NULL);
|
||||
if (parsed) {
|
||||
g_task_return_pointer (task, parsed, g_free);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
error:
|
||||
/* Chain up to parent method; older devices don't support ^ICCID */
|
||||
self = g_task_get_source_object (task);
|
||||
MM_BASE_SIM_CLASS (mm_sim_huawei_parent_class)->load_sim_identifier (self,
|
||||
(GAsyncReadyCallback) parent_load_sim_identifier_ready,
|
||||
task);
|
||||
}
|
||||
|
||||
static void
|
||||
load_sim_identifier (MMBaseSim *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMBaseModem *modem = NULL;
|
||||
|
||||
g_object_get (self,
|
||||
MM_BASE_SIM_MODEM, &modem,
|
||||
NULL);
|
||||
|
||||
mm_base_modem_at_command (
|
||||
modem,
|
||||
"^ICCID?",
|
||||
5,
|
||||
FALSE,
|
||||
(GAsyncReadyCallback)iccid_read_ready,
|
||||
g_task_new (self, NULL, callback, user_data));
|
||||
g_object_unref (modem);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMBaseSim *
|
||||
mm_sim_huawei_new_finish (GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
GObject *source;
|
||||
GObject *sim;
|
||||
|
||||
source = g_async_result_get_source_object (res);
|
||||
sim = g_async_initable_new_finish (G_ASYNC_INITABLE (source), res, error);
|
||||
g_object_unref (source);
|
||||
|
||||
if (!sim)
|
||||
return NULL;
|
||||
|
||||
/* Only export valid SIMs */
|
||||
mm_base_sim_export (MM_BASE_SIM (sim));
|
||||
|
||||
return MM_BASE_SIM (sim);
|
||||
}
|
||||
|
||||
void
|
||||
mm_sim_huawei_new (MMBaseModem *modem,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_async_initable_new_async (MM_TYPE_SIM_HUAWEI,
|
||||
G_PRIORITY_DEFAULT,
|
||||
cancellable,
|
||||
callback,
|
||||
user_data,
|
||||
MM_BASE_SIM_MODEM, modem,
|
||||
"active", TRUE, /* by default always active */
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_sim_huawei_init (MMSimHuawei *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_sim_huawei_class_init (MMSimHuaweiClass *klass)
|
||||
{
|
||||
MMBaseSimClass *base_sim_class = MM_BASE_SIM_CLASS (klass);
|
||||
|
||||
base_sim_class->load_sim_identifier = load_sim_identifier;
|
||||
base_sim_class->load_sim_identifier_finish = load_sim_identifier_finish;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/* -*- 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 - 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012 Lanedo GmbH
|
||||
*/
|
||||
|
||||
#ifndef MM_SIM_HUAWEI_H
|
||||
#define MM_SIM_HUAWEI_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "mm-base-sim.h"
|
||||
|
||||
#define MM_TYPE_SIM_HUAWEI (mm_sim_huawei_get_type ())
|
||||
#define MM_SIM_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_SIM_HUAWEI, MMSimHuawei))
|
||||
#define MM_SIM_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_SIM_HUAWEI, MMSimHuaweiClass))
|
||||
#define MM_IS_SIM_HUAWEI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_SIM_HUAWEI))
|
||||
#define MM_IS_SIM_HUAWEI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_SIM_HUAWEI))
|
||||
#define MM_SIM_HUAWEI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_SIM_HUAWEI, MMSimHuaweiClass))
|
||||
|
||||
typedef struct _MMSimHuawei MMSimHuawei;
|
||||
typedef struct _MMSimHuaweiClass MMSimHuaweiClass;
|
||||
|
||||
struct _MMSimHuawei {
|
||||
MMBaseSim parent;
|
||||
};
|
||||
|
||||
struct _MMSimHuaweiClass {
|
||||
MMBaseSimClass parent;
|
||||
};
|
||||
|
||||
GType mm_sim_huawei_get_type (void);
|
||||
|
||||
void mm_sim_huawei_new (MMBaseModem *modem,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
MMBaseSim *mm_sim_huawei_new_finish (GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_SIM_HUAWEI_H */
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user