summaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorColin Helliwell <colin.helliwell@ln-systems.com>2018-01-01 18:36:11 +0100
committerAleksander Morgado <aleksander@aleksander.es>2018-01-01 18:37:10 +0100
commit8f26848ef00b343a15904bf7f8cd1a77de795b3e (patch)
tree225e51e5192875b62b4a6ca655398c2f1a5c07d6 /src/mm-modem-helpers.c
parent850107acbfe3878326b695d4ea31f02d2321aa22 (diff)
downloadModemManager-8f26848ef00b343a15904bf7f8cd1a77de795b3e.tar.gz
helpers: move generic load_unlock_retries from Telit plugin
As a precursor to a generic load_unlock_retries method, move the CSIM Response parser from the Telit plugin into the core code.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index b2806dfad..dce7e795d 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -4238,3 +4238,88 @@ mm_parse_cclk_response (const char *response,
return ret;
}
+
+/*****************************************************************************/
+/* +CSIM response parser */
+#define MM_MIN_SIM_RETRY_HEX 0x63C0
+#define MM_MAX_SIM_RETRY_HEX 0x63CF
+
+gint
+mm_parse_csim_response (const gchar *response,
+ GError **error)
+{
+ GMatchInfo *match_info = NULL;
+ GRegex *r = NULL;
+ gchar *str_code = NULL;
+ gint retries = -1;
+ guint hex_code;
+ GError *inner_error = NULL;
+
+ r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*\".*([0-9a-fA-F]{4})\"", G_REGEX_RAW, 0, NULL);
+ g_regex_match (r, response, 0, &match_info);
+
+ if (!g_match_info_matches (match_info)) {
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Could not recognize +CSIM response '%s'", response);
+ goto out;
+ }
+
+ str_code = mm_get_string_unquoted_from_match_info (match_info, 1);
+ if (str_code == NULL) {
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Could not find expected string code in response '%s'", response);
+ goto out;
+ }
+
+ if (!mm_get_uint_from_hex_str (str_code, &hex_code)) {
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Could not recognize expected hex code in response '%s'", response);
+ goto out;
+ }
+
+ switch (hex_code) {
+ case 0x6300:
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "SIM verification failed");
+ goto out;
+ case 0x6983:
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "SIM authentication method blocked");
+ goto out;
+ case 0x6984:
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "SIM reference data invalidated");
+ goto out;
+ case 0x6A86:
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Incorrect parameters in SIM request");
+ goto out;
+ case 0x6A88:
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "SIM reference data not found");
+ goto out;
+ default:
+ break;
+ }
+
+ if (hex_code < MM_MIN_SIM_RETRY_HEX || hex_code > MM_MAX_SIM_RETRY_HEX) {
+ inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Unknown error returned '0x%04x'", hex_code);
+ goto out;
+ }
+
+ retries = (gint)(hex_code - MM_MIN_SIM_RETRY_HEX);
+
+out:
+ g_regex_unref (r);
+ g_match_info_free (match_info);
+ g_free (str_code);
+
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return -1;
+ }
+
+ g_assert (retries >= 0);
+ return retries;
+}