From 24f9309d6ecd559d24c54391fadef76cdbde1097 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 16 May 2025 11:19:59 -0500 Subject: serial-parsers,port-serial-at: move echo removal into serial parser Mainly because we need somewhere to stash the call end regex, and it's silly to have a 3rd instance of that in MMPortSerialAt when we already have one in the serial parsers that MMPortSerialAt relies on pretty heavily. Signed-off-by: Dan Williams --- src/tests/test-at-serial-port.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/tests/test-at-serial-port.c') diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c index 5372c478..5592971d 100644 --- a/src/tests/test-at-serial-port.c +++ b/src/tests/test-at-serial-port.c @@ -89,6 +89,7 @@ at_serial_echo_removal (void) guint i; for (i = 0; i < G_N_ELEMENTS (echo_removal_tests); i++) { + gpointer parser; GByteArray *ba; /* Note that we add last NUL also to the byte array, so that we can compare @@ -98,7 +99,9 @@ at_serial_echo_removal (void) (guint8 *)echo_removal_tests[i].original, strlen (echo_removal_tests[i].original) + 1); - mm_port_serial_at_remove_echo (ba); + parser = mm_serial_parser_v1_new (); + mm_serial_parser_v1_remove_echo (parser, ba); + mm_serial_parser_v1_destroy (parser); g_assert_cmpstr ((gchar *)ba->data, ==, echo_removal_tests[i].without_echo); @@ -119,6 +122,7 @@ _run_parse_test (const ParseResponseTest tests[], guint number_of_tests) parser = mm_serial_parser_v1_new (); response = g_string_new (tests[i].response); found = mm_serial_parser_v1_parse (parser, response, NULL, &error); + mm_serial_parser_v1_destroy (parser); /* Verify if we expect a match or not */ g_assert_cmpint (found, ==, tests[i].found); -- cgit v1.2.3-70-g09d2 From c3c6fdc55e5a45f9bf0611ec0925fd0702aff316 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 16 May 2025 11:21:01 -0500 Subject: serial-parsers: don't echo-remove strange call start/end URCs Some Sierra devices omit the leading from call start/end URCs like NO CARRIER and CONNECT, which caused the echo-removal code to remove from the response buffer because the leading did not exist. That can break call control and hangup handling on those devices. Signed-off-by: Dan Williams --- src/mm-modem-helpers.c | 6 +++++- src/mm-serial-parsers.c | 36 ++++++++++++++++++++++++++++++++---- src/tests/test-at-serial-port.c | 2 ++ 3 files changed, 39 insertions(+), 5 deletions(-) (limited to 'src/tests/test-at-serial-port.c') diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index c6fa13fc..d69951be 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -487,8 +487,12 @@ mm_call_end_regex_get (void) { /* Example: * NO ANSWER + * NO CARRIER + * BUSY + * + * Some Sierra devices omit the leading for in-call responses. */ - return g_regex_new ("\\r\\n(NO CARRIER)|(BUSY)|(NO ANSWER)|(NO DIALTONE)\\r\\n", + return g_regex_new ("(\\r)?\\n(NO CARRIER)|(BUSY)|(NO ANSWER)|(NO DIALTONE)\\r\\n", G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); diff --git a/src/mm-serial-parsers.c b/src/mm-serial-parsers.c index d8dc1e5d..0823afac 100644 --- a/src/mm-serial-parsers.c +++ b/src/mm-serial-parsers.c @@ -17,8 +17,11 @@ #include #include +#define _LIBMM_INSIDE_MM + #include "mm-error-helpers.h" #include "mm-serial-parsers.h" +#include "mm-modem-helpers.h" #include "mm-log-object.h" /* Clean up the response by removing control characters like etc */ @@ -92,7 +95,8 @@ typedef struct { GRegex *regex_cms_error_str; GRegex *regex_ezx_error; GRegex *regex_unknown_error; - GRegex *regex_connect_failed; + GRegex *regex_call_start; + GRegex *regex_call_end; GRegex *regex_na; GRegex *regex_custom_error; /* User-provided parser filter */ @@ -117,7 +121,8 @@ mm_serial_parser_v1_new (void) parser->regex_cms_error_str = g_regex_new ("\\r\\n\\+CMS ERROR:\\s*([^\\n\\r]+)\\r\\n", flags, 0, NULL); parser->regex_ezx_error = g_regex_new ("\\r\\nMODEM ERROR:\\s*(\\d+)\\r\\n", flags, 0, NULL); parser->regex_unknown_error = g_regex_new ("\\r\\n(ERROR)|(COMMAND NOT SUPPORT)\\r\\n", flags, 0, NULL); - parser->regex_connect_failed = g_regex_new ("\\r\\n(NO CARRIER)|(BUSY)|(NO ANSWER)|(NO DIALTONE)\\r\\n", flags, 0, NULL); + parser->regex_call_start = g_regex_new ("(\\r)?\\n(CONNECT)\\r\\n", flags, 0, NULL); + parser->regex_call_end = mm_call_end_regex_get (); /* Samsung Z810 may reply "NA" to report a not-available error */ parser->regex_na = g_regex_new ("\\r\\nNA\\r\\n", flags, 0, NULL); @@ -164,11 +169,33 @@ void mm_serial_parser_v1_remove_echo (gpointer data, GByteArray *response) { + MMSerialParserV1 *parser = (MMSerialParserV1 *) data; guint i; if (response->len <= 2) return; + /* Some devices omit the leading from call end responses which would + * otherwise fail the checks below and be removed. We want to leave + * them in the response. + */ + if (g_regex_match_full (parser->regex_call_end, + (const gchar *) response->data, + response->len, + 0, + 0, + NULL, + NULL)) + return; + if (g_regex_match_full (parser->regex_call_start, + (const gchar *) response->data, + response->len, + 0, + 0, + NULL, + NULL)) + return; + for (i = 0; i < (response->len - 1); i++) { /* If there is any content before the first * , assume it's echo or garbage, and skip it */ @@ -337,7 +364,7 @@ mm_serial_parser_v1_parse (gpointer data, g_clear_pointer (&match_info, g_match_info_free); /* Connection failures */ - found = g_regex_match_full (parser->regex_connect_failed, + found = g_regex_match_full (parser->regex_call_end, response->str, response->len, 0, 0, &match_info, NULL); if (found) { @@ -417,7 +444,8 @@ mm_serial_parser_v1_destroy (gpointer data) g_regex_unref (parser->regex_cms_error_str); g_regex_unref (parser->regex_ezx_error); g_regex_unref (parser->regex_unknown_error); - g_regex_unref (parser->regex_connect_failed); + g_regex_unref (parser->regex_call_start); + g_regex_unref (parser->regex_call_end); g_regex_unref (parser->regex_na); if (parser->regex_custom_successful) diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c index 5592971d..bd608461 100644 --- a/src/tests/test-at-serial-port.c +++ b/src/tests/test-at-serial-port.c @@ -46,6 +46,8 @@ static const EchoRemovalTest echo_removal_tests[] = { { "echo echo\r\nthis is valid\r\nand so is this", "\r\nthis is valid\r\nand so is this" }, { "\r\nthis is valid\r\nand so is this", "\r\nthis is valid\r\nand so is this" }, { "\r\nthis is valid\r\nand so is this\r\n", "\r\nthis is valid\r\nand so is this\r\n" }, + { "\nNO CARRIER\r\n", "\nNO CARRIER\r\n" }, + { "\nCONNECT\r\n", "\nCONNECT\r\n" }, }; static const ParseResponseTest parse_ok_tests[] = { -- cgit v1.2.3-70-g09d2