diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2014-02-26 15:51:11 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2014-02-28 16:35:18 +0100 |
commit | e6430acaaaa56eae95206a564109e2a04c99e7c5 (patch) | |
tree | 00e494a98dc76df790df293d34e413810d8da6ae /plugins/cinterion/mm-modem-helpers-cinterion.c | |
parent | 82067915d16a5e367346a3b62489b6efcb19f834 (diff) |
cinterion: add helper to parse AT^SCFG="Radio/Band" response in 3G devices
Diffstat (limited to 'plugins/cinterion/mm-modem-helpers-cinterion.c')
-rw-r--r-- | plugins/cinterion/mm-modem-helpers-cinterion.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index 7e350512..8fe641b7 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -15,6 +15,7 @@ #include <config.h> #include <string.h> +#include <stdlib.h> #include "ModemManager.h" #define _LIBMM_INSIDE_MM @@ -98,6 +99,8 @@ mm_cinterion_parse_scfg_3g_test (const gchar *response, } } } + + g_free (maxbandstr); } if (match_info) @@ -119,3 +122,71 @@ mm_cinterion_parse_scfg_3g_test (const gchar *response, return TRUE; } + +/*****************************************************************************/ +/* ^SCFG (3G) response parser + * + * Example: + * AT^SCFG="Radio/Band" + * ^SCFG: "Radio/Band",127 + */ + +gboolean +mm_cinterion_parse_scfg_3g_response (const gchar *response, + GArray **current_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\",\\s*(\\d*)", 0, 0, NULL); + g_assert (r != NULL); + + if (g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, NULL)) { + gchar *current; + + current = g_match_info_fetch (match_info, 1); + if (current) { + guint32 current_int; + guint i; + + current_int = (guint32) atoi (current); + + for (i = 0; i < G_N_ELEMENTS (bands_3g); i++) { + if (current_int & bands_3g[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_free (current); + } + } + + 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); + *current_bands = bands; + + return TRUE; +} |