Sure, good point!<div><br><div>At least for the error codes it's easy, I'll think something for the hex with the retry value as well.</div><div>I'll update the patch</div><div><br></div><div>Carlo<br><br>Il lunedì 3 aprile 2017, Dan Williams <<a href="mailto:dcbw@redhat.com">dcbw@redhat.com</a>> ha scritto:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, 2017-04-03 at 17:01 +0200, Carlo Lobrano wrote:<br>
> Updated mm_telit_parse_csim_response in order to correctly recognize<br>
> the<br>
> following +CSIM error codes:<br>
><br>
> * 6300 - Verification failed<br>
> * 6983 - Authentication method blocked<br>
> * 6984 - Reference data invalidated<br>
> * 6A86 - Incorrect parameters<br>
> * 6A88 - Reference data not found<br>
><br>
> Fixes: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=100374" target="_blank">https://bugs.freedesktop.org/<wbr>show_bug.cgi?id=100374</a><br>
> ---<br>
><br>
> As a side note, I observed that sometimes the modem replies with<br>
> error<br>
> code<br>
><br>
> 6A86 - Incorrect parameters<br>
><br>
> when #QSS: 3 has not been received yet. This seems to be a modem's<br>
> bug<br>
> because the very same request is accepted as correct when issued<br>
> later,<br>
> namely when the SIM is ready.<br>
><br>
> ---<br>
> plugins/telit/mm-modem-<wbr>helpers-telit.c | 96<br>
> ++++++++++++++++++++---<br>
> plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c | 43 +++++++---<br>
> 2 files changed, 113 insertions(+), 26 deletions(-)<br>
><br>
> diff --git a/plugins/telit/mm-modem-<wbr>helpers-telit.c<br>
> b/plugins/telit/mm-modem-<wbr>helpers-telit.c<br>
> index c8c1f4b..cc8cf0a 100644<br>
> --- a/plugins/telit/mm-modem-<wbr>helpers-telit.c<br>
> +++ b/plugins/telit/mm-modem-<wbr>helpers-telit.c<br>
> @@ -121,45 +121,115 @@ mm_telit_parse_csim_response (const guint<br>
> step,<br>
> {<br>
> GRegex *r = NULL;<br>
> GMatchInfo *match_info = NULL;<br>
> - gchar *retries_hex_str;<br>
> - guint retries;<br>
> + gchar *error_code = NULL;<br>
> + gchar *retries_hex_str = NULL;<br>
> + gint rtv = -1;<br>
> <br>
> + /* Check for error codes */<br>
> + r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*.*<wbr>6300\"", G_REGEX_RAW,<br>
> 0, NULL);<br>
> + if (g_regex_match (r, response, 0, &match_info)) {<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "SIM verification failed");<br>
> + goto out;<br>
> + }<br>
<br>
Can we do a single regex, capture the 4-hex-character response as part<br>
of the regex, run g_ascii_strtoull() on it to get a uint, and then use<br>
switch() to compare to known error codes instead?<br>
<br>
Dan<br>
<br>
> + g_match_info_free (match_info);<br>
> + match_info = NULL;<br>
> + g_regex_unref (r);<br>
> + r = NULL;<br>
> +<br>
> + r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*.*69(<wbr>.*)\"",<br>
> G_REGEX_RAW, 0, NULL);<br>
> + if (g_regex_match (r, response, 0, &match_info) &&<br>
> + match_info != NULL &&<br>
> + g_match_info_matches (match_info)) {<br>
> + error_code = mm_get_string_unquoted_from_<wbr>match_info<br>
> (match_info, 1);<br>
> +<br>
> + if (error_code == NULL) {<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "<wbr>Could not parse CSIM error code in<br>
> response '%s'",<br>
> + <wbr>response);<br>
> + } else if (strstr (error_code, "83") != NULL) {<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "SIM authentication method blocked");<br>
> + } else if (strstr (error_code, "84") != NULL) {<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "SIM reference data invalidated");<br>
> + } else {<br>
> + g_set_error (error, MM_CORE_ERROR,<br>
> MM_CORE_ERROR_FAILED,<br>
> + "<wbr>Unknown error code '69%s'", error_code);<br>
> + }<br>
> +<br>
> + goto out;<br>
> + }<br>
> +<br>
> + g_match_info_free (match_info);<br>
> + match_info = NULL;<br>
> + g_regex_unref (r);<br>
> + r = NULL;<br>
> +<br>
> + r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*.*6A(<wbr>.*)\"",<br>
> G_REGEX_RAW, 0, NULL);<br>
> + if (g_regex_match (r, response, 0, &match_info) &&<br>
> + match_info != NULL &&<br>
> + g_match_info_matches (match_info)) {<br>
> + error_code = mm_get_string_unquoted_from_<wbr>match_info<br>
> (match_info, 1);<br>
> +<br>
> + if (error_code == NULL) {<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "<wbr>Could not parse CSIM error code in<br>
> response '%s'",<br>
> + <wbr>response);<br>
> + } else if (strstr (error_code, "86") != NULL) {<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "<wbr>Incorrect parameters in SIM request");<br>
> + } else if (strstr (error_code, "88") != NULL) {<br>
> + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> + "SIM reference data not found");<br>
> + } else {<br>
> + g_set_error (error, MM_CORE_ERROR,<br>
> MM_CORE_ERROR_FAILED,<br>
> + "<wbr>Unknown error code '6A%s'", error_code);<br>
> + }<br>
> +<br>
> + goto out;<br>
> + }<br>
> +<br>
> + g_match_info_free (match_info);<br>
> + match_info = NULL;<br>
> + g_regex_unref (r);<br>
> + r = NULL;<br>
> +<br>
> + /* No errors found. Get SIM retries */<br>
> r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*.*<wbr>63C(.*)\"",<br>
> G_REGEX_RAW, 0, NULL);<br>
> <br>
> if (!g_regex_match (r, response, 0, &match_info)) {<br>
> g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> "Could not parse reponse '%s'", response);<br>
> - g_match_info_free (match_info);<br>
> - g_regex_unref (r);<br>
> - return -1;<br>
> + goto out;<br>
> }<br>
> <br>
> if (!g_match_info_matches (match_info)) {<br>
> g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> "Could not find matches in response '%s'",<br>
> response);<br>
> - g_match_info_free (match_info);<br>
> - g_regex_unref (r);<br>
> - return -1;<br>
> + goto out;<br>
> }<br>
> <br>
> retries_hex_str = mm_get_string_unquoted_from_<wbr>match_info<br>
> (match_info, 1);<br>
> g_assert (NULL != retries_hex_str);<br>
> <br>
> /* convert hex value to uint */<br>
> - if (sscanf (retries_hex_str, "%x", &retries) != 1) {<br>
> + if (sscanf (retries_hex_str, "%x", &rtv) != 1) {<br>
> g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
> "Could not get retry value from match '%s'",<br>
> retries_<wbr>hex_str);<br>
> - g_match_info_free (match_info);<br>
> - g_regex_unref (r);<br>
> - return -1;<br>
> + goto out;<br>
> }<br>
> <br>
> g_free (retries_hex_str);<br>
> +<br>
> +out:<br>
> + g_free (error_code),<br>
> g_match_info_free (match_info);<br>
> g_regex_unref (r);<br>
> <br>
> - return retries;<br>
> + return rtv;<br>
> }<br>
> #define<br>
> SUPP_BAND_RESPONSE_REGEX <wbr> "#BND:\\s*\\((?P<Bands2G>[<wbr>0-9\\-<br>
> ,]*)\\)(,\\s*\\((?P<Bands3G>[<wbr>0-9\\-,]*)\\))?(,\\s*\\((?P<<wbr>Bands4G>[0-<br>
> 9\\-,]*)\\))?"<br>
> #define<br>
> CURR_BAND_RESPONSE_REGEX <wbr> "#BND:\\s*(?P<Bands2G>\\d+<wbr>)(,\\s*(?<br>
> P<Bands3G>\\d+))?(,\\s*(?P<<wbr>Bands4G>\\d+))?"<br>
> diff --git a/plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c<br>
> b/plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c<br>
> index 40e3628..4907ce5 100644<br>
> --- a/plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c<br>
> +++ b/plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c<br>
> @@ -28,36 +28,46 @@<br>
> typedef struct {<br>
> gchar *response;<br>
> gint result;<br>
> + gchar *error_message;<br>
> } CSIMResponseTest;<br>
> <br>
> static CSIMResponseTest valid_csim_response_test_list [] = {<br>
> /* The parser expects that 2nd arg contains<br>
> * substring "63Cx" where x is an HEX string<br>
> * representing the retry value */<br>
> - {"+CSIM:8,\"xxxx63C1\"", 1},<br>
> - {"+CSIM:8,\"xxxx63CA\"", 10},<br>
> - {"+CSIM:8,\"xxxx63CF\"", 15},<br>
> + {"+CSIM:8,\"xxxx63C1\"", 1, NULL},<br>
> + {"+CSIM:8,\"xxxx63CA\"", 10, NULL},<br>
> + {"+CSIM:8,\"xxxx63CF\"", 15, NULL},<br>
> /* The parser accepts spaces */<br>
> - {"+CSIM:8,\"xxxx63C1\"", 1},<br>
> - {"+CSIM:8, \"xxxx63C1\"", 1},<br>
> - {"+CSIM: 8, \"xxxx63C1\"", 1},<br>
> - {"+CSIM: 8, \"xxxx63C1\"", 1},<br>
> + {"+CSIM:8,\"xxxx63C1\"", 1, NULL},<br>
> + {"+CSIM:8, \"xxxx63C1\"", 1, NULL},<br>
> + {"+CSIM: 8, \"xxxx63C1\"", 1, NULL},<br>
> + {"+CSIM: 8, \"xxxx63C1\"", 1, NULL},<br>
> /* the parser expects an int as first argument (2nd arg's<br>
> length),<br>
> * but does not check if it is correct */<br>
> - {"+CSIM: 10, \"63CF\"", 15},<br>
> + {"+CSIM: 4, \"63CF\"", 15, NULL},<br>
> /* the parser expect a quotation mark at the end<br>
> * of the response, but not at the begin */<br>
> - {"+CSIM: 10, 63CF\"", 15},<br>
> + {"+CSIM: 4, 63CF\"", 15, NULL},<br>
> + {"+CSIM: 4, 63CF\"", 15, NULL},<br>
> + /* SIM Error codes */<br>
> + {"+CSIM: 4, \"6300\"", -1, "SIM verification failed"},<br>
> + {"+CSIM: 4, \"6983\"", -1, "SIM authentication method blocked"},<br>
> + {"+CSIM: 4, \"6984\"", -1, "SIM reference data invalidated"},<br>
> + {"+CSIM: 4, \"69XX\"", -1, "Unknown error code '69XX'"},<br>
> + {"+CSIM: 4, \"6A86\"", -1, "Incorrect parameters in SIM<br>
> request"},<br>
> + {"+CSIM: 4, \"6A88\"", -1, "SIM reference data not found"},<br>
> + {"+CSIM: 4, \"6AXX\"", -1, "Unknown error code '6AXX'"},<br>
> { NULL, -1}<br>
> };<br>
> <br>
> static CSIMResponseTest invalid_csim_response_test_<wbr>list [] = {<br>
> /* Test missing final quotation mark */<br>
> - {"+CSIM: 8, xxxx63CF", -1},<br>
> + {"+CSIM: 8, xxxx63CF", -1, NULL},<br>
> /* Negative test for substring "63Cx" */<br>
> - {"+CSIM: 4, xxxx73CF\"", -1},<br>
> + {"+CSIM: 4, xxxx73CF\"", -1, NULL},<br>
> /* Test missing first argument */<br>
> - {"+CSIM:xxxx63CF\"", -1},<br>
> + {"+CSIM:xxxx63CF\"", -1, NULL},<br>
> { NULL, -1}<br>
> };<br>
> <br>
> @@ -73,7 +83,14 @@ test_mm_telit_parse_csim_<wbr>response (void)<br>
> for (i = 0; valid_csim_response_test_list[<wbr>i].response != NULL;<br>
> i++) {<br>
> res = mm_telit_parse_csim_response (step,<br>
> valid_csim_response_test_list[<wbr>i].response, &error);<br>
> <br>
> - g_assert_no_error (error);<br>
> + if (valid_csim_response_test_<wbr>list[i].error_message == NULL)<br>
> {<br>
> + g_assert_no_error (error);<br>
> + } else {<br>
> + g_assert_cmpstr (error->message, ==,<br>
> valid_csim_response_test_list[<wbr>i].error_message);<br>
> + g_error_free (error);<br>
> + error = NULL;<br>
> + }<br>
> +<br>
> g_assert_cmpint (res, ==,<br>
> valid_csim_response_test_list[<wbr>i].result);<br>
> }<br>
> <br>
</blockquote></div></div>