summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/huawei/mm-modem-helpers-huawei.c66
-rw-r--r--plugins/huawei/mm-modem-helpers-huawei.h7
-rw-r--r--plugins/huawei/tests/test-modem-helpers-huawei.c69
3 files changed, 142 insertions, 0 deletions
diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c
index a626b0600..b136a30fe 100644
--- a/plugins/huawei/mm-modem-helpers-huawei.c
+++ b/plugins/huawei/mm-modem-helpers-huawei.c
@@ -710,6 +710,72 @@ mm_huawei_parse_syscfg_test (const gchar *response,
}
/*****************************************************************************/
+/* ^SYSCFG response parser */
+
+const MMHuaweiSyscfgCombination *
+mm_huawei_parse_syscfg_response (const gchar *response,
+ const GArray *supported_mode_combinations,
+ GError **error)
+{
+ gchar **split;
+ guint mode;
+ guint acqorder;
+ guint i;
+
+ if (!response || !g_str_has_prefix (response, "^SYSCFG:")) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Missing ^SYSCFG prefix");
+ return NULL;
+ }
+
+ /* Format:
+ *
+ * ^SYSCFG: <mode>,<acqorder>,<band>,<roam>,<srvdomain>
+ */
+
+ response = mm_strip_tag (response, "^SYSCFG:");
+ split = g_strsplit (response, ",", -1);
+
+ /* We expect 5 string chunks */
+ if (g_strv_length (split) < 5 ||
+ !mm_get_uint_from_str (split[0], &mode) ||
+ !mm_get_uint_from_str (split[1], &acqorder)) {
+ /* Dump error to upper layer */
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Unexpected ^SYSCFG response: '%s'",
+ response);
+ g_strfreev (split);
+ return NULL;
+ }
+
+ /* Look for current modes among the supported ones */
+ for (i = 0; i < supported_mode_combinations->len; i++) {
+ const MMHuaweiSyscfgCombination *combination;
+
+ combination = &g_array_index (supported_mode_combinations,
+ MMHuaweiSyscfgCombination,
+ i);
+ if (mode == combination->mode && acqorder == combination->acqorder) {
+ g_strfreev (split);
+ return combination;
+ }
+ }
+
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "No SYSCFG combination found matching the current one (%d,%d)",
+ mode,
+ acqorder);
+ g_strfreev (split);
+ return NULL;
+}
+
+/*****************************************************************************/
/* ^SYSCFGEX test parser */
static void
diff --git a/plugins/huawei/mm-modem-helpers-huawei.h b/plugins/huawei/mm-modem-helpers-huawei.h
index 1c1f1be10..07184e84d 100644
--- a/plugins/huawei/mm-modem-helpers-huawei.h
+++ b/plugins/huawei/mm-modem-helpers-huawei.h
@@ -84,6 +84,13 @@ GArray *mm_huawei_parse_syscfg_test (const gchar *response,
GError **error);
/*****************************************************************************/
+/* ^SYSCFG response parser */
+
+const MMHuaweiSyscfgCombination *mm_huawei_parse_syscfg_response (const gchar *response,
+ const GArray *supported_mode_combinations,
+ GError **error);
+
+/*****************************************************************************/
/* ^SYSCFGEX test parser */
typedef struct {
diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c
index fd35ec287..20dcf5f6a 100644
--- a/plugins/huawei/tests/test-modem-helpers-huawei.c
+++ b/plugins/huawei/tests/test-modem-helpers-huawei.c
@@ -578,6 +578,74 @@ test_syscfg (void)
}
/*****************************************************************************/
+/* Test ^SYSCFG? responses */
+
+typedef struct {
+ const gchar *str;
+ const gchar *format;
+ MMModemMode allowed;
+ MMModemMode preferred;
+} SyscfgResponseTest;
+
+static const SyscfgResponseTest syscfg_response_tests[] = {
+ {
+ .str = "^SYSCFG: 2,0,400000,0,3\r\n",
+ .format = "^SYSCFG:(2,13,14,16),(0-3),((400000,\"WCDMA2100\")),(0-2),(0-4)\r\n",
+ .allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_2G),
+ .preferred = MM_MODEM_MODE_NONE
+ },
+ {
+ .str = "^SYSCFG: 2,1,400000,0,3\r\n",
+ .format = "^SYSCFG:(2,13,14,16),(0-3),((400000,\"WCDMA2100\")),(0-2),(0-4)\r\n",
+ .allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_2G),
+ .preferred = MM_MODEM_MODE_2G
+ },
+ {
+ .str = "^SYSCFG: 2,2,400000,0,3\r\n",
+ .format = "^SYSCFG:(2,13,14,16),(0-3),((400000,\"WCDMA2100\")),(0-2),(0-4)\r\n",
+ .allowed = (MM_MODEM_MODE_3G | MM_MODEM_MODE_2G),
+ .preferred = MM_MODEM_MODE_3G
+ },
+ {
+ .str = "^SYSCFG: 13,0,400000,0,3\r\n",
+ .format = "^SYSCFG:(2,13,14,16),(0-3),((400000,\"WCDMA2100\")),(0-2),(0-4)\r\n",
+ .allowed = MM_MODEM_MODE_2G,
+ .preferred = MM_MODEM_MODE_NONE
+ },
+ {
+ .str = "^SYSCFG: 14,0,400000,0,3\r\n",
+ .format = "^SYSCFG:(2,13,14,16),(0-3),((400000,\"WCDMA2100\")),(0-2),(0-4)\r\n",
+ .allowed = MM_MODEM_MODE_3G,
+ .preferred = MM_MODEM_MODE_NONE
+ }
+};
+
+static void
+test_syscfg_response (void)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (syscfg_response_tests); i++) {
+ GArray *combinations = NULL;
+ const MMHuaweiSyscfgCombination *found;
+ GError *error = NULL;
+
+ combinations = mm_huawei_parse_syscfg_test (syscfg_response_tests[i].format, NULL);
+ g_assert (combinations != NULL);
+
+ found = mm_huawei_parse_syscfg_response (syscfg_response_tests[i].str,
+ combinations,
+ &error);
+
+ g_assert (found != NULL);
+ g_assert_cmpuint (found->allowed, ==, syscfg_response_tests[i].allowed);
+ g_assert_cmpuint (found->preferred, ==, syscfg_response_tests[i].preferred);
+
+ g_array_unref (combinations);
+ }
+}
+
+/*****************************************************************************/
/* Test ^SYSCFGEX=? responses */
#define MAX_SYSCFGEX_COMBINATIONS 5
@@ -796,6 +864,7 @@ int main (int argc, char **argv)
g_test_add_func ("/MM/huawei/prefmode", test_prefmode);
g_test_add_func ("/MM/huawei/prefmode/response", test_prefmode_response);
g_test_add_func ("/MM/huawei/syscfg", test_syscfg);
+ g_test_add_func ("/MM/huawei/syscfg/response", test_syscfg_response);
g_test_add_func ("/MM/huawei/syscfgex", test_syscfgex);
return g_test_run ();