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
This commit is contained in:
Supreeth Herle 2020-03-24 10:19:15 +01:00
parent bf5d602588
commit 441c4a768f
1 changed files with 22 additions and 0 deletions

View File

@ -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