aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2013-07-04 17:33:33 +0400
committerSylvain Munaut <tnt@246tNt.com>2013-07-13 08:49:03 +0200
commit5e96c3d910fbec87f699d16ff25b87018a4a687a (patch)
treed3b2732cc0425fa941341c8bc310734964297754
parent21885249cfb777f299c36b6def8bb768f61942a3 (diff)
utils: Add functions to decode IMSI and ICCID from EF raw data.
-rw-r--r--pySim/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py
index d8b9518..12ae94e 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -42,3 +42,20 @@ def rpad(s, l, c='f'):
def lpad(s, l, c='f'):
return c * (l - len(s)) + s
+
+def dec_imsi(ef):
+ """Converts an EF value to the imsi string representation"""
+ if len(ef) < 4:
+ return None
+ l = int(ef[0:2]) * 2 # Length of the IMSI string
+ swapped = swap_nibbles(ef[2:])
+ oe = (int(swapped[0])>>3) & 1 # Odd (1) / Even (0)
+ if oe:
+ l = l-1
+ if l+1 > len(swapped):
+ return None
+ imsi = swapped[1:l+2]
+ return imsi
+
+def dec_iccid(ef):
+ return swap_nibbles(ef).strip('f')