From f39dbe72e5fceacd9a45f48049b14f734f515ee3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 15 Jul 2019 17:13:21 +0200 Subject: broadband-modem,voice: implement call waiting status setup/query with +CCWA --- src/mm-modem-helpers.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'src/mm-modem-helpers.c') diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index b9d364d2..c6644c1c 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -2723,6 +2723,85 @@ mm_3gpp_parse_cemode_query_response (const gchar *response, return FALSE; } +/*************************************************************************/ +/* CCWA service query response parser */ + +gboolean +mm_3gpp_parse_ccwa_service_query_response (const gchar *response, + gboolean *status, + GError **error) +{ + GRegex *r; + GError *inner_error = NULL; + GMatchInfo *match_info = NULL; + gint class_1_status = -1; + + /* + * AT+CCWA=[,] + * +CCWA: , + * [+CCWA: , + * [...]] + * OK + * + * If is 255 it applies to ALL classes. + * + * We're only interested in class 1 (voice) + */ + r = g_regex_new ("\\+CCWA:\\s*(\\d+),\\s*(\\d+)$", + G_REGEX_RAW | G_REGEX_MULTILINE | G_REGEX_NEWLINE_CRLF, + G_REGEX_MATCH_NEWLINE_CRLF, + NULL); + g_assert (r != NULL); + + g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); + if (inner_error) + goto out; + + /* Parse the results */ + while (g_match_info_matches (match_info)) { + guint st; + guint class; + + if (!mm_get_uint_from_match_info (match_info, 2, &class)) + mm_warn ("couldn't parse class from +CCWA line"); + else if (class == 1 || class == 255) { + if (!mm_get_uint_from_match_info (match_info, 1, &st)) + mm_warn ("couldn't parse status from +CCWA line"); + else { + class_1_status = st; + break; + } + } + g_match_info_next (match_info, NULL); + } + +out: + g_clear_pointer (&match_info, g_match_info_free); + g_regex_unref (r); + + if (inner_error) { + g_propagate_error (error, inner_error); + return FALSE; + } + + if (class_1_status < 0) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_NOT_FOUND, + "call waiting status for voice class missing"); + return FALSE; + } + + if (class_1_status != 0 && class_1_status != 1) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED, + "call waiting status for voice class invalid: %d", class_1_status); + return FALSE; + } + + if (status) + *status = (gboolean) class_1_status; + + return TRUE; +} + /*************************************************************************/ static MMSmsStorage -- cgit v1.2.3-70-g09d2