plugin,mtk: Add load_unlock_retries
This patch add load_unlock_retries support by AT in mtk-based Fibocom modem.
This commit is contained in:
committed by
Aleksander Morgado
parent
7312c86130
commit
388e8ea538
+3
-2
@@ -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']},
|
||||
|
||||
+21
-3
@@ -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
|
||||
|
||||
|
||||
@@ -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 *
|
||||
@@ -292,6 +298,11 @@ shared_fibocom_init (MMSharedFibocomInterface *iface)
|
||||
iface->peek_parent_class = peek_parent_class;
|
||||
}
|
||||
|
||||
static void
|
||||
shared_mtk_init (MMSharedMtkInterface *iface)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_broadband_modem_mbim_mtk_fibocom_class_init (MMBroadbandModemMbimMtkFibocomClass *klass)
|
||||
{
|
||||
|
||||
@@ -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 */
|
||||
@@ -51,91 +54,6 @@ struct _MMBroadbandModemMtkLegacyPrivate {
|
||||
GRegex *ecsqel_regex;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 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,
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
@@ -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 */
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user