phcoder has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/41786?usp=email )


Change subject: Print SMSC in read mode
......................................................................

Print SMSC in read mode

Change-Id: I17067b68086316d51fd71ba77049874605594e3f
---
M pySim-read.py
M pySim/legacy/utils.py
2 files changed, 12 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/86/41786/1

diff --git a/pySim-read.py b/pySim-read.py
index 9829a15..ab2049b 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -43,7 +43,7 @@
 from pySim.exceptions import SwMatchError
 from pySim.legacy.cards import card_detect, SimCard, UsimCard, IsimCard
 from pySim.utils import dec_imsi, dec_iccid
-from pySim.legacy.utils import format_xplmn_w_act, dec_st, dec_msisdn
+from pySim.legacy.utils import format_xplmn_w_act, dec_st, dec_msisdn, 
dec_smsc_from_smsp

 option_parser = argparse.ArgumentParser(description='Legacy tool for reading 
some parts of a SIM card',
                                         
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
@@ -141,6 +141,7 @@
     (res, sw) = card.read_record('SMSP', 1)
     if sw == '9000':
         print("SMSP: %s" % (res,))
+        print("SMSC: %s" % (dec_smsc_from_smsp(res),))
     else:
         print("SMSP: Can't read, response code = %s" % (sw,))

diff --git a/pySim/legacy/utils.py b/pySim/legacy/utils.py
index 49c8633..f96e318 100644
--- a/pySim/legacy/utils.py
+++ b/pySim/legacy/utils.py
@@ -334,6 +334,16 @@
     return s


+def dec_smsc_from_smsp(smsp):
+    y = (len(smsp) // 2) - 28
+    if y <= 0:
+        return (None, sw)
+    tp_sca = smsp[((y+14)*2):((y+25)*2)]
+    prefix = '+' if tp_sca[0:2] == '91' else ''
+
+    return prefix + swap_nibbles(tp_sca[2:]).rstrip('f')
+
+
 def dec_msisdn(ef_msisdn: Hexstr) -> Optional[Tuple[int, int, Optional[str]]]:
     """
     Decode MSISDN from EF.MSISDN or EF.ADN (same structure).

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/41786?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I17067b68086316d51fd71ba77049874605594e3f
Gerrit-Change-Number: 41786
Gerrit-PatchSet: 1
Gerrit-Owner: phcoder <[email protected]>

Reply via email to