cinterion: consolidate supported bands loading for 2G and 3G devices
This commit is contained in:
@@ -924,9 +924,9 @@ load_supported_bands_finish (MMIfaceModem *self,
|
||||
}
|
||||
|
||||
static void
|
||||
scfg_3g_test_ready (MMBaseModem *_self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *simple)
|
||||
scfg_test_ready (MMBaseModem *_self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *simple)
|
||||
{
|
||||
MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self);
|
||||
const gchar *response;
|
||||
@@ -936,7 +936,10 @@ scfg_3g_test_ready (MMBaseModem *_self,
|
||||
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))
|
||||
else if (!mm_cinterion_parse_scfg_test (response,
|
||||
mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (self)),
|
||||
&bands,
|
||||
&error))
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
else {
|
||||
mm_cinterion_build_band (bands, 0, &self->priv->supported_bands, NULL);
|
||||
@@ -960,30 +963,11 @@ load_supported_bands (MMIfaceModem *self,
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* 2G+3G device, query AT^SCFG */
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||
"AT^SCFG=?",
|
||||
3,
|
||||
FALSE,
|
||||
(GAsyncReadyCallback)scfg_3g_test_ready,
|
||||
(GAsyncReadyCallback)scfg_test_ready,
|
||||
simple);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "ModemManager.h"
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
#include "mm-charsets.h"
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-modem-helpers-cinterion.h"
|
||||
|
||||
@@ -28,14 +29,14 @@
|
||||
typedef struct {
|
||||
guint32 cinterion_band_flag;
|
||||
MMModemBand mm_band;
|
||||
} CinterionBand3G;
|
||||
} CinterionBand;
|
||||
|
||||
/* 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[] = {
|
||||
static const CinterionBand cinterion_bands[] = {
|
||||
{ (1 << 0), MM_MODEM_BAND_EGSM },
|
||||
{ (1 << 1), MM_MODEM_BAND_DCS },
|
||||
{ (1 << 2), MM_MODEM_BAND_PCS },
|
||||
@@ -61,9 +62,10 @@ static const CinterionBand3G bands_3g[] = {
|
||||
*/
|
||||
|
||||
gboolean
|
||||
mm_cinterion_parse_scfg_3g_test (const gchar *response,
|
||||
GArray **supported_bands,
|
||||
GError **error)
|
||||
mm_cinterion_parse_scfg_test (const gchar *response,
|
||||
MMModemCharset charset,
|
||||
GArray **supported_bands,
|
||||
GError **error)
|
||||
{
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
@@ -75,27 +77,37 @@ mm_cinterion_parse_scfg_3g_test (const gchar *response,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r = g_regex_new ("\\^SCFG:\\s*\"Radio/Band\",\\(\"(\\d+)-(\\d+)\",.*\\)",
|
||||
r = g_regex_new ("\\^SCFG:\\s*\"Radio/Band\",\\(\"([0-9a-fA-F]*)-([0-9a-fA-F]*)\",.*\\)",
|
||||
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;
|
||||
gchar *maxbandstr;
|
||||
guint maxband = 0;
|
||||
|
||||
if (!mm_get_uint_from_match_info (match_info, 2, &maxband)) {
|
||||
maxbandstr = mm_get_string_unquoted_from_match_info (match_info, 2);
|
||||
if (maxbandstr) {
|
||||
/* Handle charset conversion if the number is given in UCS2 */
|
||||
if (charset != MM_MODEM_CHARSET_UNKNOWN)
|
||||
maxbandstr = mm_charset_take_and_convert_to_utf8 (maxbandstr, charset);
|
||||
|
||||
mm_get_uint_from_str (maxbandstr, &maxband);
|
||||
}
|
||||
|
||||
if (maxband == 0) {
|
||||
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) {
|
||||
for (i = 0; i < G_N_ELEMENTS (cinterion_bands); i++) {
|
||||
if (maxband & cinterion_bands[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);
|
||||
g_array_append_val (bands, cinterion_bands[i].mm_band);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,11 +171,11 @@ mm_cinterion_parse_scfg_3g_response (const gchar *response,
|
||||
|
||||
current_int = (guint32) atoi (current);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (bands_3g); i++) {
|
||||
if (current_int & bands_3g[i].cinterion_band_flag) {
|
||||
for (i = 0; i < G_N_ELEMENTS (cinterion_bands); i++) {
|
||||
if (current_int & cinterion_bands[i].cinterion_band_flag) {
|
||||
if (G_UNLIKELY (!bands))
|
||||
bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 4);
|
||||
g_array_append_val (bands, bands_3g[i].mm_band);
|
||||
g_array_append_val (bands, cinterion_bands[i].mm_band);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,12 +220,12 @@ mm_cinterion_build_band (GArray *bands,
|
||||
} else {
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (bands_3g); i++) {
|
||||
for (i = 0; i < G_N_ELEMENTS (cinterion_bands); i++) {
|
||||
guint j;
|
||||
|
||||
for (j = 0; j < bands->len; j++) {
|
||||
if (g_array_index (bands, MMModemBand, j) == bands_3g[i].mm_band) {
|
||||
band |= bands_3g[i].cinterion_band_flag;
|
||||
if (g_array_index (bands, MMModemBand, j) == cinterion_bands[i].mm_band) {
|
||||
band |= cinterion_bands[i].cinterion_band_flag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
/*****************************************************************************/
|
||||
/* ^SCFG test parser */
|
||||
|
||||
gboolean mm_cinterion_parse_scfg_3g_test (const gchar *response,
|
||||
GArray **supported_bands,
|
||||
GError **error);
|
||||
gboolean mm_cinterion_parse_scfg_test (const gchar *response,
|
||||
MMModemCharset charset,
|
||||
GArray **supported_bands,
|
||||
GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SCFG response parser */
|
||||
|
||||
@@ -44,7 +44,10 @@ common_test_scfg (const gchar *response,
|
||||
GError *error = NULL;
|
||||
gboolean res;
|
||||
|
||||
res = mm_cinterion_parse_scfg_3g_test (response, &bands, &error);
|
||||
res = mm_cinterion_parse_scfg_test (response,
|
||||
MM_MODEM_CHARSET_UNKNOWN,
|
||||
&bands,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (res == TRUE);
|
||||
g_assert (bands != NULL);
|
||||
|
||||
Reference in New Issue
Block a user