diff options
author | Supreeth Herle <herlesupreeth@gmail.com> | 2020-04-20 13:28:31 +0200 |
---|---|---|
committer | Supreeth Herle <herlesupreeth@gmail.com> | 2020-04-27 12:29:00 +0200 |
commit | 0c4d82d84a74c2de9ef5e08119f5c3bfe8789c08 (patch) | |
tree | 8ef5730cb06cf734c8ded214c58c92f1a91cbc5c /pySim | |
parent | 3e6f16d8f6686cb4e2cd2a2053a6c6aad98feaa4 (diff) |
utils.py: Add helper method to parse and print Service Table
This method helps in printing Service Tables in EF.SST, EF.UST, EF.IST.
Takes hex string of Service table, parses it and prints available service along with its description.
Change-Id: Ie1e82e07ead2e28314a5794661e6b2ced0acd72a
Diffstat (limited to 'pySim')
-rw-r--r-- | pySim/utils.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pySim/utils.py b/pySim/utils.py index 51f2954..be670e9 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -347,3 +347,34 @@ def parse_st(st): avail_srvc.append((8*i) + j) byte = byte >> 1 return avail_srvc + +def dec_st(st, table="sim"): + """ + Parses the EF S/U/IST and prints the list of available services in EF S/U/IST + """ + + if table == "usim": + from pySim.ts_31_102 import EF_UST_map + lookup_map = EF_UST_map + else: + from pySim.ts_51_011 import EF_SST_map + lookup_map = EF_SST_map + + st_bytes = [st[i:i+2] for i in range(0, len(st), 2) ] + + avail_st = "" + # 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 and ((8*i) + j in lookup_map): + # Byte X contains info about Services num (8X-7) to num (8X) + # bit = 1: service available + # bit = 0: service not available + avail_st += '\tService %d - %s\n' % ((8*i) + j, lookup_map[(8*i) + j]) + byte = byte >> 1 + return avail_st |