From fcd393a6c2a6faeb09cd7ae3ee60addef7ac3e2c Mon Sep 17 00:00:00 2001 From: Sven Schwermer Date: Fri, 9 Sep 2022 13:24:01 +0200 Subject: [PATCH] quectel: Trigger reprobe upon RDY URC Apparent self-resets without re-enumeration have been observed on Quectel modems EC21 and EG91. See #285 and https://lists.freedesktop.org/archives/modemmanager-devel/2022-September/009407.html Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/285 Signed-off-by: Sven Schwermer --- plugins/quectel/mm-shared-quectel.c | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/plugins/quectel/mm-shared-quectel.c b/plugins/quectel/mm-shared-quectel.c index c383dc05..47d7cd33 100644 --- a/plugins/quectel/mm-shared-quectel.c +++ b/plugins/quectel/mm-shared-quectel.c @@ -56,6 +56,7 @@ typedef struct { FeatureSupport qgps_supported; GRegex *qgpsurc_regex; GRegex *qlwurc_regex; + GRegex *rdy_regex; } Private; static void @@ -63,6 +64,7 @@ private_free (Private *priv) { g_regex_unref (priv->qgpsurc_regex); g_regex_unref (priv->qlwurc_regex); + g_regex_unref (priv->rdy_regex); g_slice_free (Private, priv); } @@ -83,6 +85,11 @@ get_private (MMSharedQuectel *self) priv->qgps_supported = FEATURE_SUPPORT_UNKNOWN; priv->qgpsurc_regex = g_regex_new ("\\r\\n\\+QGPSURC:.*", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); priv->qlwurc_regex = g_regex_new ("\\r\\n\\+QLWURC:.*", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + priv->rdy_regex = g_regex_new ("\\r\\nRDY", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); + + g_assert (priv->qgpsurc_regex); + g_assert (priv->qlwurc_regex); + g_assert (priv->rdy_regex); g_assert (MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_broadband_modem_class); priv->broadband_modem_class_parent = MM_SHARED_QUECTEL_GET_INTERFACE (self)->peek_parent_broadband_modem_class (self); @@ -98,6 +105,23 @@ get_private (MMSharedQuectel *self) return priv; } +/*****************************************************************************/ +/* RDY unsolicited event handler */ + +static void +rdy_handler (MMPortSerialAt *port, + GMatchInfo *match_info, + MMBroadbandModem *self) +{ + /* The RDY URC indicates a modem reset that may or may not go hand-in-hand + * with USB re-enumeration. For the latter case, we must make sure to + * re-synchronize modem and ModemManager states by re-probing. + */ + mm_obj_warn (self, "modem reset detected, triggering reprobe"); + mm_base_modem_set_reprobe (MM_BASE_MODEM (self), TRUE); + mm_base_modem_set_valid (MM_BASE_MODEM (self), FALSE); +} + /*****************************************************************************/ /* Setup ports (Broadband modem class) */ @@ -134,6 +158,14 @@ mm_shared_quectel_setup_ports (MMBroadbandModem *self) ports[i], priv->qlwurc_regex, NULL, NULL, NULL); + + /* Handle RDY */ + mm_port_serial_at_add_unsolicited_msg_handler ( + ports[i], + priv->rdy_regex, + (MMPortSerialAtUnsolicitedMsgFn)rdy_handler, + self, + NULL); } }