mobile: adapt BCD number codec to support both NAS / MSISDN and SCCP / GT schemes

This commit is contained in:
mich 2019-07-02 11:27:40 +02:00
parent 6bcbd691c9
commit af18a03548
2 changed files with 20 additions and 13 deletions

View File

@ -132,6 +132,11 @@ class SrcLocalRef(Uint24):
# ITU-T Q.713, section 3.4 / 3.5
#------------------------------------------------------------------------------#
class SCCPBufBCD(BufBCD):
_chars = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '11', '12', '_', 'ST')
_filler = 0x0
# GTInd 0001
# section 3.4.2.3.1
@ -151,7 +156,7 @@ class _GlobalTitle0001(Envelope):
_GEN = (
Uint('OE', bl=1, dic={0:'even number of address signals', 1:'odd number of address signals'}),
Uint('NAI', val=1, bl=7, dic=_GTNAI_dict),
BufBCD('Addr', val=b'')
SCCPBufBCD('Addr', val=b'')
)
@ -194,8 +199,8 @@ class _GlobalTitle0011(Envelope):
Uint('NumberingPlan', val=1, bl=4, dic=_NumPlan_dict),
Uint('EncodingScheme', val=1, bl=4, dic=_EncScheme_dict),
Alt('Addr', GEN={
1 : BufBCD('BCD', val=b''),
2 : BufBCD('BCD', val=b'')},
1 : SCCPBufBCD('BCD', val=b''),
2 : SCCPBufBCD('BCD', val=b'')},
DEFAULT=Buf('Raw', val=b'', rep=REPR_HEX),
sel=lambda self: self.get_env()[2].get_val())
)
@ -224,8 +229,8 @@ class _GlobalTitle0100(Envelope):
Uint('spare', bl=1),
Uint('NAI', val=1, bl=7, dic=_GTNAI_dict),
Alt('Addr', GEN={
1 : BufBCD('BCD', val=b''),
2 : BufBCD('BCD', val=b'')},
1 : SCCPBufBCD('BCD', val=b''),
2 : SCCPBufBCD('BCD', val=b'')},
DEFAULT=Buf('Raw', val=b'', rep=REPR_HEX),
sel=lambda self: self.get_env()[2].get_val())
)

View File

@ -105,10 +105,12 @@ class BufBCD(Buf):
"""
_rep = REPR_HUM
_dic = None # dict lookup not supported for repr()
_dic = None # dict lookup not supported for repr()
# characters accepted in a BCD number
_chars = '0123456789*#abc'
_chars = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '#', 'a', 'b', 'c')
# filler character for odd length number encoding
_filler = 0xF
def __init__(self, *args, **kw):
# element name in kw, or first args
@ -175,12 +177,12 @@ class BufBCD(Buf):
"""
# encode the chars
try:
ret = [self._chars.find(c) for c in bcd]
except:
raise(PycrateErr('{0}: invalid BCD string to encode, {1!r}'\
ret = [self._chars.index(c) for c in bcd]
except Exception:
raise(PycrateErr('{0}: invalid character in BCD string to encode, {1!r}'\
.format(self._name, bcd)))
if len(ret) % 2:
ret.append( 0xF )
ret.append( self._filler )
#
if python_version < 3:
self._val = ''.join([chr(c) for c in map(lambda x,y:x+(y<<4), ret[::2], ret[1::2])])
@ -2709,7 +2711,7 @@ class ProtConfigElt(Envelope):
char._len_bit = ccur + 8*self[1].get_val()
try:
cont._from_char(char)
except:
except Exception:
cont = None
char._cur, char._len_bit = ccur, clen
else:
@ -3346,7 +3348,7 @@ class TFTPktFilter(Envelope):
char._cur -= cont_bl
try:
self._Cont._from_char(char)
except:
except Exception:
char._cur, char._len_bit = ccur, clen
else:
if char._cur == ccur: