aboutsummaryrefslogtreecommitdiff
path: root/plugins/cinterion/mm-modem-helpers-cinterion.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-02-14 19:46:26 +0100
committerAleksander Morgado <aleksander@aleksander.es>2017-02-16 12:27:57 +0100
commit37df2643d2334a8ed8b9774396fcd2567a68a6de (patch)
tree241eddec3baebc77ff9d016fa7db1e0405ad9d15 /plugins/cinterion/mm-modem-helpers-cinterion.c
parent97eb23a964046abd0724d6fff6d3816f4ab3e220 (diff)
cinterion: improve ^SMONG response parser:
* Allow whitespaces prefixing the values row. * Allow more than one \r\n between the title and the table header. Reported-by: Colin Helliwell <colin.helliwell@ln-systems.com>
Diffstat (limited to 'plugins/cinterion/mm-modem-helpers-cinterion.c')
-rw-r--r--plugins/cinterion/mm-modem-helpers-cinterion.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c
index e9c1e0d1..9bc8db4f 100644
--- a/plugins/cinterion/mm-modem-helpers-cinterion.c
+++ b/plugins/cinterion/mm-modem-helpers-cinterion.c
@@ -546,3 +546,80 @@ mm_cinterion_parse_swwan_response (const gchar *response,
return status;
}
+
+/*****************************************************************************/
+/* ^SMONG response parser */
+
+static MMModemAccessTechnology
+get_access_technology_from_smong_gprs_status (guint gprs_status,
+ GError **error)
+{
+ switch (gprs_status) {
+ case 0:
+ return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+ case 1:
+ case 2:
+ return MM_MODEM_ACCESS_TECHNOLOGY_GPRS;
+ case 3:
+ case 4:
+ return MM_MODEM_ACCESS_TECHNOLOGY_EDGE;
+ default:
+ break;
+ }
+
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_INVALID_ARGS,
+ "Couldn't get network capabilities, "
+ "unsupported GPRS status value: '%u'",
+ gprs_status);
+ return MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
+}
+
+gboolean
+mm_cinterion_parse_smong_response (const gchar *response,
+ MMModemAccessTechnology *access_tech,
+ GError **error)
+{
+ GError *inner_error = NULL;
+ GMatchInfo *match_info = NULL;
+ GRegex *regex;
+
+ /* The AT^SMONG command returns a cell info table, where the second
+ * column identifies the "GPRS status", which is exactly what we want.
+ * So we'll try to read that second number in the values row.
+ *
+ * AT^SMONG
+ * GPRS Monitor
+ * BCCH G PBCCH PAT MCC MNC NOM TA RAC # Cell #
+ * 0776 1 - - 214 03 2 00 01
+ * OK
+ */
+ regex = g_regex_new (".*GPRS Monitor(?:\r\n)*"
+ "BCCH\\s*G.*\\r\\n"
+ "\\s*(\\d+)\\s*(\\d+)\\s*",
+ G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
+ 0, NULL);
+ g_assert (regex);
+
+ if (g_regex_match_full (regex, response, strlen (response), 0, 0, &match_info, &inner_error)) {
+ guint value = 0;
+
+ if (!mm_get_uint_from_match_info (match_info, 2, &value))
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Couldn't read 'GPRS status' field from AT^SMONG response");
+ else if (access_tech)
+ *access_tech = get_access_technology_from_smong_gprs_status (value, &inner_error);
+ }
+
+ g_match_info_free (match_info);
+ g_regex_unref (regex);
+
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return FALSE;
+ }
+
+ g_assert (access_tech != MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN);
+ return TRUE;
+}