1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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;
}
|