cinterion: use AT^SCFG=? to parse supported bands in 3G devices
This commit is contained in:
@@ -156,6 +156,7 @@ uml290/uml290mode
|
||||
plugins/test-suite.log
|
||||
plugins/test-modem-helpers-huawei*
|
||||
plugins/test-modem-helpers-altair*
|
||||
plugins/test-modem-helpers-cinterion*
|
||||
plugins/test-service-*
|
||||
|
||||
TAGS
|
||||
|
||||
@@ -360,11 +360,26 @@ libmm_plugin_samsung_la_LIBADD = $(ICERA_COMMON_LIBADD_FLAGS)
|
||||
libmm_plugin_cinterion_la_SOURCES = \
|
||||
cinterion/mm-plugin-cinterion.c \
|
||||
cinterion/mm-plugin-cinterion.h \
|
||||
cinterion/mm-modem-helpers-cinterion.c \
|
||||
cinterion/mm-modem-helpers-cinterion.h \
|
||||
cinterion/mm-broadband-modem-cinterion.c \
|
||||
cinterion/mm-broadband-modem-cinterion.h
|
||||
libmm_plugin_cinterion_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
|
||||
libmm_plugin_cinterion_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
|
||||
|
||||
noinst_PROGRAMS += test-modem-helpers-cinterion
|
||||
test_modem_helpers_cinterion_SOURCES = \
|
||||
cinterion/mm-modem-helpers-cinterion.c \
|
||||
cinterion/mm-modem-helpers-cinterion.h \
|
||||
cinterion/tests/test-modem-helpers-cinterion.c
|
||||
test_modem_helpers_cinterion_CPPFLAGS = \
|
||||
-I$(top_srcdir)/plugins/cinterion \
|
||||
$(PLUGIN_COMMON_COMPILER_FLAGS)
|
||||
test_modem_helpers_cinterion_LDADD = \
|
||||
$(top_builddir)/libmm-glib/libmm-glib.la \
|
||||
$(top_builddir)/src/libmodem-helpers.la
|
||||
test_modem_helpers_cinterion_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
|
||||
|
||||
# Iridium modem
|
||||
libmm_plugin_iridium_la_SOURCES = \
|
||||
iridium/mm-plugin-iridium.c \
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "mm-iface-modem-messaging.h"
|
||||
#include "mm-base-modem-at.h"
|
||||
#include "mm-broadband-modem-cinterion.h"
|
||||
#include "mm-modem-helpers-cinterion.h"
|
||||
|
||||
static void iface_modem_init (MMIfaceModem *iface);
|
||||
static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface);
|
||||
@@ -927,58 +928,78 @@ register_in_network (MMIfaceModem3gpp *self,
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* SUPPORTED BANDS */
|
||||
/* Supported bands (Modem interface) */
|
||||
|
||||
static GArray *
|
||||
load_supported_bands_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
/* Never fails */
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
||||
return NULL;
|
||||
|
||||
return (GArray *) g_array_ref (g_simple_async_result_get_op_res_gpointer (
|
||||
G_SIMPLE_ASYNC_RESULT (res)));
|
||||
}
|
||||
|
||||
static void
|
||||
scfg_3g_test_ready (MMBaseModem *self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *simple)
|
||||
{
|
||||
const gchar *response;
|
||||
GError *error = NULL;
|
||||
GArray *bands;
|
||||
|
||||
response = mm_base_modem_at_command_finish (self, res, &error);
|
||||
if (!response)
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
else if (!mm_cinterion_parse_scfg_3g_test (response, &bands, &error))
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
else
|
||||
g_simple_async_result_set_op_res_gpointer (simple, bands, (GDestroyNotify)g_array_unref);
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
}
|
||||
|
||||
static void
|
||||
load_supported_bands (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *result;
|
||||
GArray *bands;
|
||||
GSimpleAsyncResult *simple;
|
||||
|
||||
result = g_simple_async_result_new (G_OBJECT (self),
|
||||
simple = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
load_supported_bands);
|
||||
|
||||
/* We do assume that we already know if the modem is 2G-only, 3G-only or
|
||||
* 2G+3G. This is checked quite before trying to load supported bands. */
|
||||
if (mm_iface_modem_is_2g_only (self)) {
|
||||
GArray *bands;
|
||||
MMModemBand single;
|
||||
|
||||
#define _g_array_insert_enum(array,index,type,val) do { \
|
||||
type aux = (type)val; \
|
||||
g_array_insert_val (array, index, aux); \
|
||||
} while (0)
|
||||
bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 4);
|
||||
single = MM_MODEM_BAND_EGSM, g_array_append_val (bands, single);
|
||||
single = MM_MODEM_BAND_DCS, g_array_append_val (bands, single);
|
||||
single = MM_MODEM_BAND_PCS, g_array_append_val (bands, single);
|
||||
single = MM_MODEM_BAND_G850, g_array_append_val (bands, single);
|
||||
|
||||
bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 4);
|
||||
_g_array_insert_enum (bands, 0, MMModemBand, MM_MODEM_BAND_EGSM);
|
||||
_g_array_insert_enum (bands, 1, MMModemBand, MM_MODEM_BAND_DCS);
|
||||
_g_array_insert_enum (bands, 2, MMModemBand, MM_MODEM_BAND_PCS);
|
||||
_g_array_insert_enum (bands, 3, MMModemBand, MM_MODEM_BAND_G850);
|
||||
|
||||
/* Add 3G-specific bands */
|
||||
if (mm_iface_modem_is_3g (self)) {
|
||||
g_array_set_size (bands, 7);
|
||||
_g_array_insert_enum (bands, 4, MMModemBand, MM_MODEM_BAND_U2100);
|
||||
_g_array_insert_enum (bands, 5, MMModemBand, MM_MODEM_BAND_U1900);
|
||||
_g_array_insert_enum (bands, 6, MMModemBand, MM_MODEM_BAND_U850);
|
||||
g_simple_async_result_set_op_res_gpointer (simple, bands, (GDestroyNotify)g_array_unref);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
return;
|
||||
}
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (result,
|
||||
bands,
|
||||
(GDestroyNotify)g_array_unref);
|
||||
g_simple_async_result_complete_in_idle (result);
|
||||
g_object_unref (result);
|
||||
/* 2G+3G device, query AT^SCFG */
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||
"AT^SCFG=?",
|
||||
3,
|
||||
FALSE,
|
||||
(GAsyncReadyCallback)scfg_3g_test_ready,
|
||||
simple);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/* -*- 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) 2014 Aleksander Morgado <aleksander@aleksander.es>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ModemManager.h"
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-modem-helpers-cinterion.h"
|
||||
|
||||
/* Setup relationship between the 3G band bitmask in the modem and the bitmask
|
||||
* in ModemManager. */
|
||||
typedef struct {
|
||||
guint32 cinterion_band_flag;
|
||||
MMModemBand mm_band;
|
||||
} CinterionBand3G;
|
||||
|
||||
/* Table checked in HC25 and PHS8 references. This table includes both 2G and 3G
|
||||
* frequencies. Depending on which one is configured, one access technology or
|
||||
* the other will be used. This may conflict with the allowed mode configuration
|
||||
* set, so you shouldn't for example set 3G frequency bands, and then use a
|
||||
* 2G-only allowed mode. */
|
||||
static const CinterionBand3G bands_3g[] = {
|
||||
{ (1 << 0), MM_MODEM_BAND_EGSM },
|
||||
{ (1 << 1), MM_MODEM_BAND_DCS },
|
||||
{ (1 << 2), MM_MODEM_BAND_PCS },
|
||||
{ (1 << 3), MM_MODEM_BAND_G850 },
|
||||
{ (1 << 4), MM_MODEM_BAND_U2100 },
|
||||
{ (1 << 5), MM_MODEM_BAND_U1900 },
|
||||
{ (1 << 6), MM_MODEM_BAND_U850 },
|
||||
{ (1 << 7), MM_MODEM_BAND_U900 },
|
||||
{ (1 << 8), MM_MODEM_BAND_U800 }
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SCFG (3G) test parser
|
||||
*
|
||||
* Example:
|
||||
* AT^SCFG=?
|
||||
* ...
|
||||
* ^SCFG: "MEShutdown/OnIgnition",("on","off")
|
||||
* ^SCFG: "Radio/Band",("1-511","0-1")
|
||||
* ^SCFG: "Radio/NWSM",("0","1","2")
|
||||
* ...
|
||||
*
|
||||
*/
|
||||
|
||||
gboolean
|
||||
mm_cinterion_parse_scfg_3g_test (const gchar *response,
|
||||
GArray **supported_bands,
|
||||
GError **error)
|
||||
{
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
GError *inner_error = NULL;
|
||||
GArray *bands = NULL;
|
||||
|
||||
if (!response) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Missing response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r = g_regex_new ("\\^SCFG:\\s*\"Radio/Band\",\\(\"(\\d+)-(\\d+)\",.*\\)",
|
||||
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
|
||||
0, NULL);
|
||||
g_assert (r != NULL);
|
||||
|
||||
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
|
||||
if (!inner_error && g_match_info_matches (match_info)) {
|
||||
guint maxband;
|
||||
|
||||
if (!mm_get_uint_from_match_info (match_info, 2, &maxband)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse ^SCFG=? response");
|
||||
} else {
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (bands_3g); i++) {
|
||||
if (maxband & bands_3g[i].cinterion_band_flag) {
|
||||
if (G_UNLIKELY (!bands))
|
||||
bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 9);
|
||||
g_array_append_val (bands, bands_3g[i].mm_band);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match_info)
|
||||
g_match_info_free (match_info);
|
||||
g_regex_unref (r);
|
||||
|
||||
if (!bands)
|
||||
inner_error = g_error_new (MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"No valid bands found in ^SCFG=? response");
|
||||
|
||||
if (inner_error) {
|
||||
g_propagate_error (error, inner_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_assert (bands != NULL && bands->len > 0);
|
||||
*supported_bands = bands;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* -*- 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) 2014 Aleksander Morgado <aleksander@aleksander.es>
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_HELPERS_CINTERION_H
|
||||
#define MM_MODEM_HELPERS_CINTERION_H
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SCFG test parser */
|
||||
|
||||
gboolean mm_cinterion_parse_scfg_3g_test (const gchar *response,
|
||||
GArray **supported_bands,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_MODEM_HELPERS_CINTERION_H */
|
||||
@@ -0,0 +1,149 @@
|
||||
/* -*- 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) 2014 Aleksander Morgado <aleksander@aleksander.es>
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include <ModemManager.h>
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include "mm-log.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-modem-helpers-cinterion.h"
|
||||
|
||||
static gint
|
||||
sort_band (MMModemBand a, MMModemBand b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Test ^SCFG test responses */
|
||||
|
||||
static void
|
||||
common_test_scfg (const gchar *response,
|
||||
GArray *expected_bands)
|
||||
{
|
||||
GArray *bands = NULL;
|
||||
gchar *expected_bands_str;
|
||||
gchar *bands_str;
|
||||
GError *error = NULL;
|
||||
gboolean res;
|
||||
|
||||
res = mm_cinterion_parse_scfg_3g_test (response, &bands, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (res == TRUE);
|
||||
g_assert (bands != NULL);
|
||||
|
||||
g_array_sort (bands, (GCompareFunc)sort_band);
|
||||
g_array_sort (expected_bands, (GCompareFunc)sort_band);
|
||||
|
||||
expected_bands_str = mm_common_build_bands_string ((const MMModemBand *)expected_bands->data,
|
||||
expected_bands->len);
|
||||
bands_str = mm_common_build_bands_string ((const MMModemBand *)bands->data,
|
||||
bands->len);
|
||||
|
||||
/* Instead of comparing the array one by one, compare the strings built from the mask
|
||||
* (we get a nicer error if it fails) */
|
||||
g_assert_cmpstr (bands_str, ==, expected_bands_str);
|
||||
|
||||
g_free (bands_str);
|
||||
g_free (expected_bands_str);
|
||||
}
|
||||
|
||||
static void
|
||||
test_scfg (void)
|
||||
{
|
||||
GArray *expected_bands;
|
||||
MMModemBand single;
|
||||
const gchar *response =
|
||||
"^SCFG: \"Audio/Loop\",(\"0\",\"1\")\r\n"
|
||||
"^SCFG: \"Call/ECC\",(\"0\"-\"255\")\r\n"
|
||||
"^SCFG: \"Call/Speech/Codec\",(\"0\",\"1\")\r\n"
|
||||
"^SCFG: \"GPRS/Auth\",(\"0\",\"1\",\"2\")\r\n"
|
||||
"^SCFG: \"GPRS/AutoAttach\",(\"disabled\",\"enabled\")\r\n"
|
||||
"^SCFG: \"GPRS/MaxDataRate/HSDPA\",(\"0\",\"1\")\r\n"
|
||||
"^SCFG: \"GPRS/MaxDataRate/HSUPA\",(\"0\",\"1\")\r\n"
|
||||
"^SCFG: \"Ident/Manufacturer\",(25)\r\n"
|
||||
"^SCFG: \"Ident/Product\",(25)\r\n"
|
||||
"^SCFG: \"MEopMode/Airplane\",(\"off\",\"on\")\r\n"
|
||||
"^SCFG: \"MEopMode/CregRoam\",(\"0\",\"1\")\r\n"
|
||||
"^SCFG: \"MEopMode/CFUN\",(\"0\",\"1\")\r\n"
|
||||
"^SCFG: \"MEopMode/PowerMgmt/LCI\",(\"disabled\",\"enabled\")\r\n"
|
||||
"^SCFG: \"MEopMode/PowerMgmt/VExt\",(\"high\",\"low\")\r\n"
|
||||
"^SCFG: \"MEopMode/PwrSave\",(\"disabled\",\"enabled\"),(\"0-600\"),(\"1-36000\")\r\n"
|
||||
"^SCFG: \"MEopMode/RingOnData\",(\"on\",\"off\")\r\n"
|
||||
"^SCFG: \"MEopMode/RingUrcOnCall\",(\"on\",\"off\")\r\n"
|
||||
"^SCFG: \"MEShutdown/OnIgnition\",(\"on\",\"off\")\r\n"
|
||||
"^SCFG: \"Radio/Band\",(\"1-511\",\"0-1\")\r\n"
|
||||
"^SCFG: \"Radio/NWSM\",(\"0\",\"1\",\"2\")\r\n"
|
||||
"^SCFG: \"Radio/OutputPowerReduction\",(\"4\"-\"8\")\r\n"
|
||||
"^SCFG: \"Serial/USB/DDD\",(\"0\",\"1\"),(\"0\"),(4),(4),(4),(63),(63),(4)\r\n"
|
||||
"^SCFG: \"URC/DstIfc\",(\"mdm\",\"app\")\r\n"
|
||||
"^SCFG: \"URC/Datamode/Ringline\",(\"off\",\"on\")\r\n"
|
||||
"^SCFG: \"URC/Ringline\",(\"off\",\"local\",\"asc0\",\"wakeup\")\r\n"
|
||||
"^SCFG: \"URC/Ringline/ActiveTime\",(\"0\",\"1\",\"2\",\"keep\")\r\n";
|
||||
|
||||
expected_bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 9);
|
||||
single = MM_MODEM_BAND_EGSM, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_DCS, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_PCS, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_G850, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_U2100, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_U1900, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_U850, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_U900, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_U800, g_array_append_val (expected_bands, single);
|
||||
|
||||
common_test_scfg (response, expected_bands);
|
||||
|
||||
g_array_unref (expected_bands);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
_mm_log (const char *loc,
|
||||
const char *func,
|
||||
guint32 level,
|
||||
const char *fmt,
|
||||
...)
|
||||
{
|
||||
#if defined ENABLE_TEST_MESSAGE_TRACES
|
||||
/* Dummy log function */
|
||||
va_list args;
|
||||
gchar *msg;
|
||||
|
||||
va_start (args, fmt);
|
||||
msg = g_strdup_vprintf (fmt, args);
|
||||
va_end (args);
|
||||
g_print ("%s\n", msg);
|
||||
g_free (msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
g_type_init ();
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/MM/cinterion/scfg", test_scfg);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
Reference in New Issue
Block a user