cinterion: consolidate current bands loading for 2G and 3G devices
This commit is contained in:
@@ -972,7 +972,7 @@ load_supported_bands (MMIfaceModem *self,
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* CURRENT BANDS */
|
||||
/* Load current bands (Modem interface) */
|
||||
|
||||
static GArray *
|
||||
load_current_bands_finish (MMIfaceModem *self,
|
||||
@@ -987,89 +987,7 @@ load_current_bands_finish (MMIfaceModem *self,
|
||||
}
|
||||
|
||||
static void
|
||||
get_2g_band_ready (MMBroadbandModemCinterion *self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *operation_result)
|
||||
{
|
||||
const gchar *response;
|
||||
GError *error = NULL;
|
||||
GArray *bands_array = NULL;
|
||||
GRegex *regex;
|
||||
GMatchInfo *match_info = NULL;
|
||||
|
||||
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
||||
if (!response) {
|
||||
/* Let the error be critical. */
|
||||
g_simple_async_result_take_error (operation_result, error);
|
||||
g_simple_async_result_complete (operation_result);
|
||||
g_object_unref (operation_result);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The AT^SCFG? command replies a list of several different config
|
||||
* values. We will only look for 'Radio/Band".
|
||||
*
|
||||
* AT+SCFG="Radio/Band"
|
||||
* ^SCFG: "Radio/Band","0031","0031"
|
||||
*
|
||||
* Note that "0031" is a UCS2-encoded string, as we configured UCS2 as
|
||||
* character set to use.
|
||||
*/
|
||||
regex = g_regex_new ("\\^SCFG:\\s*\"Radio/Band\",\\s*\"(.*)\",\\s*\"(.*)\"", 0, 0, NULL);
|
||||
g_assert (regex != NULL);
|
||||
|
||||
if (g_regex_match_full (regex, response, strlen (response), 0, 0, &match_info, NULL)) {
|
||||
gchar *current;
|
||||
|
||||
/* The first number given is the current band configuration, the
|
||||
* second number given is the allowed band configuration, which we
|
||||
* don't really need to get here. */
|
||||
current = g_match_info_fetch (match_info, 1);
|
||||
if (current) {
|
||||
guint i;
|
||||
|
||||
/* If in UCS2, convert to UTF-8 */
|
||||
current = mm_broadband_modem_take_and_convert_to_utf8 (MM_BROADBAND_MODEM (self),
|
||||
current);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (bands_2g); i++) {
|
||||
if (strcmp (bands_2g[i].cinterion_band, current) == 0) {
|
||||
guint j;
|
||||
|
||||
if (G_UNLIKELY (!bands_array))
|
||||
bands_array = g_array_new (FALSE, FALSE, sizeof (MMModemBand));
|
||||
|
||||
for (j = 0; j < bands_2g[i].n_mm_bands; j++)
|
||||
g_array_append_val (bands_array, bands_2g[i].mm_bands[j]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_free (current);
|
||||
}
|
||||
}
|
||||
|
||||
if (match_info)
|
||||
g_match_info_free (match_info);
|
||||
g_regex_unref (regex);
|
||||
|
||||
if (!bands_array)
|
||||
g_simple_async_result_set_error (operation_result,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse current bands reply");
|
||||
else
|
||||
g_simple_async_result_set_op_res_gpointer (operation_result,
|
||||
bands_array,
|
||||
(GDestroyNotify)g_array_unref);
|
||||
|
||||
g_simple_async_result_complete (operation_result);
|
||||
g_object_unref (operation_result);
|
||||
}
|
||||
|
||||
static void
|
||||
get_3g_band_ready (MMBroadbandModemCinterion *self,
|
||||
get_band_ready (MMBroadbandModemCinterion *self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *simple)
|
||||
{
|
||||
@@ -1080,7 +998,10 @@ get_3g_band_ready (MMBroadbandModemCinterion *self,
|
||||
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
||||
if (!response)
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
else if (!mm_cinterion_parse_scfg_3g_response (response, &bands, &error))
|
||||
else if (!mm_cinterion_parse_scfg_response (response,
|
||||
mm_broadband_modem_get_current_charset (MM_BROADBAND_MODEM (self)),
|
||||
&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);
|
||||
@@ -1101,15 +1022,11 @@ load_current_bands (MMIfaceModem *self,
|
||||
user_data,
|
||||
load_current_bands);
|
||||
|
||||
/* Query the currently used Radio/Band. The query command is the same for
|
||||
* both 2G and 3G devices, but the reply reader is different. */
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||
"AT^SCFG=\"Radio/Band\"",
|
||||
3,
|
||||
FALSE,
|
||||
(GAsyncReadyCallback)(mm_iface_modem_is_3g (self) ?
|
||||
get_3g_band_ready :
|
||||
get_2g_band_ready),
|
||||
(GAsyncReadyCallback)get_band_ready,
|
||||
result);
|
||||
}
|
||||
|
||||
|
@@ -136,15 +136,24 @@ mm_cinterion_parse_scfg_test (const gchar *response,
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^SCFG (3G) response parser
|
||||
/* ^SCFG response parser
|
||||
*
|
||||
* Example:
|
||||
* Example (3G):
|
||||
* AT^SCFG="Radio/Band"
|
||||
* ^SCFG: "Radio/Band",127
|
||||
*
|
||||
* Example (2G, UCS-2):
|
||||
* AT+SCFG="Radio/Band"
|
||||
* ^SCFG: "Radio/Band","0031","0031"
|
||||
*
|
||||
* Example (2G):
|
||||
* AT+SCFG="Radio/Band"
|
||||
* ^SCFG: "Radio/Band","3","3"
|
||||
*/
|
||||
|
||||
gboolean
|
||||
mm_cinterion_parse_scfg_3g_response (const gchar *response,
|
||||
mm_cinterion_parse_scfg_response (const gchar *response,
|
||||
MMModemCharset charset,
|
||||
GArray **current_bands,
|
||||
GError **error)
|
||||
{
|
||||
@@ -158,29 +167,39 @@ mm_cinterion_parse_scfg_3g_response (const gchar *response,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r = g_regex_new ("\\^SCFG:\\s*\"Radio/Band\",\\s*(\\d*)", 0, 0, NULL);
|
||||
r = g_regex_new ("\\^SCFG:\\s*\"Radio/Band\",\\s*\"?([0-9a-fA-F]*)\"?", 0, 0, NULL);
|
||||
g_assert (r != NULL);
|
||||
|
||||
if (g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, NULL)) {
|
||||
gchar *current;
|
||||
gchar *currentstr;
|
||||
guint current = 0;
|
||||
|
||||
current = g_match_info_fetch (match_info, 1);
|
||||
if (current) {
|
||||
guint32 current_int;
|
||||
currentstr = mm_get_string_unquoted_from_match_info (match_info, 1);
|
||||
if (currentstr) {
|
||||
/* Handle charset conversion if the number is given in UCS2 */
|
||||
if (charset != MM_MODEM_CHARSET_UNKNOWN)
|
||||
currentstr = mm_charset_take_and_convert_to_utf8 (currentstr, charset);
|
||||
|
||||
mm_get_uint_from_str (currentstr, ¤t);
|
||||
}
|
||||
|
||||
if (current == 0) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse ^SCFG response");
|
||||
} else {
|
||||
guint i;
|
||||
|
||||
current_int = (guint32) atoi (current);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (cinterion_bands); i++) {
|
||||
if (current_int & cinterion_bands[i].cinterion_band_flag) {
|
||||
if (current & cinterion_bands[i].cinterion_band_flag) {
|
||||
if (G_UNLIKELY (!bands))
|
||||
bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 4);
|
||||
bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 9);
|
||||
g_array_append_val (bands, cinterion_bands[i].mm_band);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (current);
|
||||
}
|
||||
|
||||
g_free (currentstr);
|
||||
}
|
||||
|
||||
if (match_info)
|
||||
@@ -190,7 +209,7 @@ mm_cinterion_parse_scfg_3g_response (const gchar *response,
|
||||
if (!bands)
|
||||
inner_error = g_error_new (MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"No valid bands found in ^SCFG=? response");
|
||||
"No valid bands found in ^SCFG response");
|
||||
|
||||
if (inner_error) {
|
||||
g_propagate_error (error, inner_error);
|
||||
|
@@ -29,7 +29,8 @@ gboolean mm_cinterion_parse_scfg_test (const gchar *response,
|
||||
/*****************************************************************************/
|
||||
/* ^SCFG response parser */
|
||||
|
||||
gboolean mm_cinterion_parse_scfg_3g_response (const gchar *response,
|
||||
gboolean mm_cinterion_parse_scfg_response (const gchar *response,
|
||||
MMModemCharset charset,
|
||||
GArray **bands,
|
||||
GError **error);
|
||||
|
||||
|
@@ -122,6 +122,7 @@ test_scfg (void)
|
||||
|
||||
static void
|
||||
common_test_scfg_response (const gchar *response,
|
||||
MMModemCharset charset,
|
||||
GArray *expected_bands)
|
||||
{
|
||||
GArray *bands = NULL;
|
||||
@@ -130,7 +131,7 @@ common_test_scfg_response (const gchar *response,
|
||||
GError *error = NULL;
|
||||
gboolean res;
|
||||
|
||||
res = mm_cinterion_parse_scfg_3g_response (response, &bands, &error);
|
||||
res = mm_cinterion_parse_scfg_response (response, charset, &bands, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (res == TRUE);
|
||||
g_assert (bands != NULL);
|
||||
@@ -152,7 +153,42 @@ common_test_scfg_response (const gchar *response,
|
||||
}
|
||||
|
||||
static void
|
||||
test_scfg_response (void)
|
||||
test_scfg_response_2g (void)
|
||||
{
|
||||
GArray *expected_bands;
|
||||
MMModemBand single;
|
||||
const gchar *response =
|
||||
"^SCFG: \"Radio/Band\",\"3\",\"3\"\r\n"
|
||||
"\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);
|
||||
|
||||
common_test_scfg_response (response, MM_MODEM_CHARSET_UNKNOWN, expected_bands);
|
||||
|
||||
g_array_unref (expected_bands);
|
||||
}
|
||||
|
||||
static void
|
||||
test_scfg_response_2g_ucs2 (void)
|
||||
{
|
||||
GArray *expected_bands;
|
||||
MMModemBand single;
|
||||
const gchar *response =
|
||||
"^SCFG: \"Radio/Band\",\"0031\",\"0031\"\r\n"
|
||||
"\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);
|
||||
|
||||
common_test_scfg_response (response, MM_MODEM_CHARSET_UCS2, expected_bands);
|
||||
|
||||
g_array_unref (expected_bands);
|
||||
}
|
||||
|
||||
static void
|
||||
test_scfg_response_3g (void)
|
||||
{
|
||||
GArray *expected_bands;
|
||||
MMModemBand single;
|
||||
@@ -169,7 +205,7 @@ test_scfg_response (void)
|
||||
single = MM_MODEM_BAND_U1900, g_array_append_val (expected_bands, single);
|
||||
single = MM_MODEM_BAND_U850, g_array_append_val (expected_bands, single);
|
||||
|
||||
common_test_scfg_response (response, expected_bands);
|
||||
common_test_scfg_response (response, MM_MODEM_CHARSET_UNKNOWN, expected_bands);
|
||||
|
||||
g_array_unref (expected_bands);
|
||||
}
|
||||
@@ -204,7 +240,9 @@ int main (int argc, char **argv)
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/MM/cinterion/scfg", test_scfg);
|
||||
g_test_add_func ("/MM/cinterion/scfg/response", test_scfg_response);
|
||||
g_test_add_func ("/MM/cinterion/scfg/response/3g", test_scfg_response_3g);
|
||||
g_test_add_func ("/MM/cinterion/scfg/response/2g", test_scfg_response_2g);
|
||||
g_test_add_func ("/MM/cinterion/scfg/response/2g/ucs2", test_scfg_response_2g_ucs2);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user