laforge submitted this change.

View Change



2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.

Approvals: Jenkins Builder: Verified dexter: Looks good to me, approved fixeria: Looks good to me, but someone else must approve
Fix more odd-length digit sequences via PaddedBcdAdapter

There are more files where trailing digits are indicated using 'f' and
should be stripped during decode, including EF.MSISDN and EF.VGCS

This is not just a presentation issue, but actually rendered wrong data
before, see the modified test output where our "read_record_uicc.ok"
file contained "bcd_len: 7" but then only 6 BCD digits due to this bug.

Change-Id: I4571482da924a3d645caa297108279d182448d21
---
M pySim/ts_31_102.py
M pySim/ts_51_011.py
M tests/pySim-shell_test/file_content/test_record_uicc.ok
3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index 3ae178c..a93f1e8 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -596,7 +596,7 @@
self._construct = Struct('alpha_id'/Bytes(this._.total_len-28),
'len_of_bcd_contents'/Int8ub,
'ton_npi'/Int8ub,
- 'call_number'/BcdAdapter(Bytes(10)),
+ 'call_number'/PaddedBcdAdapter(Rpad(Bytes(10))),
'cap_cfg2_record_id'/Int8ub,
'ext5_record_id'/Int8ub,
'date_and_time'/BcdAdapter(Bytes(7)),
@@ -612,7 +612,7 @@
self._construct = Struct('alpha_id'/Bytes(this._.total_len-27),
'len_of_bcd_contents'/Int8ub,
'ton_npi'/Int8ub,
- 'call_number'/BcdAdapter(Bytes(10)),
+ 'call_number'/PaddedBcdAdapter(Rpad(Bytes(10))),
'cap_cfg2_record_id'/Int8ub,
'ext5_record_id'/Int8ub,
'date_and_time'/BcdAdapter(Bytes(7)),
@@ -1118,7 +1118,7 @@
# responsibility of home network operator but BCD coding shall be used. If a network
# operator decides to assign less than 4 digits to Routing Indicator, the remaining digits
# shall be coded as "1111" to fill the 4 digits coding of Routing Indicator
- self._construct = Struct('routing_indicator'/Rpad(BcdAdapter(Bytes(2)), 'f', 2),
+ self._construct = Struct('routing_indicator'/PaddedBcdAdapter(Rpad(Bytes(2))),
'rfu'/Bytes(2))

# TS 31.102 Section 4.4.11.13 (Rel 16)
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index d37715f..70c38b1 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -152,7 +152,7 @@
self._construct = Struct('alpha_id'/COptional(GsmOrUcs2Adapter(Rpad(Bytes(this._.total_len-14)))),
'len_of_bcd'/Int8ub,
'ton_npi'/TonNpi,
- 'dialing_nr'/ExtendedBcdAdapter(BcdAdapter(Rpad(Bytes(10)))),
+ 'dialing_nr'/ExtendedBcdAdapter(PaddedBcdAdapter(Rpad(Bytes(10)))),
'cap_conf_id'/Int8ub,
ext_name/Int8ub)

@@ -193,11 +193,11 @@
( 'ffffffffffffffffffffffffffffffffffffffff04b12143f5ffffffffffffffffff',
{"alpha_id": "", "len_of_bcd": 4, "ton_npi": {"ext": True, "type_of_number": "network_specific",
"numbering_plan_id": "isdn_e164"},
- "dialing_nr": "12345f"}),
+ "dialing_nr": "12345"}),
( '456967656e65205275666e756d6d6572ffffffff0891947172199181f3ffffffffff',
{"alpha_id": "Eigene Rufnummer", "len_of_bcd": 8, "ton_npi": {"ext": True, "type_of_number": "international",
"numbering_plan_id": "isdn_e164"},
- "dialing_nr": "4917279119183f"}),
+ "dialing_nr": "4917279119183"}),
]

# Ensure deprecated representations still work
@@ -215,7 +215,7 @@
self._construct = Struct('alpha_id'/COptional(GsmOrUcs2Adapter(Rpad(Bytes(this._.total_len-14)))),
'len_of_bcd'/Int8ub,
'ton_npi'/TonNpi,
- 'dialing_nr'/ExtendedBcdAdapter(BcdAdapter(Rpad(Bytes(10)))),
+ 'dialing_nr'/ExtendedBcdAdapter(PaddedBcdAdapter(Rpad(Bytes(10)))),
Padding(2, pattern=b'\xff'))

# Maintain compatibility with deprecated representations
@@ -661,12 +661,12 @@
# TS 51.011 Section 10.3.20 / 10.3.22
class EF_VGCS(TransRecEF):
_test_de_encode = [
- ( "92f9ffff", "299fffff" ),
+ ( "92f9ffff", "299" ),
]
def __init__(self, fid='6fb1', sfid=None, name='EF.VGCS', size=(4, 200), rec_len=4,
desc='Voice Group Call Service', **kwargs):
super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs)
- self._construct = BcdAdapter(Bytes(4))
+ self._construct = PaddedBcdAdapter(Rpad(Bytes(4)))

# TS 51.011 Section 10.3.21 / 10.3.23
class EF_VGCSS(TransparentEF):
diff --git a/tests/pySim-shell_test/file_content/test_record_uicc.ok b/tests/pySim-shell_test/file_content/test_record_uicc.ok
index 14183eb..5a4e747 100644
--- a/tests/pySim-shell_test/file_content/test_record_uicc.ok
+++ b/tests/pySim-shell_test/file_content/test_record_uicc.ok
@@ -19,7 +19,7 @@
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
- "dialing_nr": "123456",
+ "dialing_nr": "1234567",
"cap_conf_id": 42,
"ext4_record_id": 23
},
@@ -67,7 +67,7 @@
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
- "dialing_nr": "123456",
+ "dialing_nr": "1234567",
"cap_conf_id": 42,
"ext4_record_id": 23
},
@@ -127,7 +127,7 @@
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
- "dialing_nr": "123456",
+ "dialing_nr": "1234567",
"cap_conf_id": 42,
"ext4_record_id": 23
}
@@ -140,7 +140,7 @@
"type_of_number": "reserved_for_extension",
"numbering_plan_id": "reserved_for_extension"
},
- "dialing_nr": "123456",
+ "dialing_nr": "1234567",
"cap_conf_id": 42,
"ext4_record_id": 23
}

To view, visit change 41742. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4571482da924a3d645caa297108279d182448d21
Gerrit-Change-Number: 41742
Gerrit-PatchSet: 5
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>