fibocom: Add bearer for ECM-based connections

This commit is contained in:
Sven Schwermer
2022-01-04 16:14:18 +01:00
committed by Aleksander Morgado
parent 6ad17fb22e
commit c21bcb5526
6 changed files with 371 additions and 2 deletions

View File

@@ -690,6 +690,8 @@ if ENABLE_PLUGIN_FIBOCOM
pkglib_LTLIBRARIES += libmm-plugin-fibocom.la
libmm_plugin_fibocom_la_SOURCES = \
fibocom/mm-broadband-bearer-fibocom-ecm.c \
fibocom/mm-broadband-bearer-fibocom-ecm.h \
fibocom/mm-broadband-modem-fibocom.c \
fibocom/mm-broadband-modem-fibocom.h \
fibocom/mm-plugin-fibocom.c \

View File

@@ -0,0 +1,240 @@
/* -*- 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) 2022 Disruptive Technologies Research AS
*/
#include <config.h>
#include "mm-broadband-bearer-fibocom-ecm.h"
#include "mm-broadband-modem-fibocom.h"
#include "mm-base-modem-at.h"
#include "mm-iface-modem-3gpp.h"
G_DEFINE_TYPE (MMBroadbandBearerFibocomEcm, mm_broadband_bearer_fibocom_ecm, MM_TYPE_BROADBAND_BEARER)
/*****************************************************************************/
/* Dial context and task */
typedef struct {
MMBroadbandModem *modem;
MMPortSerialAt *primary;
guint cid;
MMPort *data;
} DialContext;
static void
dial_task_free (DialContext *ctx)
{
g_object_unref (ctx->modem);
g_object_unref (ctx->primary);
if (ctx->data)
g_object_unref (ctx->data);
g_slice_free (DialContext, ctx);
}
static GTask *
dial_task_new (MMBroadbandBearerFibocomEcm *self,
MMBroadbandModem *modem,
MMPortSerialAt *primary,
guint cid,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
DialContext *ctx;
GTask *task;
ctx = g_slice_new0 (DialContext);
ctx->modem = g_object_ref (modem);
ctx->primary = g_object_ref (primary);
ctx->cid = cid;
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_task_data (task, ctx, (GDestroyNotify) dial_task_free);
ctx->data = mm_base_modem_get_best_data_port (MM_BASE_MODEM (modem), MM_PORT_TYPE_NET);
if (!ctx->data) {
g_task_return_new_error (task,
MM_CORE_ERROR,
MM_CORE_ERROR_NOT_FOUND,
"No valid data port found to launch connection");
g_object_unref (task);
return NULL;
}
return task;
}
/*****************************************************************************/
/* 3GPP Dialing (sub-step of the 3GPP Connection sequence) */
static MMPort *
dial_3gpp_finish (MMBroadbandBearer *self,
GAsyncResult *res,
GError **error)
{
return g_task_propagate_pointer (G_TASK (res), error);
}
static void
gtrndis_activate_ready (MMBaseModem *modem,
GAsyncResult *res,
GTask *task)
{
DialContext *ctx;
GError *error = NULL;
ctx = g_task_get_task_data (task);
if (!mm_base_modem_at_command_finish (modem, res, &error))
g_task_return_error (task, error);
else
g_task_return_pointer (task, g_object_ref (ctx->data), g_object_unref);
g_object_unref (task);
}
static void
dial_3gpp (MMBroadbandBearer *self,
MMBaseModem *modem,
MMPortSerialAt *primary,
guint cid,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
g_autofree gchar *cmd = NULL;
task = dial_task_new (MM_BROADBAND_BEARER_FIBOCOM_ECM (self),
MM_BROADBAND_MODEM (modem),
primary,
cid,
cancellable,
callback,
user_data);
if (!task)
return;
cmd = g_strdup_printf ("+GTRNDIS=1,%u", cid);
mm_base_modem_at_command (modem,
cmd,
MM_BASE_BEARER_DEFAULT_CONNECTION_TIMEOUT,
FALSE, /* allow_cached */
(GAsyncReadyCallback) gtrndis_activate_ready,
task);
}
/*****************************************************************************/
/* 3GPP Disconnect sequence */
static gboolean
disconnect_3gpp_finish (MMBroadbandBearer *self,
GAsyncResult *res,
GError **error)
{
return g_task_propagate_boolean (G_TASK (res), error);
}
static void
gtrndis_deactivate_ready (MMBaseModem *modem,
GAsyncResult *res,
GTask *task)
{
GError *error = NULL;
if (!mm_base_modem_at_command_finish (modem, res, &error))
g_task_return_error (task, error);
else
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
static void
disconnect_3gpp (MMBroadbandBearer *self,
MMBroadbandModem *modem,
MMPortSerialAt *primary,
MMPortSerialAt *secondary,
MMPort *data,
guint cid,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
g_autofree gchar *cmd = NULL;
task = g_task_new (self, NULL, callback, user_data);
cmd = g_strdup_printf ("+GTRNDIS=0,%u", cid);
mm_base_modem_at_command (MM_BASE_MODEM (modem),
cmd,
MM_BASE_BEARER_DEFAULT_DISCONNECTION_TIMEOUT,
FALSE, /* allow_cached */
(GAsyncReadyCallback) gtrndis_deactivate_ready,
task);
}
/*****************************************************************************/
MMBaseBearer *
mm_broadband_bearer_fibocom_ecm_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_fibocom_ecm_new (MMBroadbandModemFibocom *modem,
MMBearerProperties *config,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_async_initable_new_async (
MM_TYPE_BROADBAND_BEARER_FIBOCOM_ECM,
G_PRIORITY_DEFAULT,
cancellable,
callback,
user_data,
MM_BASE_BEARER_MODEM, modem,
MM_BASE_BEARER_CONFIG, config,
NULL);
}
static void
mm_broadband_bearer_fibocom_ecm_init (MMBroadbandBearerFibocomEcm *self)
{
}
static void
mm_broadband_bearer_fibocom_ecm_class_init (MMBroadbandBearerFibocomEcmClass *klass)
{
MMBroadbandBearerClass *broadband_bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
broadband_bearer_class->dial_3gpp = dial_3gpp;
broadband_bearer_class->dial_3gpp_finish = dial_3gpp_finish;
broadband_bearer_class->disconnect_3gpp = disconnect_3gpp;
broadband_bearer_class->disconnect_3gpp_finish = disconnect_3gpp_finish;
}

View File

@@ -0,0 +1,50 @@
/* -*- 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) 2022 Disruptive Technologies Research AS
*/
#ifndef MM_BROADBAND_BEARER_FIBOCOM_ECM_H
#define MM_BROADBAND_BEARER_FIBOCOM_ECM_H
#include "mm-broadband-bearer.h"
#include "mm-broadband-modem-fibocom.h"
#define MM_TYPE_BROADBAND_BEARER_FIBOCOM_ECM (mm_broadband_bearer_fibocom_ecm_get_type ())
#define MM_BROADBAND_BEARER_FIBOCOM_ECM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BROADBAND_BEARER_FIBOCOM_ECM, MMBroadbandBearerFibocomEcm))
#define MM_BROADBAND_BEARER_FIBOCOM_ECM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BROADBAND_BEARER_FIBOCOM_ECM, MMBroadbandBearerFibocomEcmClass))
#define MM_IS_BROADBAND_BEARER_FIBOCOM_ECM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BROADBAND_BEARER_FIBOCOM_ECM))
#define MM_IS_BROADBAND_BEARER_FIBOCOM_ECM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_BEARER_FIBOCOM_ECM))
#define MM_BROADBAND_BEARER_FIBOCOM_ECM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_BEARER_FIBOCOM_ECM, MMBroadbandBearerFibocomEcmClass))
typedef struct _MMBroadbandBearerFibocomEcm MMBroadbandBearerFibocomEcm;
typedef struct _MMBroadbandBearerFibocomEcmClass MMBroadbandBearerFibocomEcmClass;
struct _MMBroadbandBearerFibocomEcm {
MMBroadbandBearer parent;
};
struct _MMBroadbandBearerFibocomEcmClass {
MMBroadbandBearerClass parent;
};
GType mm_broadband_bearer_fibocom_ecm_get_type (void);
void mm_broadband_bearer_fibocom_ecm_new (MMBroadbandModemFibocom *modem,
MMBearerProperties *properties,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
MMBaseBearer *mm_broadband_bearer_fibocom_ecm_new_finish (GAsyncResult *res,
GError **error);
#endif /* MM_BROADBAND_BEARER_FIBOCOM_ECM_H */

View File

@@ -16,14 +16,88 @@
#include <config.h>
#include "mm-broadband-modem-fibocom.h"
#include "mm-broadband-bearer-fibocom-ecm.h"
#include "mm-broadband-modem.h"
#include "mm-iface-modem.h"
#include "mm-log.h"
static void iface_modem_init (MMIfaceModem *iface);
G_DEFINE_TYPE_EXTENDED (MMBroadbandModemFibocom, mm_broadband_modem_fibocom, MM_TYPE_BROADBAND_MODEM, 0,
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init))
/*****************************************************************************/
/* Create Bearer (Modem interface) */
static MMBaseBearer *
modem_create_bearer_finish (MMIfaceModem *self,
GAsyncResult *res,
GError **error)
{
return g_task_propagate_pointer (G_TASK (res), error);
}
static void
broadband_bearer_fibocom_ecm_new_ready (GObject *source,
GAsyncResult *res,
GTask *task)
{
MMBaseBearer *bearer = NULL;
GError *error = NULL;
bearer = mm_broadband_bearer_fibocom_ecm_new_finish (res, &error);
if (!bearer)
g_task_return_error (task, error);
else
g_task_return_pointer (task, bearer, g_object_unref);
g_object_unref (task);
}
static void
broadband_bearer_new_ready (GObject *source,
GAsyncResult *res,
GTask *task)
{
MMBaseBearer *bearer = NULL;
GError *error = NULL;
bearer = mm_broadband_bearer_new_finish (res, &error);
if (!bearer)
g_task_return_error (task, error);
else
g_task_return_pointer (task, bearer, g_object_unref);
g_object_unref (task);
}
static void
modem_create_bearer (MMIfaceModem *self,
MMBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
task = g_task_new (self, NULL, callback, user_data);
/* If we get a NET port, create Fibocom ECM bearer */
if (mm_base_modem_peek_best_data_port (MM_BASE_MODEM (self), MM_PORT_TYPE_NET)) {
mm_obj_dbg (self, "Creating Fibocom ECM bearer");
mm_broadband_bearer_fibocom_ecm_new (MM_BROADBAND_MODEM_FIBOCOM (self),
properties,
NULL, /* cancellable */
(GAsyncReadyCallback) broadband_bearer_fibocom_ecm_new_ready,
task);
} else {
/* Otherwise, use generic broadband bearer for PPP */
mm_obj_dbg (self, "Creating generic PPP bearer");
mm_broadband_bearer_new (MM_BROADBAND_MODEM (self),
properties,
NULL, /* cancellable */
(GAsyncReadyCallback) broadband_bearer_new_ready,
task);
}
}
/*****************************************************************************/
MMBroadbandModemFibocom *
@@ -39,7 +113,7 @@ mm_broadband_modem_fibocom_new (const gchar *device,
MM_BASE_MODEM_PLUGIN, plugin,
MM_BASE_MODEM_VENDOR_ID, vendor_id,
MM_BASE_MODEM_PRODUCT_ID, product_id,
MM_BASE_MODEM_DATA_NET_SUPPORTED, FALSE,
MM_BASE_MODEM_DATA_NET_SUPPORTED, TRUE,
MM_BASE_MODEM_DATA_TTY_SUPPORTED, TRUE,
NULL);
}
@@ -52,6 +126,8 @@ mm_broadband_modem_fibocom_init (MMBroadbandModemFibocom *self)
static void
iface_modem_init (MMIfaceModem *iface)
{
iface->create_bearer = modem_create_bearer;
iface->create_bearer_finish = modem_create_bearer_finish;
}
static void

View File

@@ -104,7 +104,7 @@ mm_plugin_create (void)
{
static const gchar *subsystems[] = { "tty", "net", "usbmisc", NULL };
static const guint16 vendor_ids[] = { 0x2cb7, 0 };
static const gchar *drivers[] = { "cdc_mbim", "qmi_wwan", NULL };
static const gchar *drivers[] = { "cdc_mbim", "qmi_wwan", "cdc_ether", NULL };
return MM_PLUGIN (
g_object_new (MM_TYPE_PLUGIN_FIBOCOM,

View File

@@ -338,6 +338,7 @@ if plugins_options['fibocom']
]
sources = files(
'fibocom/mm-broadband-bearer-fibocom-ecm.c',
'fibocom/mm-broadband-modem-fibocom.c',
'fibocom/mm-plugin-fibocom.c',
)