Never use Bytes without any 'Adapter'

Otherwise we have binary/bytes as values inside the dict, rather than a
hexadecimal string.  That's ugly when printing without json formatting.

Change-Id: Ia3e7c4791d11bd4e3719a43d58e11e05ec986d1f
This commit is contained in:
Harald Welte
2022-07-20 07:40:05 +02:00
parent 857f110492
commit 3c98d5e91d
4 changed files with 34 additions and 31 deletions

View File

@@ -185,7 +185,7 @@ class EF_Shunting(TransparentEF):
super().__init__(fid='6ff4', sfid=None, super().__init__(fid='6ff4', sfid=None,
name='EF.Shunting', desc='Shunting', size={8, 8}) name='EF.Shunting', desc='Shunting', size={8, 8})
self._construct = Struct('common_gid'/Int8ub, self._construct = Struct('common_gid'/Int8ub,
'shunting_gid'/Bytes(7)) 'shunting_gid'/HexAdapter(Bytes(7)))
class EF_GsmrPLMN(LinFixedEF): class EF_GsmrPLMN(LinFixedEF):

View File

@@ -142,13 +142,12 @@ class EF_SIM_AUTH_KEY(TransparentEF):
'use_opc_instead_of_op'/Bit, 'use_opc_instead_of_op'/Bit,
'algorithm'/Enum(Nibble, milenage=4, comp128v1=1, comp128v2=2, comp128v3=3)) 'algorithm'/Enum(Nibble, milenage=4, comp128v1=1, comp128v2=2, comp128v3=3))
self._construct = Struct('cfg'/CfgByte, self._construct = Struct('cfg'/CfgByte,
'key'/Bytes(16), 'key'/HexAdapter(Bytes(16)),
'op' / 'op'/ If(this.cfg.algorithm == 'milenage' and not this.cfg.use_opc_instead_of_op,
If(this.cfg.algorithm == 'milenage' and not this.cfg.use_opc_instead_of_op, Bytes( HexAdapter(Bytes(16))),
16)),
'opc' / 'opc' /
If(this.cfg.algorithm == 'milenage' and this.cfg.use_opc_instead_of_op, Bytes( If(this.cfg.algorithm == 'milenage' and this.cfg.use_opc_instead_of_op,
16)) HexAdapter(Bytes(16)))
) )
@@ -198,13 +197,13 @@ class EF_USIM_AUTH_KEY(TransparentEF):
'use_opc_instead_of_op'/Bit, 'use_opc_instead_of_op'/Bit,
'algorithm'/Enum(Nibble, milenage=4, sha1_aka=5, xor=15)) 'algorithm'/Enum(Nibble, milenage=4, sha1_aka=5, xor=15))
self._construct = Struct('cfg'/CfgByte, self._construct = Struct('cfg'/CfgByte,
'key'/Bytes(16), 'key'/HexAdapter(Bytes(16)),
'op' / 'op' /
If(this.cfg.algorithm == 'milenage' and not this.cfg.use_opc_instead_of_op, Bytes( If(this.cfg.algorithm == 'milenage' and not this.cfg.use_opc_instead_of_op,
16)), HexAdapter(Bytes(16))),
'opc' / 'opc' /
If(this.cfg.algorithm == 'milenage' and this.cfg.use_opc_instead_of_op, Bytes( If(this.cfg.algorithm == 'milenage' and this.cfg.use_opc_instead_of_op,
16)) HexAdapter(Bytes(16)))
) )
@@ -216,13 +215,13 @@ class EF_USIM_AUTH_KEY_2G(TransparentEF):
'use_opc_instead_of_op'/Bit, 'use_opc_instead_of_op'/Bit,
'algorithm'/Enum(Nibble, milenage=4, comp128v1=1, comp128v2=2, comp128v3=3)) 'algorithm'/Enum(Nibble, milenage=4, comp128v1=1, comp128v2=2, comp128v3=3))
self._construct = Struct('cfg'/CfgByte, self._construct = Struct('cfg'/CfgByte,
'key'/Bytes(16), 'key'/HexAdapter(Bytes(16)),
'op' / 'op' /
If(this.cfg.algorithm == 'milenage' and not this.cfg.use_opc_instead_of_op, Bytes( If(this.cfg.algorithm == 'milenage' and not this.cfg.use_opc_instead_of_op,
16)), HexAdapter(Bytes(16))),
'opc' / 'opc' /
If(this.cfg.algorithm == 'milenage' and this.cfg.use_opc_instead_of_op, Bytes( If(this.cfg.algorithm == 'milenage' and this.cfg.use_opc_instead_of_op,
16)) HexAdapter(Bytes(16)))
) )

