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


Change subject: pySim/EF.SMSP: fix encoding of TP-Destination Address
......................................................................

pySim/EF.SMSP: fix encoding of TP-Destination Address

The TP-Destination Address in EF.SMSP uses the same encoding as the
TS-Service Centre Address field. However, even though the encoding
of both fields looks almost identical, it actually isn't.

The TS-Service Centre Address field encodes the length field as
octets required for the call_number + one octet for ton_npi.
(see also: 3GPP TS 24.011, section 8.2.5.2)

The TP-Destination Address uses the number of digits of the
call_number directly in the length field.
(see also: 3GPP TS 23.040, section 9.1.2.5)

Related: SYS#7765
Change-Id: I55c123c9e244e5a6e71a0348f5d476ef03e618e8
---
M pySim/ts_51_011.py
1 file changed, 24 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/69/42469/1

diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index 86d0192..44eccfa 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -271,6 +271,16 @@
                                                         "numbering_plan_id": 
"isdn_e164" },
                             "call_number": "49301234567" },
             "tp_pid": b"\xff", "tp_dcs": b"\xff", "tp_vp_minutes": 635040 } ),
+        ( 
'fffffffffffffffffffffffffffffffffffffffffffffffffc0b919403214365f7ffffffff07919403214365f7ffffffffffffff',
+          { "alpha_id": "", "parameter_indicators": { "tp_dest_addr": True, 
"tp_sc_addr": True,
+                                                               "tp_pid": 
False, "tp_dcs": False, "tp_vp": False },
+            "tp_dest_addr": { "length": 11, "ton_npi": { "ext": True, 
"type_of_number": "international",
+                                                          "numbering_plan_id": 
"isdn_e164" },
+                              "call_number": "49301234567" },
+            "tp_sc_addr": { "length": 7, "ton_npi": { "ext": True, 
"type_of_number": "international",
+                                                        "numbering_plan_id": 
"isdn_e164" },
+                            "call_number": "49301234567" },
+            "tp_pid": b"\xff", "tp_dcs": b"\xff", "tp_vp_minutes": 635040 } ),
     ]
     _test_no_pad = True
     class ValidityPeriodAdapter(Adapter):
@@ -299,16 +309,28 @@

     @staticmethod
     def sc_addr_len(ctx):
-        """Compute the length field for an address field (like TP-DestAddr or 
TP-ScAddr)."""
+        """Compute the length field for an address field (see also: 3GPP TS 
24.011, section 8.2.5.2)."""
         if not hasattr(ctx, 'call_number') or len(ctx.call_number) == 0:
             return 0xff
         else:
+            # octets required for the call_number + one octet for ton_npi
             return bytes_for_nibbles(len(ctx.call_number)) + 1

+    @staticmethod
+    def dest_addr_len(ctx):
+        """Compute the length field for an address field (see also: 3GPP TS 
23.040, section 9.1.2.5)."""
+        if not hasattr(ctx, 'call_number') or len(ctx.call_number) == 0:
+            return 0xff
+        else:
+            # number of call_number digits
+            return len(ctx.call_number)
+
     def __init__(self, fid='6f42', sfid=None, name='EF.SMSP', desc='Short 
message service parameters', **kwargs):
         super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(28, 
None), **kwargs)
         ScAddr = Struct('length'/Rebuild(Int8ub, lambda ctx: 
EF_SMSP.sc_addr_len(ctx)),
                         'ton_npi'/TonNpi, 
'call_number'/PaddedBcdAdapter(Rpad(Bytes(10))))
+        DestAddr = Struct('length'/Rebuild(Int8ub, lambda ctx: 
EF_SMSP.dest_addr_len(ctx)),
+                        'ton_npi'/TonNpi, 
'call_number'/PaddedBcdAdapter(Rpad(Bytes(10))))
         self._construct = 
Struct('alpha_id'/COptional(GsmOrUcs2Adapter(Rpad(Bytes(this._.total_len-28)))),
                                  
'parameter_indicators'/InvertAdapter(BitStruct(
                                                                         
Const(7, BitsInteger(3)),
@@ -317,7 +339,7 @@
                                                                         
'tp_pid'/Flag,
                                                                         
'tp_sc_addr'/Flag,
                                                                         
'tp_dest_addr'/Flag)),
-                                 'tp_dest_addr'/ScAddr,
+                                 'tp_dest_addr'/DestAddr,
                                  'tp_sc_addr'/ScAddr,
                                  'tp_pid'/Bytes(1),
                                  'tp_dcs'/Bytes(1),

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/42469?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: I55c123c9e244e5a6e71a0348f5d476ef03e618e8
Gerrit-Change-Number: 42469
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <[email protected]>

Reply via email to