Uhm, sorry, not the right patch. Please ignore<div><br>Carlo</div><br>Il martedì 4 aprile 2017, Carlo Lobrano <<a href="mailto:c.lobrano@gmail.com">c.lobrano@gmail.com</a>> ha scritto:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Refactored mm_telit_parse_csim_response in order to correctly recognize 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 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 bug<br>
because the very same request is accepted as correct when issued later,<br>
namely when the SIM is ready.<br>
<br>
---<br>
plugins/telit/mm-modem-<wbr>helpers-telit.c | 91 +++++++++++++++++------<br>
plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c | 44 +++++++----<br>
2 files changed, 98 insertions(+), 37 deletions(-)<br>
<br>
diff --git a/plugins/telit/mm-modem-<wbr>helpers-telit.c b/plugins/telit/mm-modem-<wbr>helpers-telit.c<br>
index c8c1f4b..f2568d8 100644<br>
--- a/plugins/telit/mm-modem-<wbr>helpers-telit.c<br>
+++ b/plugins/telit/mm-modem-<wbr>helpers-telit.c<br>
@@ -17,6 +17,7 @@<br>
#include <stdlib.h><br>
#include <string.h><br>
#include <stdio.h><br>
+#include <errno.h><br>
<br>
#include <ModemManager.h><br>
#define _LIBMM_INSIDE_MMCLI<br>
@@ -113,54 +114,96 @@ mm_telit_get_band_flag (GArray *bands_array,<br>
<br>
/*****************************<wbr>******************************<wbr>******************/<br>
/* +CSIM response parser */<br>
+#define MM_TELIT_MIN_SIM_RETRY_HEX 0x63C0<br>
+#define MM_TELIT_MAX_SIM_RETRY_HEX 0x63CF<br>
<br>
gint<br>
mm_telit_parse_csim_response (const guint step,<br>
const gchar *response,<br>
GError **error)<br>
{<br>
- GRegex *r = NULL;<br>
GMatchInfo *match_info = NULL;<br>
- gchar *retries_hex_str;<br>
- guint retries;<br>
+ GRegex *r = NULL;<br>
+ gchar *str_code = NULL;<br>
+ gint retries = -1;<br>
+ guint64 hex_code = 0x0;<br>
<br>
- r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*.*<wbr>63C(.*)\"", G_REGEX_RAW, 0, NULL);<br>
+ //TODO why do I need step?<br>
<br>
+ r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*.*([<wbr>0-9a-fA-F]{4})\"", G_REGEX_RAW, 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>
- "Could not parse reponse '%s'", response);<br>
- g_match_info_free (match_info);<br>
- g_regex_unref (r);<br>
- return -1;<br>
+ "Could not recognize response '%s'", response);<br>
+ goto out;<br>
}<br>
<br>
- if (!g_match_info_matches (match_info)) {<br>
+ if (match_info == NULL || !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'", response);<br>
- g_match_info_free (match_info);<br>
- g_regex_unref (r);<br>
- return -1;<br>
+ "Could not parse response '%s'", response);<br>
+ goto out;<br>
}<br>
<br>
- retries_hex_str = mm_get_string_unquoted_from_<wbr>match_info (match_info, 1);<br>
- g_assert (NULL != retries_hex_str);<br>
+ str_code = mm_get_string_unquoted_from_<wbr>match_info (match_info, 1);<br>
+ if (str_code == NULL) {<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Could not find expected string code in response '%s'", response);<br>
+ goto out;<br>
+ }<br>
<br>
- /* convert hex value to uint */<br>
- if (sscanf (retries_hex_str, "%x", &retries) != 1) {<br>
- g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
- "Could not get retry value from match '%s'",<br>
- retries_hex_str);<br>
- g_match_info_free (match_info);<br>
- g_regex_unref (r);<br>
- return -1;<br>
+ errno = 0;<br>
+ hex_code = g_ascii_strtoull (str_code, NULL, 16);<br>
+ if (hex_code == G_MAXUINT64 && errno == ERANGE) {<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Could not recognize expected hex code in response '%s'", response);<br>
+ goto out;<br>
}<br>
<br>
- g_free (retries_hex_str);<br>
+ switch(hex_code) {<br>
+ case 0x6300:<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "SIM verification failed");<br>
+ break;<br>
+ case 0x6983:<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "SIM authentication method blocked");<br>
+ break;<br>
+ case 0x6984:<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "SIM reference data invalidated");<br>
+ break;<br>
+ case 0x6A86:<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "Incorrect parameters in SIM request");<br>
+ break;<br>
+ case 0x6A88:<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "SIM reference data not found");<br>
+ break;<br>
+ default:<br>
+ break;<br>
+ }<br>
+<br>
+ if (g_error_matches (*error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED)) {<br>
+ goto out;<br>
+ }<br>
+<br>
+ if (hex_code < MM_TELIT_MIN_SIM_RETRY_HEX || hex_code > MM_TELIT_MAX_SIM_RETRY_HEX) {<br>
+ // TODO unittest<br>
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,<br>
+ "SIM retries out of bound in response '%s'", response);<br>
+ } else {<br>
+ retries = (gint)(hex_code - MM_TELIT_MIN_SIM_RETRY_HEX);<br>
+ }<br>
+<br>
+out:<br>
+ if (str_code != NULL)<br>
+ g_free (str_code);<br>
g_match_info_free (match_info);<br>
g_regex_unref (r);<br>
<br>
return retries;<br>
}<br>
+<br>
#define SUPP_BAND_RESPONSE_REGEX "#BND:\\s*\\((?P<Bands2G>[0-9\<wbr>\-,]*)\\)(,\\s*\\((?P<Bands3G><wbr>[0-9\\-,]*)\\))?(,\\s*\\((?P<<wbr>Bands4G>[0-9\\-,]*)\\))?"<br>
#define CURR_BAND_RESPONSE_REGEX "#BND:\\s*(?P<Bands2G>\\d+)(,\<wbr>\s*(?P<Bands3G>\\d+))?(,\\s*(?<wbr>P<Bands4G>\\d+))?"<br>
<br>
diff --git a/plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c b/plugins/telit/tests/test-mm-<wbr>modem-helpers-telit.c<br>
index 40e3628..3d902b2 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 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, \"69FF\"", -1, "Could not parse response '+CSIM: 4, \"69FF\"'"},<br>
+ {"+CSIM: 4, \"6A86\"", -1, "Incorrect parameters in SIM request"},<br>
+ {"+CSIM: 4, \"6A88\"", -1, "SIM reference data not found"},<br>
+ {"+CSIM: 4, \"6AFF\"", -1, "Could not parse response '+CSIM: 4, \"6AFF\"'"},<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, "Could not recognize response '+CSIM: 8, xxxx63CF'"},<br>
/* Negative test for substring "63Cx" */<br>
- {"+CSIM: 4, xxxx73CF\"", -1},<br>
+ {"+CSIM: 4, xxxx73CF\"", -1, "Could not parse response '+CSIM: 4, xxxx73CF\"'"},<br>
/* Test missing first argument */<br>
- {"+CSIM:xxxx63CF\"", -1},<br>
+ {"+CSIM:xxxx63CF\"", -1, "Could not recognize response '+CSIM:xxxx63CF\"'"},<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; i++) {<br>
res = mm_telit_parse_csim_response (step, 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>
+ g_assert_no_error (error);<br>
+ } else {<br>
+ g_assert_cmpstr (error->message, ==, valid_csim_response_test_list[<wbr>i].error_message);<br>
+ g_error_free (error);<br>
+ error = NULL;<br>
+ }<br>
+<br>
g_assert_cmpint (res, ==, valid_csim_response_test_list[<wbr>i].result);<br>
}<br>
<br>
@@ -82,6 +99,7 @@ test_mm_telit_parse_csim_<wbr>response (void)<br>
res = mm_telit_parse_csim_response (step, invalid_csim_response_test_<wbr>list[i].response, &error);<br>
<br>
g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED);<br>
+ g_assert_cmpstr (error->message, ==, invalid_csim_response_test_<wbr>list[i].error_message);<br>
g_assert_cmpint (res, ==, invalid_csim_response_test_<wbr>list[i].result);<br>
<br>
if (NULL != error) {<br>
--<br>
2.7.4<br>
<br>
</blockquote>