View File

@@ -664,7 +664,7 @@ class EF_ICI(CyclicEF):
def __init__(self, fid='6f80', sfid=0x14, name='EF.ICI', rec_len={28, 48}, def __init__(self, fid='6f80', sfid=0x14, name='EF.ICI', rec_len={28, 48},
desc='Incoming Call Information', **kwargs): desc='Incoming Call Information', **kwargs):
super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
self._construct = Struct('alpha_id'/Bytes(this._.total_len-28), self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-28)),
'len_of_bcd_contents'/Int8ub, 'len_of_bcd_contents'/Int8ub,
'ton_npi'/Int8ub, 'ton_npi'/Int8ub,
'call_number'/BcdAdapter(Bytes(10)), 'call_number'/BcdAdapter(Bytes(10)),
@@ -673,14 +673,14 @@ class EF_ICI(CyclicEF):
'date_and_time'/BcdAdapter(Bytes(7)), 'date_and_time'/BcdAdapter(Bytes(7)),
'duration'/Int24ub, 'duration'/Int24ub,
'status'/Byte, 'status'/Byte,
'link_to_phonebook'/Bytes(3)) 'link_to_phonebook'/HexAdapter(Bytes(3)))
# TS 31.102 Section 4.2.34 # TS 31.102 Section 4.2.34
class EF_OCI(CyclicEF): class EF_OCI(CyclicEF):
def __init__(self, fid='6f81', sfid=0x15, name='EF.OCI', rec_len={27, 47}, def __init__(self, fid='6f81', sfid=0x15, name='EF.OCI', rec_len={27, 47},
desc='Outgoing Call Information', **kwargs): desc='Outgoing Call Information', **kwargs):
super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
self._construct = Struct('alpha_id'/Bytes(this._.total_len-27), self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-27)),
'len_of_bcd_contents'/Int8ub, 'len_of_bcd_contents'/Int8ub,
'ton_npi'/Int8ub, 'ton_npi'/Int8ub,
'call_number'/BcdAdapter(Bytes(10)), 'call_number'/BcdAdapter(Bytes(10)),
@@ -688,7 +688,7 @@ class EF_OCI(CyclicEF):
'ext5_record_id'/Int8ub, 'ext5_record_id'/Int8ub,
'date_and_time'/BcdAdapter(Bytes(7)), 'date_and_time'/BcdAdapter(Bytes(7)),
'duration'/Int24ub, 'duration'/Int24ub,
'link_to_phonebook'/Bytes(3)) 'link_to_phonebook'/HexAdapter(Bytes(3)))
# TS 31.102 Section 4.2.35 # TS 31.102 Section 4.2.35
class EF_ICT(CyclicEF): class EF_ICT(CyclicEF):
@@ -727,7 +727,7 @@ class EF_ACL(TransparentEF):
def __init__(self, fid='6f57', sfid=None, name='EF.ACL', size={32, None}, def __init__(self, fid='6f57', sfid=None, name='EF.ACL', size={32, None},
desc='Access Point Name Control List', **kwargs): desc='Access Point Name Control List', **kwargs):
super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
self._construct = Struct('num_of_apns'/Int8ub, 'tlvs'/GreedyBytes) self._construct = Struct('num_of_apns'/Int8ub, 'tlvs'/HexAdapter(GreedyBytes))
# TS 31.102 Section 4.2.51 # TS 31.102 Section 4.2.51
class EF_START_HFN(TransparentEF): class EF_START_HFN(TransparentEF):
@@ -771,7 +771,7 @@ class EF_MSK(LinFixedEF):
def __init__(self, fid='6fd7', sfid=None, name='EF.MSK', desc='MBMS Service Key List', **kwargs): def __init__(self, fid='6fd7', sfid=None, name='EF.MSK', desc='MBMS Service Key List', **kwargs):
super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={20, None}, **kwargs) super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={20, None}, **kwargs)
msk_ts_constr = Struct('msk_id'/Int32ub, 'timestamp_counter'/Int32ub) msk_ts_constr = Struct('msk_id'/Int32ub, 'timestamp_counter'/Int32ub)
self._construct = Struct('key_domain_id'/Bytes(3), self._construct = Struct('key_domain_id'/HexAdapter(Bytes(3)),
'num_msk_id'/Int8ub, 'num_msk_id'/Int8ub,
'msk_ids'/msk_ts_constr[this.num_msk_id]) 'msk_ids'/msk_ts_constr[this.num_msk_id])
# TS 31.102 Section 4.2.81 # TS 31.102 Section 4.2.81
@@ -865,7 +865,8 @@ class EF_EPSLOCI(TransparentEF):
super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
upd_status_constr = Enum( upd_status_constr = Enum(
Byte, updated=0, not_updated=1, roaming_not_allowed=2) Byte, updated=0, not_updated=1, roaming_not_allowed=2)
self._construct = Struct('guti'/Bytes(12), 'last_visited_registered_tai'/Bytes(5), self._construct = Struct('guti'/HexAdapter(Bytes(12)),
'last_visited_registered_tai'/HexAdapter(Bytes(5)),
'eps_update_status'/upd_status_constr) 'eps_update_status'/upd_status_constr)
# TS 31.102 Section 4.2.92 # TS 31.102 Section 4.2.92
@@ -958,7 +959,8 @@ class EF_5GS3GPPLOCI(TransparentEF):
super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
upd_status_constr = Enum( upd_status_constr = Enum(
Byte, updated=0, not_updated=1, roaming_not_allowed=2) Byte, updated=0, not_updated=1, roaming_not_allowed=2)
self._construct = Struct('5g_guti'/Bytes(13), 'last_visited_registered_tai_in_5gs'/Bytes(6), self._construct = Struct('5g_guti'/HexAdapter(Bytes(13)),
'last_visited_registered_tai_in_5gs'/HexAdapter(Bytes(6)),
'5gs_update_status'/upd_status_constr) '5gs_update_status'/upd_status_constr)
# TS 31.102 Section 4.4.11.7 # TS 31.102 Section 4.4.11.7
@@ -974,7 +976,8 @@ class EF_UAC_AIC(TransparentEF):
class EF_OPL5G(LinFixedEF): class EF_OPL5G(LinFixedEF):
def __init__(self, fid='6f08', sfid=0x08, name='EF.OPL5G', desc='5GS Operator PLMN List', **kwargs): def __init__(self, fid='6f08', sfid=0x08, name='EF.OPL5G', desc='5GS Operator PLMN List', **kwargs):
super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={10, None}, **kwargs) super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={10, None}, **kwargs)
Tai = Struct('mcc_mnc'/BcdAdapter(Bytes(3)), 'tac_min'/Bytes(3), 'tac_max'/Bytes(3)) Tai = Struct('mcc_mnc'/BcdAdapter(Bytes(3)), 'tac_min'/HexAdapter(Bytes(3)),
'tac_max'/HexAdapter(Bytes(3)))
self._construct = Struct('tai'/Tai, 'pnn_record_id'/Int8ub) self._construct = Struct('tai'/Tai, 'pnn_record_id'/Int8ub)
# TS 31.102 Section 4.4.11.10 # TS 31.102 Section 4.4.11.10

