aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build5
-rw-r--r--src/plugins/meson.build24
-rw-r--r--src/plugins/mtk/mm-broadband-modem-mbim-mtk-fibocom.c13
-rw-r--r--src/plugins/mtk/mm-broadband-modem-mtk-legacy.c99
-rw-r--r--src/plugins/mtk/mm-shared-mtk.c127
-rw-r--r--src/plugins/mtk/mm-shared-mtk.h45
-rw-r--r--src/plugins/mtk/mm-shared.c18
7 files changed, 237 insertions, 94 deletions
diff --git a/meson.build b/meson.build
index 5a5028d5..f69298b3 100644
--- a/meson.build
+++ b/meson.build
@@ -306,6 +306,7 @@ plugins_shared_reqs = {
'fibocom': true,
'foxconn': enable_mbim,
'icera': true,
+ 'mtk': true,
'novatel': true,
'option': true,
'sierra': true,
@@ -314,7 +315,7 @@ plugins_shared_reqs = {
}
dell_shared_reqs = ['novatel', 'sierra', 'telit', 'xmm']
-mtk_shared_reqs = []
+mtk_shared_reqs = ['mtk']
if enable_mbim
dell_shared_reqs += ['foxconn']
# only the MBIM implementation in MTK needs the shared fibocom utils
@@ -340,7 +341,7 @@ plugins_options_reqs = {
'longcheer': {'available': true, 'shared': []},
'mbm': {'available': true, 'shared': []},
'motorola': {'available': true, 'shared': []},
- 'mtk-legacy': {'available': true, 'shared': []},
+ 'mtk-legacy': {'available': true, 'shared': mtk_shared_reqs},
'mtk': {'available': true, 'shared': mtk_shared_reqs},
'nokia': {'available': true, 'shared': []},
'nokia-icera': {'available': true, 'shared': ['icera']},
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index d7f78a4a..4f4d253b 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -132,6 +132,23 @@ if plugins_shared['icera']
}}
endif
+# common mtk support library
+if plugins_shared['mtk']
+ mtk_inc = include_directories('mtk')
+
+ c_args = '-DMM_MODULE_NAME="shared-mtk"'
+
+ sources = files(
+ 'mtk/mm-shared.c',
+ 'mtk/mm-shared-mtk.c',
+ )
+
+ plugins += {'shared-mtk': {
+ 'plugin': false,
+ 'module': {'sources': sources, 'include_directories': plugins_incs, 'c_args': c_args},
+ }}
+endif
+
# common novatel support
if plugins_shared['novatel']
novatel_inc = include_directories('novatel')
@@ -630,6 +647,7 @@ if plugins_options['mtk-legacy']
test_udev_rules_dir_c_args = ['-DTESTUDEVRULESDIR_MTK="@0@"'.format(plugins_dir / 'mtk')]
plugins_test_udev_rules_dir_c_args += test_udev_rules_dir_c_args
+ incs = plugins_incs + [mtk_inc]
sources = files(
'mtk/mm-broadband-modem-mtk-legacy.c',
'mtk/mm-plugin-mtk-legacy.c',
@@ -637,7 +655,7 @@ if plugins_options['mtk-legacy']
plugins += {'plugin-mtk-legacy': {
'plugin': true,
- 'module': {'sources': sources, 'include_directories': plugins_incs, 'c_args': test_udev_rules_dir_c_args + ['-DMM_MODULE_NAME="mtk-legacy"']},
+ 'module': {'sources': sources, 'include_directories': incs, 'c_args': test_udev_rules_dir_c_args + ['-DMM_MODULE_NAME="mtk-legacy"']},
}}
plugins_udev_rules += files('mtk/77-mm-mtk-legacy-port-types.rules')
@@ -648,7 +666,7 @@ if plugins_options['mtk']
test_udev_rules_dir_c_args = ['-DTESTUDEVRULESDIR_MTK="@0@"'.format(plugins_dir / 'mtk')]
plugins_test_udev_rules_dir_c_args += test_udev_rules_dir_c_args
- incs = plugins_incs
+ incs = plugins_incs + [mtk_inc]
sources = files(
'mtk/mm-plugin-mtk.c',
)
@@ -658,7 +676,7 @@ if plugins_options['mtk']
sources += files(
'mtk/mm-bearer-mbim-mtk-fibocom.c',
'mtk/mm-broadband-modem-mbim-mtk.c',
- 'mtk/mm-broadband-modem-mbim-mtk-fibocom.c'
+ 'mtk/mm-broadband-modem-mbim-mtk-fibocom.c',
)
endif
diff --git a/src/plugins/mtk/mm-broadband-modem-mbim-mtk-fibocom.c b/src/plugins/mtk/mm-broadband-modem-mbim-mtk-fibocom.c
index 650e14c7..a2c90899 100644
--- a/src/plugins/mtk/mm-broadband-modem-mbim-mtk-fibocom.c
+++ b/src/plugins/mtk/mm-broadband-modem-mbim-mtk-fibocom.c
@@ -27,15 +27,18 @@
#include "mm-bearer-mbim-mtk-fibocom.h"
#include "mm-broadband-modem-mbim-mtk-fibocom.h"
#include "mm-shared-fibocom.h"
+#include "mm-shared-mtk.h"
static void iface_modem_init (MMIfaceModemInterface *iface);
static void shared_fibocom_init (MMSharedFibocomInterface *iface);
+static void shared_mtk_init (MMSharedMtkInterface *iface);
static MMIfaceModemInterface *iface_modem_parent;
G_DEFINE_TYPE_EXTENDED (MMBroadbandModemMbimMtkFibocom, mm_broadband_modem_mbim_mtk_fibocom, MM_TYPE_BROADBAND_MODEM_MBIM_MTK, 0,
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)
- G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_FIBOCOM, shared_fibocom_init))
+ G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_FIBOCOM, shared_fibocom_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_MTK, shared_mtk_init))
struct _MMBroadbandModemMbimMtkFibocomPrivate {
/* Custom MTK/Fibocom bearer behavior */
@@ -278,6 +281,9 @@ iface_modem_init (MMIfaceModemInterface *iface)
iface->create_bearer = create_bearer;
iface->create_bearer_finish = create_bearer_finish;
iface->create_bearer_list = create_bearer_list;
+ iface->load_unlock_retries = mm_shared_mtk_load_unlock_retries;
+ iface->load_unlock_retries_finish = mm_shared_mtk_load_unlock_retries_finish;
+
}
static MMBaseModemClass *
@@ -293,6 +299,11 @@ shared_fibocom_init (MMSharedFibocomInterface *iface)
}
static void
+shared_mtk_init (MMSharedMtkInterface *iface)
+{
+}
+
+static void
mm_broadband_modem_mbim_mtk_fibocom_class_init (MMBroadbandModemMbimMtkFibocomClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
diff --git a/src/plugins/mtk/mm-broadband-modem-mtk-legacy.c b/src/plugins/mtk/mm-broadband-modem-mtk-legacy.c
index 02089a76..36121d0e 100644
--- a/src/plugins/mtk/mm-broadband-modem-mtk-legacy.c
+++ b/src/plugins/mtk/mm-broadband-modem-mtk-legacy.c
@@ -31,16 +31,19 @@
#include "mm-iface-modem.h"
#include "mm-iface-modem-3gpp.h"
#include "mm-broadband-modem-mtk-legacy.h"
+#include "mm-shared-mtk.h"
static void iface_modem_init (MMIfaceModemInterface *iface);
static void iface_modem_3gpp_init (MMIfaceModem3gppInterface *iface);
+static void shared_mtk_init (MMSharedMtkInterface *iface);
static MMIfaceModemInterface *iface_modem_parent;
static MMIfaceModem3gppInterface *iface_modem_3gpp_parent;
G_DEFINE_TYPE_EXTENDED (MMBroadbandModemMtkLegacy, mm_broadband_modem_mtk_legacy, MM_TYPE_BROADBAND_MODEM, 0,
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)
- G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init));
+ G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init)
+ G_IMPLEMENT_INTERFACE (MM_TYPE_SHARED_MTK, shared_mtk_init));
struct _MMBroadbandModemMtkLegacyPrivate {
/* Signal quality regex */
@@ -52,91 +55,6 @@ struct _MMBroadbandModemMtkLegacyPrivate {
};
/*****************************************************************************/
-/* Unlock retries (Modem interface) */
-
-static MMUnlockRetries *
-load_unlock_retries_finish (MMIfaceModem *self,
- GAsyncResult *res,
- GError **error)
-{
- return g_task_propagate_pointer (G_TASK (res), error);
-}
-
-static void
-load_unlock_retries_ready (MMBaseModem *self,
- GAsyncResult *res,
- GTask *task)
-{
- g_autoptr(GMatchInfo) match_info = NULL;
- g_autoptr(GRegex) r = NULL;
- const gchar *response;
- GError *error = NULL;
- GError *match_error = NULL;
- gint pin1;
- gint puk1;
- gint pin2;
- gint puk2;
- MMUnlockRetries *retries;
-
- response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
- if (!response) {
- g_task_return_error (task, error);
- g_object_unref (task);
- return;
- }
-
- r = g_regex_new (
- "\\+EPINC:\\s*([0-9]+),\\s*([0-9]+),\\s*([0-9]+),\\s*([0-9]+)",
- 0,
- 0,
- NULL);
-
- g_assert (r != NULL);
-
- if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &match_error)){
- if (match_error)
- g_task_return_error (task, match_error);
- else
- g_task_return_new_error (task, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
- "Failed to match EPINC response: %s", response);
- g_task_return_error (task, error);
- } else if (!mm_get_int_from_match_info (match_info, 1, &pin1) ||
- !mm_get_int_from_match_info (match_info, 2, &pin2) ||
- !mm_get_int_from_match_info (match_info, 3, &puk1) ||
- !mm_get_int_from_match_info (match_info, 4, &puk2)) {
- g_task_return_new_error (task,
- MM_CORE_ERROR,
- MM_CORE_ERROR_FAILED,
- "Failed to parse the EPINC response: '%s'",
- response);
- } else {
- retries = mm_unlock_retries_new ();
-
- mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PIN, pin1);
- mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PIN2, pin2);
- mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK, puk1);
- mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK2, puk2);
-
- g_task_return_pointer (task, retries, g_object_unref);
- }
- g_object_unref (task);
-}
-
-static void
-load_unlock_retries (MMIfaceModem *self,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- mm_base_modem_at_command (
- MM_BASE_MODEM (self),
- "+EPINC?",
- 3,
- FALSE,
- (GAsyncReadyCallback)load_unlock_retries_ready,
- g_task_new (self, NULL, callback, user_data));
-}
-
-/*****************************************************************************/
static gboolean
modem_after_sim_unlock_finish (MMIfaceModem *self,
GAsyncResult *res,
@@ -925,8 +843,13 @@ iface_modem_init (MMIfaceModemInterface *iface)
iface->load_current_modes_finish = load_current_modes_finish;
iface->set_current_modes = set_current_modes;
iface->set_current_modes_finish = set_current_modes_finish;
- iface->load_unlock_retries = load_unlock_retries;
- iface->load_unlock_retries_finish = load_unlock_retries_finish;
+ iface->load_unlock_retries = mm_shared_mtk_load_unlock_retries;
+ iface->load_unlock_retries_finish = mm_shared_mtk_load_unlock_retries_finish;
+}
+
+static void
+shared_mtk_init (MMSharedMtkInterface *iface)
+{
}
static void
diff --git a/src/plugins/mtk/mm-shared-mtk.c b/src/plugins/mtk/mm-shared-mtk.c
new file mode 100644
index 00000000..1959f781
--- /dev/null
+++ b/src/plugins/mtk/mm-shared-mtk.c
@@ -0,0 +1,127 @@
+/* -*- 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) 2024 Fibocom Wireless Inc.
+ */
+
+#include <config.h>
+#include <arpa/inet.h>
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-log-object.h"
+#include "mm-iface-modem.h"
+#include "mm-shared-mtk.h"
+#include "mm-base-modem-at.h"
+
+G_DEFINE_INTERFACE (MMSharedMtk, mm_shared_mtk, MM_TYPE_IFACE_MODEM)
+
+/*****************************************************************************/
+/* Unlock retries (Modem interface) */
+
+MMUnlockRetries *
+mm_shared_mtk_load_unlock_retries_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error)
+{
+ return g_task_propagate_pointer (G_TASK (res), error);
+}
+
+static MMUnlockRetries *
+epinc_query_response_parse (const gchar *response,
+ GError **error)
+{
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
+ gint pin1;
+ gint puk1;
+ gint pin2;
+ gint puk2;
+ MMUnlockRetries *retries;
+
+ r = g_regex_new ("\\+EPINC:\\s*([0-9]+),\\s*([0-9]+),\\s*([0-9]+),\\s*([0-9]+)", 0, 0, NULL);
+ g_assert (r != NULL);
+
+ if (!g_regex_match_full (r, response, strlen(response), 0, 0, &match_info, error))
+ return NULL;
+
+ if (!mm_get_int_from_match_info (match_info, 1, &pin1) ||
+ !mm_get_int_from_match_info (match_info, 2, &pin2) ||
+ !mm_get_int_from_match_info (match_info, 3, &puk1) ||
+ !mm_get_int_from_match_info (match_info, 4, &puk2)) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Failed to parse the EPINC response: '%s'", response);
+ return NULL;
+ }
+
+ retries = mm_unlock_retries_new();
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PIN, pin1);
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PIN2, pin2);
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK, puk1);
+ mm_unlock_retries_set (retries, MM_MODEM_LOCK_SIM_PUK2, puk2);
+
+ return retries;
+}
+
+static void
+epinc_query_ready (MMBaseModem *self,
+ GAsyncResult *res,
+ GTask *task)
+{
+ const gchar *response;
+ GError *error = NULL;
+ MMUnlockRetries *retries;
+
+ response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
+ if (!response) {
+ g_task_return_error (task, error);
+ g_object_unref (task);
+ return;
+ }
+
+ retries = epinc_query_response_parse (response, &error);
+ if (!retries) {
+ g_task_return_error (task, error);
+ g_object_unref (task);
+ return;
+ }
+
+ g_task_return_pointer (task, retries, g_object_unref);
+ g_object_unref (task);
+}
+
+void
+mm_shared_mtk_load_unlock_retries (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ task = g_task_new (self, NULL, callback, user_data);
+
+ mm_base_modem_at_command (
+ MM_BASE_MODEM (self),
+ "+EPINC?",
+ 3,
+ FALSE,
+ (GAsyncReadyCallback)epinc_query_ready,
+ task);
+}
+
+static void
+mm_shared_mtk_default_init (MMSharedMtkInterface *iface)
+{
+}
diff --git a/src/plugins/mtk/mm-shared-mtk.h b/src/plugins/mtk/mm-shared-mtk.h
new file mode 100644
index 00000000..12b21df7
--- /dev/null
+++ b/src/plugins/mtk/mm-shared-mtk.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details:
+ *
+ * Copyright (C) 2024 Fibocom Wireless Inc.
+ */
+
+#ifndef MM_SHARED_MTK_H
+#define MM_SHARED_MTK_H
+
+#include <config.h>
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-broadband-modem.h"
+#include "mm-iface-modem.h"
+
+#define MM_TYPE_SHARED_MTK mm_shared_mtk_get_type ()
+G_DECLARE_INTERFACE (MMSharedMtk, mm_shared_mtk, MM, SHARED_MTK, MMIfaceModem)
+
+struct _MMSharedMtkInterface {
+ GTypeInterface g_iface;
+};
+
+void mm_shared_mtk_load_unlock_retries (MMIfaceModem *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+MMUnlockRetries *mm_shared_mtk_load_unlock_retries_finish (MMIfaceModem *self,
+ GAsyncResult *res,
+ GError **error);
+
+#endif /* MM_SHARED_MTK_H */ \ No newline at end of file
diff --git a/src/plugins/mtk/mm-shared.c b/src/plugins/mtk/mm-shared.c
new file mode 100644
index 00000000..3cd5aad8
--- /dev/null
+++ b/src/plugins/mtk/mm-shared.c
@@ -0,0 +1,18 @@
+/* -*- 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) 2024 Fibocom Wireless Inc
+ */
+
+#include "mm-shared-common.h"
+
+MM_DEFINE_SHARED (mtk) \ No newline at end of file