laforge has submitted this change. (
https://gerrit.osmocom.org/c/pysim/+/31066 )
Change subject: ts_51_011: Implement Extended BCD Coding
......................................................................
ts_51_011: Implement Extended BCD Coding
TS 51.011 specifies an "Extended BCD Coding" in Table 12 of Section
10.5.1. It allows to express the '*' and '#' symbols used in GSM
SS and/or USSD codes.
This improves decoding from
"dialing_nr": "a753b1200f",
to
"dialing_nr": "*753#1200f",
Change-Id: Ifcec13e9b296dba7bec34b7872192b7ce185c23c
Related: OS#5784
---
M pySim/ts_51_011.py
1 file changed, 17 insertions(+), 1 deletion(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index de49e7a..df1bfed 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -340,6 +340,22 @@
# DF.TELECOM
######################################################################
+
+# TS 51.011 Section 10.5.1 / Table 12
+class ExtendedBcdAdapter(Adapter):
+ """Replace some hex-characters with other ASCII
characters"""
+ # we only translate a=* / b=# as they habe a clear representation
+ # in terms of USSD / SS service codes
+ def _decode(self, obj, context, path):
+ if not isinstance(obj, str):
+ return obj
+ return
obj.lower().replace("a","*").replace("b","#")
+
+ def _encode(self, obj, context, path):
+ if not isinstance(obj, str):
+ return obj
+ return
obj.replace("*","a").replace("#","b")
+
# TS 51.011 Section 10.5.1
class EF_ADN(LinFixedEF):
def __init__(self, fid='6f3a', sfid=None, name='EF.ADN',
desc='Abbreviated Dialing Numbers', **kwargs):
@@ -347,7 +363,7 @@
self._construct =
Struct('alpha_id'/COptional(GsmStringAdapter(Rpad(Bytes(this._.total_len-14)),
codec='ascii')),
'len_of_bcd'/Int8ub,
'ton_npi'/TonNpi,
- 'dialing_nr'/BcdAdapter(Rpad(Bytes(10))),
+
'dialing_nr'/ExtendedBcdAdapter(BcdAdapter(Rpad(Bytes(10)))),
'cap_conf_id'/Int8ub,
'ext1_record_id'/Int8ub)
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/31066
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ifcec13e9b296dba7bec34b7872192b7ce185c23c
Gerrit-Change-Number: 31066
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged