diff options
Diffstat (limited to 'plugins/huawei/mm-modem-helpers-huawei.c')
-rw-r--r-- | plugins/huawei/mm-modem-helpers-huawei.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c index bb977c27..b869c310 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.c +++ b/plugins/huawei/mm-modem-helpers-huawei.c @@ -112,3 +112,70 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response, return TRUE; } + +/*****************************************************************************/ +/* ^SYSINFO response parser */ + +gboolean +mm_huawei_parse_sysinfo_response (const char *reply, + guint *out_srv_status, + guint *out_srv_domain, + guint *out_roam_status, + guint *out_sys_mode, + guint *out_sim_state, + gboolean *out_sys_submode_valid, + guint *out_sys_submode, + GError **error) +{ + gboolean matched; + GRegex *r; + GMatchInfo *match_info = NULL; + GError *match_error = NULL; + + g_assert (out_srv_status != NULL); + g_assert (out_srv_domain != NULL); + g_assert (out_roam_status != NULL); + g_assert (out_sys_mode != NULL); + g_assert (out_sim_state != NULL); + g_assert (out_sys_submode_valid != NULL); + g_assert (out_sys_submode != NULL); + + /* Format: + * + * ^SYSINFO: <srv_status>,<srv_domain>,<roam_status>,<sys_mode>,<sim_state>[,<reserved>,<sys_submode>] + */ + + /* Can't just use \d here since sometimes you get "^SYSINFO:2,1,0,3,1,,3" */ + r = g_regex_new ("\\^SYSINFO:\\s*(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),?(\\d+)?,?(\\d+)?$", 0, 0, NULL); + g_assert (r != NULL); + + matched = g_regex_match_full (r, reply, -1, 0, 0, &match_info, &match_error); + if (!matched) { + if (match_error) { + g_propagate_error (error, match_error); + g_prefix_error (error, "Could not parse ^SYSINFO results: "); + } else { + g_set_error_literal (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't match ^SYSINFO reply"); + } + } else { + mm_get_uint_from_match_info (match_info, 1, out_srv_status); + mm_get_uint_from_match_info (match_info, 2, out_srv_domain); + mm_get_uint_from_match_info (match_info, 3, out_roam_status); + mm_get_uint_from_match_info (match_info, 4, out_sys_mode); + mm_get_uint_from_match_info (match_info, 5, out_sim_state); + + /* Remember that g_match_info_get_match_count() includes match #0 */ + if (g_match_info_get_match_count (match_info) >= 8) { + *out_sys_submode_valid = TRUE; + mm_get_uint_from_match_info (match_info, 7, out_sys_submode); + } + } + + if (match_info) + g_match_info_free (match_info); + g_regex_unref (r); + return matched; +} |