aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2019-06-07 18:06:53 +0200
committerAleksander Morgado <aleksander@aleksander.es>2019-07-11 23:00:50 +0200
commitdca00271ce8a5020b78e46d6f0e3eca90ef69d67 (patch)
tree2a279bb9e89aef8fd1d23fcd20264ee972d8747b
parentd9a7b403eeb12b22f9d63aae9c6956d735cdd97a (diff)
broadband-modem: implement +CCWA URC handling
-rw-r--r--src/mm-broadband-modem.c28
-rw-r--r--src/mm-modem-helpers.c17
-rw-r--r--src/mm-modem-helpers.h2
-rw-r--r--src/tests/test-modem-helpers.c50
4 files changed, 94 insertions, 3 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index c9cc9b93..c1e2582f 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -7250,12 +7250,25 @@ modem_voice_setup_cleanup_unsolicited_events_finish (MMIfaceModemVoice *self,
}
static void
+ccwa_received (MMPortSerialAt *port,
+ GMatchInfo *info,
+ MMBroadbandModem *self)
+{
+ gchar *str;
+
+ str = mm_get_string_unquoted_from_match_info (info, 1);
+ mm_dbg ("Call waiting (%s)", str);
+ mm_iface_modem_voice_report_incoming_call (MM_IFACE_MODEM_VOICE (self), str, MM_CALL_STATE_WAITING);
+ g_free (str);
+}
+
+static void
ring_received (MMPortSerialAt *port,
GMatchInfo *info,
MMBroadbandModem *self)
{
mm_dbg ("Ringing");
- mm_iface_modem_voice_report_incoming_call (MM_IFACE_MODEM_VOICE (self), NULL);
+ mm_iface_modem_voice_report_incoming_call (MM_IFACE_MODEM_VOICE (self), NULL, MM_CALL_STATE_RINGING_IN);
}
static void
@@ -7271,7 +7284,7 @@ cring_received (MMPortSerialAt *port,
mm_dbg ("Ringing (%s)", str);
g_free (str);
- mm_iface_modem_voice_report_incoming_call (MM_IFACE_MODEM_VOICE (self), NULL);
+ mm_iface_modem_voice_report_incoming_call (MM_IFACE_MODEM_VOICE (self), NULL, MM_CALL_STATE_RINGING_IN);
}
static void
@@ -7282,7 +7295,7 @@ clip_received (MMPortSerialAt *port,
gchar *str;
str = mm_get_string_unquoted_from_match_info (info, 1);
- mm_iface_modem_voice_report_incoming_call (MM_IFACE_MODEM_VOICE (self), str);
+ mm_iface_modem_voice_report_incoming_call (MM_IFACE_MODEM_VOICE (self), str, MM_CALL_STATE_RINGING_IN);
g_free (str);
}
@@ -7296,12 +7309,14 @@ set_voice_unsolicited_events_handlers (MMIfaceModemVoice *self,
GRegex *cring_regex;
GRegex *ring_regex;
GRegex *clip_regex;
+ GRegex *ccwa_regex;
guint i;
GTask *task;
cring_regex = mm_voice_cring_regex_get ();
ring_regex = mm_voice_ring_regex_get ();
clip_regex = mm_voice_clip_regex_get ();
+ ccwa_regex = mm_voice_ccwa_regex_get ();
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
@@ -7332,8 +7347,15 @@ set_voice_unsolicited_events_handlers (MMIfaceModemVoice *self,
enable ? (MMPortSerialAtUnsolicitedMsgFn) clip_received : NULL,
enable ? self : NULL,
NULL);
+ mm_port_serial_at_add_unsolicited_msg_handler (
+ ports[i],
+ ccwa_regex,
+ enable ? (MMPortSerialAtUnsolicitedMsgFn) ccwa_received : NULL,
+ enable ? self : NULL,
+ NULL);
}
+ g_regex_unref (ccwa_regex);
g_regex_unref (clip_regex);
g_regex_unref (cring_regex);
g_regex_unref (ring_regex);
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 5f027fdd..f94b26f3 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -558,6 +558,23 @@ mm_voice_clip_regex_get (void)
NULL);
}
+GRegex *
+mm_voice_ccwa_regex_get (void)
+{
+ /*
+ * Only first 3 fields are mandatory, but we read only the first one
+ * +CCWA: <number>,<type>,<class>,[<alpha>][,<CLI_validity>[,<subaddr>,<satype>[,<priority>]]]
+ *
+ * Example:
+ * <CR><LF>+CCWA: "+393351391306",145,1
+ * \_ Number \_ Type
+ */
+ return g_regex_new ("\\r\\n\\+CCWA:\\s*([^,\\s]*)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,?(.*)\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE,
+ 0,
+ NULL);
+}
+
/*************************************************************************/
static MMFlowControl
diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h
index c6f8fe26..9c067747 100644
--- a/src/mm-modem-helpers.h
+++ b/src/mm-modem-helpers.h
@@ -93,9 +93,11 @@ gchar *mm_bcd_to_string (const guint8 *bcd, gsize bcd_len);
/*****************************************************************************/
/* VOICE specific helpers and utilities */
/*****************************************************************************/
+
GRegex *mm_voice_ring_regex_get (void);
GRegex *mm_voice_cring_regex_get (void);
GRegex *mm_voice_clip_regex_get (void);
+GRegex *mm_voice_ccwa_regex_get (void);
/*****************************************************************************/
/* SERIAL specific helpers and utilities */
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index 0e8674d2..714bbab4 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -3970,6 +3970,55 @@ test_clip_indication (void)
}
/*****************************************************************************/
+/* +CCWA URC */
+
+typedef struct {
+ const gchar *str;
+ const gchar *number;
+ guint type;
+ guint class;
+} CcwaUrcTest;
+
+static const CcwaUrcTest ccwa_urc_tests[] = {
+ { "\r\n+CCWA: \"123456789\",129,1\r\n", "123456789", 129, 1 },
+ { "\r\n+CCWA: \"123456789\",129,1,,0\r\n", "123456789", 129, 1 },
+ { "\r\n+CCWA: \"123456789\",129,1,,0,,,\r\n", "123456789", 129, 1 },
+};
+
+static void
+test_ccwa_indication (void)
+{
+ GRegex *r;
+ guint i;
+
+ r = mm_voice_ccwa_regex_get ();
+
+ for (i = 0; i < G_N_ELEMENTS (ccwa_urc_tests); i++) {
+ GMatchInfo *match_info = NULL;
+ gchar *number;
+ guint type;
+ guint class;
+
+ g_assert (g_regex_match (r, ccwa_urc_tests[i].str, 0, &match_info));
+ g_assert (g_match_info_matches (match_info));
+
+ number = mm_get_string_unquoted_from_match_info (match_info, 1);
+ g_assert_cmpstr (number, ==, ccwa_urc_tests[i].number);
+
+ g_assert (mm_get_uint_from_match_info (match_info, 2, &type));
+ g_assert_cmpuint (type, ==, ccwa_urc_tests[i].type);
+
+ g_assert (mm_get_uint_from_match_info (match_info, 3, &class));
+ g_assert_cmpuint (class, ==, ccwa_urc_tests[i].class);
+
+ g_free (number);
+ g_match_info_free (match_info);
+ }
+
+ g_regex_unref (r);
+}
+
+/*****************************************************************************/
typedef struct {
gchar *str;
@@ -4281,6 +4330,7 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_cesq_response_to_signal, NULL));
g_test_suite_add (suite, TESTCASE (test_clip_indication, NULL));
+ g_test_suite_add (suite, TESTCASE (test_ccwa_indication, NULL));
g_test_suite_add (suite, TESTCASE (test_parse_uint_list, NULL));