aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2011-12-08 20:16:43 +0100
committerSylvain Munaut <tnt@246tNt.com>2011-12-08 20:16:43 +0100
commit607ce2a029793278746f3f4ec54233daa8dc99b1 (patch)
tree559eb189b0480fb4126771aeb12ab883fd860807
parent1a914439b85665571fc9cb61de39e3e68b456c1f (diff)
Fix computation of SMSP from a SMSC number
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rwxr-xr-xpySim-prog.py35
-rw-r--r--pySim/cards.py4
2 files changed, 31 insertions, 8 deletions
diff --git a/pySim-prog.py b/pySim-prog.py
index aad68c0..9f240db 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -39,7 +39,7 @@ except ImportError:
from pySim.commands import SimCardCommands
from pySim.cards import _cards_classes
-from pySim.utils import h2b
+from pySim.utils import h2b, swap_nibbles, rpad
def parse_options():
@@ -83,9 +83,12 @@ def parse_options():
help="Mobile Network Code [default: %default]",
default=55,
)
- parser.add_option("-m", "--smsp", dest="smsp",
+ parser.add_option("-m", "--smsc", dest="smsc",
help="SMSP [default: '00 + country code + 5555']",
)
+ parser.add_option("-M", "--smsp", dest="smsp",
+ help="Raw SMSP content in hex [default: auto from SMSC]",
+ )
parser.add_option("-s", "--iccid", dest="iccid", metavar="ID",
help="Integrated Circuit Card ID",
@@ -155,6 +158,10 @@ def _cc_digits(cc):
def _isnum(s, l=-1):
return s.isdigit() and ((l== -1) or (len(s) == l))
+def _ishex(s, l=-1):
+ hc = '0123456789abcdef'
+ return all([x in hc for x in s.lower()]) and ((l== -1) or (len(s) == l))
+
def _dbi_binary_quote(s):
# Count usage of each char
@@ -265,11 +272,29 @@ def gen_parameters(opts):
# SMSP
if opts.smsp is not None:
smsp = opts.smsp
- if not _isnum(smsp):
- raise ValueError('SMSP must be digits only !')
+ if not _ishex(smsp):
+ raise ValueError('SMSP must be hex digits only !')
+ if len(smsp) < 28*2:
+ raise ValueError('SMSP must be at least 28 bytes')
else:
- smsp = '00%d' % opts.country + '5555' # Hack ...
+ if opts.smsc is not None:
+ smsc = opts.smsc
+ if not _isnum(smsc):
+ raise ValueError('SMSC must be digits only !')
+ else:
+ smsc = '00%d' % opts.country + '5555' # Hack ...
+
+ smsc = '%02d' % ((len(smsc) + 3)//2,) + "80" + swap_nibbles(rpad(smsc, 20))
+
+ smsp = (
+ 'e1' + # Parameters indicator
+ 'ff' * 12 + # TP-Destination address
+ smsc + # TP-Service Centre Address
+ '00' + # TP-Protocol identifier
+ '00' + # TP-Data coding scheme
+ '00' # TP-Validity period
+ )
# Ki (random)
if opts.ki is not None:
diff --git a/pySim/cards.py b/pySim/cards.py
index af83e78..cc7be17 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -240,9 +240,7 @@ class FakeMagicSim(Card):
self._e_iccid(p['iccid']) + # 10b ICCID
self._e_imsi(p['imsi']) + # 9b IMSI_len + id_type(9) + IMSI
p['ki'] + # 16b Ki
- 24*'f' + 'fd' + 24*'f' + # 25b (unknown ...)
- rpad(p['smsp'], 20) + # 10b SMSP (padded with ff if needed)
- 10*'f' # 5b (unknown ...)
+ rpad(p['smsp'], 80) # 40b SMSP (padded with ff if needed)
)
self._scc.update_record('000c', 1, entry)