laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/31057
)
Change subject: gsm_r: Fix byte ordering of predefined_value1
......................................................................
gsm_r: Fix byte ordering of predefined_value1
In GSM-R, a number of files such as EF.FC, EF.Service, etc. are
defined to have reverse byte ordering for their first two bytes
in all but the first record. Let's implement this using a
new ReverseOrderAdapter() class for construct.
Change-Id: Ia0dd8994556548a17a0a3101225c23e804511717
Related: OS#5784
---
M pySim/construct.py
M pySim/gsm_r.py
2 files changed, 9 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/57/31057/1
diff --git a/pySim/construct.py b/pySim/construct.py
index 97af235..5db6724 100644
--- a/pySim/construct.py
+++ b/pySim/construct.py
@@ -64,6 +64,14 @@
def _encode(self, obj, context, path):
return self._invert_bool_in_obj(obj)
+class ReverseOrderAdapter(Adapter):
+
+ def _decode(self, obj, context, path):
+ return reversed(obj)
+
+ def _encode(self, obj, context, path):
+ return reversed(obj)
+
class Rpad(Adapter):
"""
Encoder appends padding bytes (b'\\xff') up to target size.
diff --git a/pySim/gsm_r.py b/pySim/gsm_r.py
index 68e0aa8..74bdf20 100644
--- a/pySim/gsm_r.py
+++ b/pySim/gsm_r.py
@@ -240,7 +240,7 @@
# 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)),
+ construct_others =
Struct('predefined_value1'/HexAdapter(ReverseOrderAdapter(Bytes(2))),
'string_table_index1'/Int8ub)
def __init__(self, fid, name, desc):
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/31057
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ia0dd8994556548a17a0a3101225c23e804511717
Gerrit-Change-Number: 31057
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange