laforge has submitted this change. ( 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(-)
Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified
diff --git a/pySim/gsm_r.py b/pySim/gsm_r.py index 5ddb04b..347c4e6 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(self.construct_first, raw_bin_data) + else: + return parse_construct(self.construct_others, raw_bin_data) + + def _encode_record_bin(self, abstract_data : dict, record_nr : int) -> bytearray: + r = None + if record_nr == 1: + r = self.construct_first.build(abstract_data) + else: + r = self.construct_others.build(abstract_data) + return filter_dict(r)
class EF_DialledVals(TransparentEF): """Section 8.6"""