aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2013-09-26 11:07:16 -0700
committerAleksander Morgado <aleksander@lanedo.com>2013-09-26 20:23:51 +0200
commitb5ef861d12c7533d89a18454b03e8e3301164bea (patch)
treed49cbf5d285f623de42879a271c0b388dba4a8b1 /src/mm-modem-helpers.c
parentb786ac0debc7aa5e9a6b0f00bd61e15d9daea049 (diff)
modem-helpers,sim: auto-detect if ICCID response is character swapped
This patch modifies mm_3gpp_parse_iccid() to auto-detect if an ICCID response is character swapped or not by comparsing the major industry identifier part of the ICCID response to the known value (89) for telecommunication purposes. This addresses the issue where the same AT command (e.g. AT^ICCID used by the huawei plugin) does not report ICCID in a consistent format.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index cf80f07b..9c86ebc2 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -1892,8 +1892,9 @@ mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type)
/*************************************************************************/
char *
-mm_3gpp_parse_iccid (const char *raw_iccid, gboolean swap, GError **error)
+mm_3gpp_parse_iccid (const char *raw_iccid, GError **error)
{
+ gboolean swap;
char *buf, *swapped = NULL;
gsize len = 0;
int f_pos = -1, i;
@@ -1934,6 +1935,22 @@ mm_3gpp_parse_iccid (const char *raw_iccid, gboolean swap, GError **error)
goto error;
}
+ /* The leading two digits of an ICCID is the major industry identifier and
+ * should be '89' for telecommunication purposes according to ISO/IEC 7812.
+ */
+ if (buf[0] == '8' && buf[1] == '9') {
+ swap = FALSE;
+ } else if (buf[0] == '9' && buf[1] == '8') {
+ swap = TRUE;
+ } else {
+ /* FIXME: Instead of erroring out, revisit this solution if we find any SIM
+ * that doesn't use '89' as the major industry identifier of the ICCID.
+ */
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "Invalid ICCID response (leading two digits are not 89)");
+ goto error;
+ }
+
/* Ensure if there's an 'F' that it's second-to-last if swap = TRUE,
* otherwise last if swap = FALSE */
if (f_pos >= 0) {