diff options
author | Supreeth Herle <herlesupreeth@gmail.com> | 2020-03-24 10:19:15 +0100 |
---|---|---|
committer | Supreeth Herle <herlesupreeth@gmail.com> | 2020-04-01 11:06:59 +0200 |
commit | 441c4a768f2bbe7547673e302a7f8e3f95570b0a (patch) | |
tree | 0d2e5a9f13910c6c8ca5cde81d83b4c279cf6e9e /pySim | |
parent | bf5d602588d2ac7ffbe706e8f6a95711567e49d8 (diff) |
utils.py: Add helper method to parse Service Table
This method helps in parsing Service Tables in EF.SST, EF.UST, EF.EST, EF.IST.
Takes hex string as input and output a list of available/enabled services.
Change-Id: I9b72efdb84ba7be4a40928a008a59c67f6fb71d4
Diffstat (limited to 'pySim')
-rw-r--r-- | pySim/utils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py index c098384..51f2954 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -325,3 +325,25 @@ def enc_msisdn(msisdn, npi=0x01, ton=0x03): bcd = rpad(swap_nibbles(msisdn), 10 * 2) # pad to 10 octets return ('%02x' % bcd_len) + ('%02x' % npi_ton) + bcd + +def parse_st(st): + """ + Parses the EF S/U/IST and returns available/supported services + """ + st_bytes = [st[i:i+2] for i in range(0, len(st), 2) ] + avail_srvc = [] + # Get each byte and check for available services + for i in range(0, len(st_bytes)): + # Byte i contains info about Services num (8i+1) to num (8i+8) + byte = int(st_bytes[i], 16) + # Services in each byte are in order MSB to LSB + # MSB - Service (8i+8) + # LSB - Service (8i+1) + for j in range(1, 9): + if byte&0x01 == 0x01: + # Byte X contains info about Services num (8X-7) to num (8X) + # bit = 1: service available + # bit = 0: service not available + avail_srvc.append((8*i) + j) + byte = byte >> 1 + return avail_srvc |