Fix computation of SMSP from a SMSC number

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
Sylvain Munaut 2011-12-08 20:16:43 +01:00
parent 1a914439b8
commit 607ce2a029
2 changed files with 31 additions and 8 deletions

View File

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

View File

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