herlesupreeth has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/17668 )


Change subject: utils.py: Add helper method to parse Service Table
......................................................................

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
---
M pySim/utils.py
1 file changed, 22 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/68/17668/1

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

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/17668
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I9b72efdb84ba7be4a40928a008a59c67f6fb71d4
Gerrit-Change-Number: 17668
Gerrit-PatchSet: 1
Gerrit-Owner: herlesupreeth <herlesupre...@gmail.com>
Gerrit-MessageType: newchange

Reply via email to