dexter has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/38117?usp=email )


Change subject: ts_51_011: replace encoding of EF.MSISDN with construct model
......................................................................

ts_51_011: replace encoding of EF.MSISDN with construct model

The encoding of EF.MSISDN is currently done with enc_msisdn and
dec_msisdn from utils.py. Let's replace this with a construct
based model, similar to the one we already use with EF.ADN

Related: OS#5714
Change-Id: I647f5c63f7f87902a86c0c5d8e92fdc7f4350a5a
---
M pySim/ts_51_011.py
1 file changed, 16 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/17/38117/1

diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index c6720fe..401db9e 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -190,20 +190,24 @@

 # TS 51.011 Section 10.5.5
 class EF_MSISDN(LinFixedEF):
+    _test_decode = [
+        ( 
'ffffffffffffffffffffffffffffffffffffffff04b12143f5ffffffffffffffffff',
+            {"alpha_id": "", "len_of_bcd": 4, "ton_npi": {"ext": True, 
"type_of_number": "network_specific",
+                                                          "numbering_plan_id": 
"isdn_e164"},
+             "dialing_nr": "12345f"}),
+        ( 
'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"}),
+    ]
+    _test_no_pad = True
+
     def __init__(self, fid='6f40', sfid=None, name='EF.MSISDN', desc='MSISDN', 
**kwargs):
         super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(15, 
34), leftpad=True, **kwargs)
-
-    def _decode_record_hex(self, raw_hex_data, **kwargs):
-        return {'msisdn': dec_msisdn(raw_hex_data)}
-
-    def _encode_record_hex(self, abstract, **kwargs):
-        msisdn = abstract['msisdn']
-        if type(msisdn) == str:
-            encoded_msisdn = enc_msisdn(msisdn)
-        else:
-            encoded_msisdn = enc_msisdn(msisdn[2], msisdn[0], msisdn[1])
-        alpha_identifier = (list(self.rec_len)[0] - len(encoded_msisdn) // 2) 
* "ff"
-        return alpha_identifier + encoded_msisdn
+        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)))))

 # TS 51.011 Section 10.5.6
 class EF_SMSP(LinFixedEF):

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38117?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I647f5c63f7f87902a86c0c5d8e92fdc7f4350a5a
Gerrit-Change-Number: 38117
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <[email protected]>

Reply via email to