View File

@@ -667,7 +667,7 @@ class EF_ACC(TransparentEF):
class EF_LOCI(TransparentEF): class EF_LOCI(TransparentEF):
def __init__(self, fid='6f7e', sfid=None, name='EF.LOCI', desc='Location Information', size={11, 11}): def __init__(self, fid='6f7e', sfid=None, name='EF.LOCI', desc='Location Information', size={11, 11}):
super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
self._construct = Struct('tmsi'/Bytes(4), 'lai'/Bytes(5), 'tmsi_time'/Int8ub, self._construct = Struct('tmsi'/HexAdapter(Bytes(4)), 'lai'/HexAdapter(Bytes(5)), 'tmsi_time'/Int8ub,
'lu_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, 'lu_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2,
location_area_not_allowed=3)) location_area_not_allowed=3))
@@ -806,7 +806,7 @@ class EF_Kc(TransparentEF):
class EF_LOCIGPRS(TransparentEF): class EF_LOCIGPRS(TransparentEF):
def __init__(self, fid='6f53', sfid=None, name='EF.LOCIGPRS', desc='GPRS Location Information', size={14, 14}): def __init__(self, fid='6f53', sfid=None, name='EF.LOCIGPRS', desc='GPRS Location Information', size={14, 14}):
super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
self._construct = Struct('ptmsi'/Bytes(4), 'ptmsi_sig'/Int8ub, 'rai'/Bytes(6), self._construct = Struct('ptmsi'/HexAdapter(Bytes(4)), 'ptmsi_sig'/Int8ub, 'rai'/HexAdapter(Bytes(6)),
'rau_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, 'rau_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2,
routing_area_not_allowed=3)) routing_area_not_allowed=3))
@@ -897,7 +897,8 @@ class EF_PNN(LinFixedEF):
class EF_OPL(LinFixedEF): class EF_OPL(LinFixedEF):
def __init__(self, fid='6fc6', sfid=None, name='EF.OPL', rec_len={8, 8}, desc='Operator PLMN List', **kwargs): def __init__(self, fid='6fc6', sfid=None, name='EF.OPL', rec_len={8, 8}, desc='Operator PLMN List', **kwargs):
super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
self._construct = Struct('lai'/Struct('mcc_mnc'/BcdAdapter(Bytes(3)), 'lac_min'/Bytes(2), 'lac_max'/Bytes(2)), 'pnn_record_id'/Int8ub) self._construct = Struct('lai'/Struct('mcc_mnc'/BcdAdapter(Bytes(3)),
'lac_min'/HexAdapter(Bytes(2)), 'lac_max'/HexAdapter(Bytes(2))), 'pnn_record_id'/Int8ub)
# TS 51.011 Section 10.3.44 + TS 31.102 4.2.62 # TS 51.011 Section 10.3.44 + TS 31.102 4.2.62
class EF_MBI(LinFixedEF): class EF_MBI(LinFixedEF):
@@ -933,8 +934,8 @@ class EF_SPDI(TransparentEF):
class EF_MMSN(LinFixedEF): class EF_MMSN(LinFixedEF):
def __init__(self, fid='6fce', sfid=None, name='EF.MMSN', rec_len={4, 20}, desc='MMS Notification', **kwargs): def __init__(self, fid='6fce', sfid=None, name='EF.MMSN', rec_len={4, 20}, desc='MMS Notification', **kwargs):
super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
self._construct = Struct('mms_status'/Bytes(2), 'mms_implementation'/Bytes(1), self._construct = Struct('mms_status'/HexAdapter(Bytes(2)), 'mms_implementation'/HexAdapter(Bytes(1)),
'mms_notification'/Bytes(this._.total_len-4), 'ext_record_nr'/Byte) 'mms_notification'/HexAdapter(Bytes(this._.total_len-4)), 'ext_record_nr'/Byte)
# TS 51.011 Annex K.1 # TS 51.011 Annex K.1
class MMS_Implementation(BER_TLV_IE, tag=0x80): class MMS_Implementation(BER_TLV_IE, tag=0x80):