aboutsummaryrefslogtreecommitdiff
path: root/plugins/huawei/mm-modem-helpers-huawei.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/huawei/mm-modem-helpers-huawei.c')
-rw-r--r--plugins/huawei/mm-modem-helpers-huawei.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c
index 0e0e046b..d3f13c23 100644
--- a/plugins/huawei/mm-modem-helpers-huawei.c
+++ b/plugins/huawei/mm-modem-helpers-huawei.c
@@ -1329,3 +1329,74 @@ gboolean mm_huawei_parse_time_response (const gchar *response,
return ret;
}
+
+/*****************************************************************************/
+/* ^HCSQ response parser */
+
+gboolean
+mm_huawei_parse_hcsq_response (const gchar *response,
+ MMModemAccessTechnology *out_act,
+ guint *out_value1,
+ guint *out_value2,
+ guint *out_value3,
+ guint *out_value4,
+ guint *out_value5,
+ GError **error)
+{
+ GRegex *r;
+ GMatchInfo *match_info = NULL;
+ GError *match_error = NULL;
+ gboolean ret = FALSE;
+ char *s;
+
+ r = g_regex_new ("\\^HCSQ:\\s*\"([a-zA-Z]*)\",(\\d+),?(\\d+)?,?(\\d+)?,?(\\d+)?,?(\\d+)?$", 0, 0, NULL);
+ g_assert (r != NULL);
+
+ if (!g_regex_match_full (r, response, -1, 0, 0, &match_info, &match_error)) {
+ if (match_error) {
+ g_propagate_error (error, match_error);
+ g_prefix_error (error, "Could not parse ^HCSQ results: ");
+ } else {
+ g_set_error_literal (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't match ^HCSQ reply");
+ }
+ goto done;
+ }
+
+ /* Remember that g_match_info_get_match_count() includes match #0 */
+ if (g_match_info_get_match_count (match_info) < 3) {
+ g_set_error_literal (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Not enough elements in ^HCSQ reply");
+ goto done;
+ }
+
+ if (out_act) {
+ s = g_match_info_fetch (match_info, 1);
+ *out_act = mm_string_to_access_tech (s);
+ g_free (s);
+ }
+
+ if (out_value1)
+ mm_get_uint_from_match_info (match_info, 2, out_value1);
+ if (out_value2)
+ mm_get_uint_from_match_info (match_info, 3, out_value2);
+ if (out_value3)
+ mm_get_uint_from_match_info (match_info, 4, out_value3);
+ if (out_value4)
+ mm_get_uint_from_match_info (match_info, 5, out_value4);
+ if (out_value5)
+ mm_get_uint_from_match_info (match_info, 6, out_value5);
+
+ ret = TRUE;
+
+done:
+ if (match_info)
+ g_match_info_free (match_info);
+ g_regex_unref (r);
+
+ return ret;
+}