aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2017-07-18 16:48:47 +0300
committerAlexander Chemeris <Alexander.Chemeris@gmail.com>2018-01-10 14:04:11 +0900
commita5f0ea6979231dad97bfe357fdc9eb1cbaa2b511 (patch)
tree197dcab08d4b21c0574895c996749d1dee7b72bd
parent067f69cade29f08272d2b863986da57f3a186fa6 (diff)
utils: Functions to encode/decode EF SPN.
According to TS 51 011. Change-Id: Ida184bc5c81cc8c228b8981b703f77d017e53334
-rw-r--r--pySim/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py
index 84b613f..8463581 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -34,6 +34,12 @@ def h2i(s):
def i2h(s):
return ''.join(['%02x'%(x) for x in s])
+def h2s(s):
+ return ''.join([chr((int(x,16)<<4)+int(y,16)) for x,y in zip(s[0::2], s[1::2]) if not (x == 'f' and y == 'f') ])
+
+def s2h(s):
+ return b2h(s)
+
def swap_nibbles(s):
return ''.join([x+y for x,y in zip(s[1::2], s[0::2])])
@@ -73,3 +79,16 @@ def enc_iccid(iccid):
def enc_plmn(mcc, mnc):
"""Converts integer MCC/MNC into 6 bytes for EF"""
return swap_nibbles(lpad('%d' % mcc, 3) + lpad('%d' % mnc, 3))
+
+def dec_spn(ef):
+ byte1 = int(ef[0:2])
+ hplmn_disp = (byte1&0x01 == 0x01)
+ oplmn_disp = (byte1&0x02 == 0x02)
+ name = h2s(ef[2:])
+ return (name, hplmn_disp, oplmn_disp)
+
+def enc_spn(name, hplmn_disp=False, oplmn_disp=False):
+ byte1 = 0x00
+ if hplmn_disp: byte1 = byte1|0x01
+ if oplmn_disp: byte1 = byte1|0x02
+ return i2h([byte1])+s2h(name)