huawei: new ^SYSCFG? response parser
This commit is contained in:
@@ -709,6 +709,72 @@ mm_huawei_parse_syscfg_test (const gchar *response,
|
||||
return out;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ^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 */
|
||||
|
||||
|
@@ -83,6 +83,13 @@ typedef struct {
|
||||
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 */
|
||||
|
||||
|
@@ -577,6 +577,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 */
|
||||
|
||||
@@ -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 ();
|
||||
|
Reference in New Issue
Block a user