laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/31056 ) Change subject: gsm_r: EF_Predefined: Decode first record different from others ...................................................................... gsm_r: EF_Predefined: Decode first record different from others In their infinite wisdom, the authors of the EIRENE FFFIS for GSM-R SIM cards invented yet a new way of encoding data in SIM card files: The first record of a file may be encoded differently than further records of files. This patch implements the feature based on the newly-introduced way by which we pass the record number to the encoder and decoder methods. Change-Id: Ib526f6c3c2ac9a945b8242e2e54536628376efc0 Related: OS#5784 --- M pySim/gsm_r.py 1 file changed, 18 insertions(+), 6 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/56/31056/1 diff --git a/pySim/gsm_r.py b/pySim/gsm_r.py index 5ddb04b..68e0aa8 100644 --- a/pySim/gsm_r.py +++ b/pySim/gsm_r.py @@ -237,17 +237,29 @@ class EF_Predefined(LinFixedEF): """Section 8.5""" + # header and other records have different structure. WTF !?! + construct_first = Struct('next_table_type'/NextTableType, + 'id_of_next_table'/HexAdapter(Bytes(2))) + construct_others = Struct('predefined_value1'/HexAdapter(Bytes(2)), + 'string_table_index1'/Int8ub) def __init__(self, fid, name, desc): 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)), - 'predefined_value1'/HexAdapter(Bytes(2)), - 'string_table_index1'/Int8ub) - # TODO: predefined value n, ... + def _decode_record_bin(self, raw_bin_data : bytes, record_nr : int) -> dict: + if record_nr == 1: + return parse_construct(EF_Predefined.construct_first, raw_bin_data) + else: + return parse_construct(EF_Predefined.construct_others, raw_bin_data) + + def _encode_record_bin(self, abstract_data : dict, record_nr : int) -> bytearray: + r = None + if record_nr == 1: + r = EF_Predefined.construct_first.build(abstract_data) + else: + r = EF_Predefined.construct_others.build(abstract_data) + return filter_dict(r) class EF_DialledVals(TransparentEF): """Section 8.6""" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/31056 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Ib526f6c3c2ac9a945b8242e2e54536628376efc0 Gerrit-Change-Number: 31056 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge@osmocom.org> Gerrit-MessageType: newchange