aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2019-10-16 18:03:53 +0200
committerAleksander Morgado <aleksander@aleksander.es>2019-10-16 18:04:47 +0200
commit5316e9e4e56faa606c2ae4f19087ae98b8c3944d (patch)
tree2b4557f8d33aa319bf9933f887709dc3327dd399
parenteb66e8ae6844dfd065b68523bc9b5e3b2bf0d979 (diff)
simtech: handle 'MISSED_CALL' URCs
https://source.puri.sm/Librem5/ModemManager/issues/6
-rw-r--r--plugins/simtech/mm-modem-helpers-simtech.c30
-rw-r--r--plugins/simtech/mm-modem-helpers-simtech.h8
-rw-r--r--plugins/simtech/mm-shared-simtech.c27
-rw-r--r--plugins/simtech/tests/test-modem-helpers-simtech.c38
4 files changed, 103 insertions, 0 deletions
diff --git a/plugins/simtech/mm-modem-helpers-simtech.c b/plugins/simtech/mm-modem-helpers-simtech.c
index 4da3c988..d452e0b6 100644
--- a/plugins/simtech/mm-modem-helpers-simtech.c
+++ b/plugins/simtech/mm-modem-helpers-simtech.c
@@ -152,6 +152,36 @@ out:
/*****************************************************************************/
/*
+ * <CR><LF>MISSED_CALL: 11:01AM 07712345678<CR><LF>
+ */
+GRegex *
+mm_simtech_get_missed_call_urc_regex (void)
+{
+ return g_regex_new ("\\r\\nMISSED_CALL:\\s*(.+)\\r\\n",
+ G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
+}
+
+gboolean
+mm_simtech_parse_missed_call_urc (GMatchInfo *match_info,
+ gchar **details,
+ GError **error)
+{
+ gchar *str;
+
+ str = mm_get_string_unquoted_from_match_info (match_info, 1);
+ if (!str) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Couldn't read missed call URC details");
+ return FALSE;
+ }
+
+ *details = str;
+ return TRUE;
+}
+
+/*****************************************************************************/
+
+/*
* Using TWO <CR> instead of one...
* <CR><CR><LF>+CRING: VOICE<CR><CR><LF>
*/
diff --git a/plugins/simtech/mm-modem-helpers-simtech.h b/plugins/simtech/mm-modem-helpers-simtech.h
index 958d9cfb..efcc23f5 100644
--- a/plugins/simtech/mm-modem-helpers-simtech.h
+++ b/plugins/simtech/mm-modem-helpers-simtech.h
@@ -46,6 +46,14 @@ gboolean mm_simtech_parse_voice_call_urc (GMatchInfo *match_info,
GError **error);
/*****************************************************************************/
+/* MISSED_CALL URC helpers */
+
+GRegex *mm_simtech_get_missed_call_urc_regex (void);
+gboolean mm_simtech_parse_missed_call_urc (GMatchInfo *match_info,
+ gchar **details,
+ GError **error);
+
+/*****************************************************************************/
/* Non-standard CRING URC helpers */
GRegex *mm_simtech_get_cring_urc_regex (void);
diff --git a/plugins/simtech/mm-shared-simtech.c b/plugins/simtech/mm-shared-simtech.c
index 5b1b852b..b7f98ace 100644
--- a/plugins/simtech/mm-shared-simtech.c
+++ b/plugins/simtech/mm-shared-simtech.c
@@ -54,6 +54,7 @@ typedef struct {
FeatureSupport clcc_urc_support;
GRegex *clcc_urc_regex;
GRegex *voice_call_regex;
+ GRegex *missed_call_regex;
GRegex *cring_regex;
GRegex *rxdtmf_regex;
} Private;
@@ -63,6 +64,7 @@ private_free (Private *ctx)
{
g_regex_unref (ctx->rxdtmf_regex);
g_regex_unref (ctx->cring_regex);
+ g_regex_unref (ctx->missed_call_regex);
g_regex_unref (ctx->voice_call_regex);
g_regex_unref (ctx->clcc_urc_regex);
g_slice_free (Private, ctx);
@@ -86,6 +88,7 @@ get_private (MMSharedSimtech *self)
priv->clcc_urc_support = FEATURE_SUPPORT_UNKNOWN;
priv->clcc_urc_regex = mm_simtech_get_clcc_urc_regex ();
priv->voice_call_regex = mm_simtech_get_voice_call_urc_regex ();
+ priv->missed_call_regex = mm_simtech_get_missed_call_urc_regex ();
priv->cring_regex = mm_simtech_get_cring_urc_regex ();
priv->rxdtmf_regex = mm_simtech_get_rxdtmf_urc_regex ();
@@ -810,6 +813,24 @@ clcc_urc_received (MMPortSerialAt *port,
}
static void
+missed_call_urc_received (MMPortSerialAt *port,
+ GMatchInfo *match_info,
+ MMSharedSimtech *self)
+{
+ GError *error = NULL;
+ gchar *details = NULL;
+
+ if (!mm_simtech_parse_missed_call_urc (match_info, &details, &error)) {
+ mm_warn ("couldn't parse missed call URC: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ mm_dbg ("missed call reported: %s", details);
+ g_free (details);
+}
+
+static void
voice_call_urc_received (MMPortSerialAt *port,
GMatchInfo *match_info,
MMSharedSimtech *self)
@@ -903,6 +924,12 @@ common_voice_setup_cleanup_unsolicited_events (MMSharedSimtech *self,
NULL);
mm_port_serial_at_add_unsolicited_msg_handler (ports[i],
+ priv->missed_call_regex,
+ enable ? (MMPortSerialAtUnsolicitedMsgFn)missed_call_urc_received : NULL,
+ enable ? self : NULL,
+ NULL);
+
+ mm_port_serial_at_add_unsolicited_msg_handler (ports[i],
priv->cring_regex,
enable ? (MMPortSerialAtUnsolicitedMsgFn)cring_urc_received : NULL,
enable ? self : NULL,
diff --git a/plugins/simtech/tests/test-modem-helpers-simtech.c b/plugins/simtech/tests/test-modem-helpers-simtech.c
index 5a90f374..2e93d895 100644
--- a/plugins/simtech/tests/test-modem-helpers-simtech.c
+++ b/plugins/simtech/tests/test-modem-helpers-simtech.c
@@ -194,6 +194,42 @@ test_voice_call_end_duration_urc (void)
/*****************************************************************************/
static void
+common_test_missed_call_urc (const gchar *urc,
+ const gchar *expected_details)
+{
+ GError *error = NULL;
+ gchar *details = NULL;
+ GRegex *missed_call_regex = NULL;
+ gboolean result;
+ GMatchInfo *match_info = NULL;
+
+ missed_call_regex = mm_simtech_get_missed_call_urc_regex ();
+
+ /* Same matching logic as done in MMSerialPortAt when processing URCs! */
+ result = g_regex_match_full (missed_call_regex, urc, -1, 0, 0, &match_info, &error);
+ g_assert_no_error (error);
+ g_assert (result);
+
+ result = mm_simtech_parse_missed_call_urc (match_info, &details, &error);
+ g_assert_no_error (error);
+ g_assert (result);
+
+ g_assert_cmpstr (expected_details, ==, details);
+ g_free (details);
+
+ g_match_info_free (match_info);
+ g_regex_unref (missed_call_regex);
+}
+
+static void
+test_missed_call_urc (void)
+{
+ common_test_missed_call_urc ("\r\nMISSED_CALL: 11:01AM 07712345678\r\n", "11:01AM 07712345678");
+}
+
+/*****************************************************************************/
+
+static void
common_test_cring_urc (const gchar *urc,
const gchar *expected_type)
{
@@ -315,6 +351,8 @@ int main (int argc, char **argv)
g_test_add_func ("/MM/simtech/voicecall/urc/end", test_voice_call_end_urc);
g_test_add_func ("/MM/simtech/voicecall/urc/end-duration", test_voice_call_end_duration_urc);
+ g_test_add_func ("/MM/simtech/missedcall/urc", test_missed_call_urc);
+
g_test_add_func ("/MM/simtech/cring/urc/two-crs", test_cring_urc_two_crs);
g_test_add_func ("/MM/simtech/cring/urc/one-cr", test_cring_urc_one_cr);