aboutsummaryrefslogtreecommitdiff
path: root/plugins/altair/mm-modem-helpers-altair-lte.c
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2014-05-28 23:13:15 -0700
committerAleksander Morgado <aleksander@aleksander.es>2014-05-29 10:06:37 +0200
commitc8f62fb4de0420a1c0876b3076a1a1a903bd8bff (patch)
tree98fc706dc11fadafad8cf7b5e3cbb64e57a53d31 /plugins/altair/mm-modem-helpers-altair-lte.c
parent8cdf45c66c3c2660ed7e49e1edf241b30f7c037c (diff)
altair-lte: ignore invalid bands in %BANDCAP / %GETCFG="BAND" responses
Due to a firmware issue, the modem may reply an invalid band value, such as 0, for the %BANDCAP or %GETCFG="BAND" command. This patch moves parse_bands_response() to mm-modem-helpers-altair-lte.c, modifies the function to ignore any invalid band outside the range of E-UTRAN operating bands, and add unit tests for the function.
Diffstat (limited to 'plugins/altair/mm-modem-helpers-altair-lte.c')
-rw-r--r--plugins/altair/mm-modem-helpers-altair-lte.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/plugins/altair/mm-modem-helpers-altair-lte.c b/plugins/altair/mm-modem-helpers-altair-lte.c
index e19f147b..b369e29c 100644
--- a/plugins/altair/mm-modem-helpers-altair-lte.c
+++ b/plugins/altair/mm-modem-helpers-altair-lte.c
@@ -14,6 +14,7 @@
*
*/
+#include <stdlib.h>
#include <string.h>
#include <ModemManager.h>
@@ -23,6 +24,44 @@
#include "mm-modem-helpers-altair-lte.h"
/*****************************************************************************/
+/* Bands response parser */
+
+GArray *
+mm_altair_parse_bands_response (const gchar *response)
+{
+ gchar **split;
+ GArray *bands;
+ guint i;
+
+ /*
+ * Response is "<band>[,<band>...]"
+ */
+ split = g_strsplit_set (response, ",", -1);
+ if (!split)
+ return NULL;
+
+ bands = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), g_strv_length (split));
+
+ for (i = 0; split[i]; i++) {
+ guint32 band_value;
+ MMModemBand band;
+
+ band_value = (guint32)strtoul (split[i], NULL, 10);
+ band = MM_MODEM_BAND_EUTRAN_I - 1 + band_value;
+
+ /* Due to a firmware issue, the modem may incorrectly includes 0 in the
+ * bands response. We thus ignore any band value outside the range of
+ * E-UTRAN operating bands. */
+ if (band >= MM_MODEM_BAND_EUTRAN_I && band <= MM_MODEM_BAND_EUTRAN_XLIV)
+ g_array_append_val (bands, band);
+ }
+
+ g_strfreev (split);
+
+ return bands;
+}
+
+/*****************************************************************************/
/* +CEER response parser */
gchar *