laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/17896 
)

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

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

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



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

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ie1e82e07ead2e28314a5794661e6b2ced0acd72a
Gerrit-Change-Number: 17896
Gerrit-PatchSet: 2
Gerrit-Owner: herlesupreeth <herlesupre...@gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-MessageType: merged

Reply via email to