mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
cosmetic: Switch to consistent four-spaces indent; run autopep8
We had a mixture of tab and 4space based indenting, which is a bad idea. 4space is the standard in python, so convert all our code to that. The result unfortuantely still shoed even more inconsistencies, so I've decided to run autopep8 on the entire code base. Change-Id: I4a4b1b444a2f43fab05fc5d2c8a7dd6ddecb5f07
This commit is contained in:
105
pySim/gsm_r.py
105
pySim/gsm_r.py
@@ -43,26 +43,32 @@ import pySim.ts_51_011
|
||||
# DF.EIRENE (FFFIS for GSM-R SIM Cards)
|
||||
######################################################################
|
||||
|
||||
|
||||
class FuncNTypeAdapter(Adapter):
|
||||
def _decode(self, obj, context, path):
|
||||
bcd = swap_nibbles(b2h(obj))
|
||||
last_digit = bcd[-1]
|
||||
return {'functional_number': bcd[:-1],
|
||||
'presentation_of_only_this_fn': last_digit & 4,
|
||||
'permanent_fn': last_digit & 8 }
|
||||
'permanent_fn': last_digit & 8}
|
||||
|
||||
def _encode(self, obj, context, path):
|
||||
return 'FIXME'
|
||||
|
||||
|
||||
class EF_FN(LinFixedEF):
|
||||
"""Section 7.2"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(fid='6ff1', sfid=None, name='EF.EN', desc='Functional numbers', rec_len={9,9})
|
||||
super().__init__(fid='6ff1', sfid=None, name='EF.EN',
|
||||
desc='Functional numbers', rec_len={9, 9})
|
||||
self._construct = Struct('functional_number_and_type'/FuncNTypeAdapter(Bytes(8)),
|
||||
'list_number'/Int8ub)
|
||||
|
||||
|
||||
class PlConfAdapter(Adapter):
|
||||
"""Section 7.4.3"""
|
||||
|
||||
def _decode(self, obj, context, path):
|
||||
num = int(obj) & 0x7
|
||||
if num == 0:
|
||||
@@ -77,6 +83,7 @@ class PlConfAdapter(Adapter):
|
||||
return 1
|
||||
elif num == 5:
|
||||
return 0
|
||||
|
||||
def _encode(self, obj, context, path):
|
||||
if obj == 'None':
|
||||
return 0
|
||||
@@ -92,8 +99,10 @@ class PlConfAdapter(Adapter):
|
||||
elif obj == 0:
|
||||
return 5
|
||||
|
||||
|
||||
class PlCallAdapter(Adapter):
|
||||
"""Section 7.4.12"""
|
||||
|
||||
def _decode(self, obj, context, path):
|
||||
num = int(obj) & 0x7
|
||||
if num == 0:
|
||||
@@ -112,6 +121,7 @@ class PlCallAdapter(Adapter):
|
||||
return 'B'
|
||||
elif num == 7:
|
||||
return 'A'
|
||||
|
||||
def _encode(self, obj, context, path):
|
||||
if obj == 'None':
|
||||
return 0
|
||||
@@ -130,12 +140,16 @@ class PlCallAdapter(Adapter):
|
||||
elif obj == 'A':
|
||||
return 7
|
||||
|
||||
NextTableType = Enum(Byte, decision=0xf0, predefined=0xf1, num_dial_digits=0xf2, ic=0xf3, empty=0xff)
|
||||
|
||||
NextTableType = Enum(Byte, decision=0xf0, predefined=0xf1,
|
||||
num_dial_digits=0xf2, ic=0xf3, empty=0xff)
|
||||
|
||||
|
||||
class EF_CallconfC(TransparentEF):
|
||||
"""Section 7.3"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(fid='6ff2', sfid=None, name='EF.CallconfC', size={24,24},
|
||||
super().__init__(fid='6ff2', sfid=None, name='EF.CallconfC', size={24, 24},
|
||||
desc='Call Configuration of emergency calls Configuration')
|
||||
self._construct = Struct('pl_conf'/PlConfAdapter(Int8ub),
|
||||
'conf_nr'/BcdAdapter(Bytes(8)),
|
||||
@@ -147,29 +161,39 @@ class EF_CallconfC(TransparentEF):
|
||||
'shunting_emergency_gid'/Int8ub,
|
||||
'imei'/BcdAdapter(Bytes(8)))
|
||||
|
||||
|
||||
class EF_CallconfI(LinFixedEF):
|
||||
"""Section 7.5"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(fid='6ff3', sfid=None, name='EF.CallconfI', rec_len={21,21},
|
||||
super().__init__(fid='6ff3', sfid=None, name='EF.CallconfI', rec_len={21, 21},
|
||||
desc='Call Configuration of emergency calls Information')
|
||||
self._construct = Struct('t_dur'/Int24ub,
|
||||
't_relcalc'/Int32ub,
|
||||
'pl_call'/PlCallAdapter(Int8ub),
|
||||
'cause'/FlagsEnum(Int8ub, powered_off=1, radio_link_error=2, user_command=5),
|
||||
'cause' /
|
||||
FlagsEnum(Int8ub, powered_off=1,
|
||||
radio_link_error=2, user_command=5),
|
||||
'gcr'/BcdAdapter(Bytes(4)),
|
||||
'fnr'/BcdAdapter(Bytes(8)))
|
||||
|
||||
|
||||
class EF_Shunting(TransparentEF):
|
||||
"""Section 7.6"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(fid='6ff4', sfid=None, name='EF.Shunting', desc='Shunting', size={8,8})
|
||||
super().__init__(fid='6ff4', sfid=None,
|
||||
name='EF.Shunting', desc='Shunting', size={8, 8})
|
||||
self._construct = Struct('common_gid'/Int8ub,
|
||||
'shunting_gid'/Bytes(7))
|
||||
|
||||
|
||||
class EF_GsmrPLMN(LinFixedEF):
|
||||
"""Section 7.7"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(fid='6ff5', sfid=None, name='EF.GsmrPLMN', desc='GSM-R network selection', rec_len={9,9})
|
||||
super().__init__(fid='6ff5', sfid=None, name='EF.GsmrPLMN',
|
||||
desc='GSM-R network selection', rec_len={9, 9})
|
||||
self._construct = Struct('plmn'/BcdAdapter(Bytes(3)),
|
||||
'class_of_network'/BitStruct('supported'/FlagsEnum(BitsInteger(5), vbs=1, vgcs=2, emlpp=4, fn=8, eirene=16),
|
||||
'preference'/BitsInteger(3)),
|
||||
@@ -177,34 +201,46 @@ class EF_GsmrPLMN(LinFixedEF):
|
||||
'outgoing_ref_tbl'/HexAdapter(Bytes(2)),
|
||||
'ic_table_ref'/HexAdapter(Bytes(1)))
|
||||
|
||||
|
||||
class EF_IC(LinFixedEF):
|
||||
"""Section 7.8"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(fid='6f8d', sfid=None, name='EF.IC', desc='International Code', rec_len={7,7})
|
||||
super().__init__(fid='6f8d', sfid=None, name='EF.IC',
|
||||
desc='International Code', rec_len={7, 7})
|
||||
self._construct = Struct('next_table_type'/NextTableType,
|
||||
'id_of_next_table'/HexAdapter(Bytes(2)),
|
||||
'ic_decision_value'/BcdAdapter(Bytes(2)),
|
||||
'network_string_table_index'/Int8ub)
|
||||
|
||||
|
||||
class EF_NW(LinFixedEF):
|
||||
"""Section 7.9"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(fid='6f80', sfid=None, name='EF.NW', desc='Network Name', rec_len={8,8})
|
||||
super().__init__(fid='6f80', sfid=None, name='EF.NW',
|
||||
desc='Network Name', rec_len={8, 8})
|
||||
self._construct = GsmString(8)
|
||||
|
||||
|
||||
class EF_Switching(LinFixedEF):
|
||||
"""Section 8.4"""
|
||||
|
||||
def __init__(self, fid, name, desc):
|
||||
super().__init__(fid=fid, sfid=None, name=name, desc=desc, rec_len={6,6})
|
||||
super().__init__(fid=fid, sfid=None,
|
||||
name=name, desc=desc, rec_len={6, 6})
|
||||
self._construct = Struct('next_table_type'/NextTableType,
|
||||
'id_of_next_table'/HexAdapter(Bytes(2)),
|
||||
'decision_value'/BcdAdapter(Bytes(2)),
|
||||
'string_table_index'/Int8ub)
|
||||
|
||||
|
||||
class EF_Predefined(LinFixedEF):
|
||||
"""Section 8.5"""
|
||||
|
||||
def __init__(self, fid, name, desc):
|
||||
super().__init__(fid=fid, sfid=None, name=name, desc=desc, rec_len={3,3})
|
||||
super().__init__(fid=fid, sfid=None,
|
||||
name=name, desc=desc, rec_len={3, 3})
|
||||
# header and other records have different structure. WTF !?!
|
||||
self._construct = Struct('next_table_type'/NextTableType,
|
||||
'id_of_next_table'/HexAdapter(Bytes(2)),
|
||||
@@ -212,10 +248,12 @@ class EF_Predefined(LinFixedEF):
|
||||
'string_table_index1'/Int8ub)
|
||||
# TODO: predefined value n, ...
|
||||
|
||||
|
||||
class EF_DialledVals(TransparentEF):
|
||||
"""Section 8.6"""
|
||||
|
||||
def __init__(self, fid, name, desc):
|
||||
super().__init__(fid=fid, sfid=None, name=name, desc=desc, size={4,4})
|
||||
super().__init__(fid=fid, sfid=None, name=name, desc=desc, size={4, 4})
|
||||
self._construct = Struct('next_table_type'/NextTableType,
|
||||
'id_of_next_table'/HexAdapter(Bytes(2)),
|
||||
'dialed_digits'/BcdAdapter(Bytes(1)))
|
||||
@@ -238,18 +276,31 @@ class DF_EIRENE(CardDF):
|
||||
EF_Switching(fid='6f8e', name='EF.CT', desc='Call Type'),
|
||||
EF_Switching(fid='6f8f', name='EF.SC', desc='Short Code'),
|
||||
EF_Predefined(fid='6f88', name='EF.FC', desc='Function Code'),
|
||||
EF_Predefined(fid='6f89', name='EF.Service', desc='VGCS/VBS Service Code'),
|
||||
EF_Predefined(fid='6f8a', name='EF.Call', desc='First digit of the group ID'),
|
||||
EF_Predefined(fid='6f8b', name='EF.FctTeam', desc='Call Type 6 Team Type + Team member function'),
|
||||
EF_Predefined(fid='6f92', name='EF.Controller', desc='Call Type 7 Controller function code'),
|
||||
EF_Predefined(fid='6f8c', name='EF.Gateway', desc='Access to external networks'),
|
||||
EF_DialledVals(fid='6f81', name='EF.5to8digits', desc='Call Type 2 User Identity Number length'),
|
||||
EF_DialledVals(fid='6f82', name='EF.2digits', desc='2 digits input'),
|
||||
EF_DialledVals(fid='6f83', name='EF.8digits', desc='8 digits input'),
|
||||
EF_DialledVals(fid='6f84', name='EF.9digits', desc='9 digits input'),
|
||||
EF_DialledVals(fid='6f85', name='EF.SSSSS', desc='Group call area input'),
|
||||
EF_DialledVals(fid='6f86', name='EF.LLLLL', desc='Location number Call Type 6'),
|
||||
EF_DialledVals(fid='6f91', name='EF.Location', desc='Location number Call Type 7'),
|
||||
EF_DialledVals(fid='6f87', name='EF.FreeNumber', desc='Free Number Call Type 0 and 8'),
|
||||
]
|
||||
EF_Predefined(fid='6f89', name='EF.Service',
|
||||
desc='VGCS/VBS Service Code'),
|
||||
EF_Predefined(fid='6f8a', name='EF.Call',
|
||||
desc='First digit of the group ID'),
|
||||
EF_Predefined(fid='6f8b', name='EF.FctTeam',
|
||||
desc='Call Type 6 Team Type + Team member function'),
|
||||
EF_Predefined(fid='6f92', name='EF.Controller',
|
||||
desc='Call Type 7 Controller function code'),
|
||||
EF_Predefined(fid='6f8c', name='EF.Gateway',
|
||||
desc='Access to external networks'),
|
||||
EF_DialledVals(fid='6f81', name='EF.5to8digits',
|
||||
desc='Call Type 2 User Identity Number length'),
|
||||
EF_DialledVals(fid='6f82', name='EF.2digits',
|
||||
desc='2 digits input'),
|
||||
EF_DialledVals(fid='6f83', name='EF.8digits',
|
||||
desc='8 digits input'),
|
||||
EF_DialledVals(fid='6f84', name='EF.9digits',
|
||||
desc='9 digits input'),
|
||||
EF_DialledVals(fid='6f85', name='EF.SSSSS',
|
||||
desc='Group call area input'),
|
||||
EF_DialledVals(fid='6f86', name='EF.LLLLL',
|
||||
desc='Location number Call Type 6'),
|
||||
EF_DialledVals(fid='6f91', name='EF.Location',
|
||||
desc='Location number Call Type 7'),
|
||||
EF_DialledVals(fid='6f87', name='EF.FreeNumber',
|
||||
desc='Free Number Call Type 0 and 8'),
|
||||
]
|
||||
self.add_files(files)
|
||||
|
||||
Reference in New Issue
Block a user