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


Change subject: personalization: SmspTpScAddr edits record 1 of EF.SMSP only
......................................................................

personalization: SmspTpScAddr edits record 1 of EF.SMSP only

SmspTpScAddr decoded the whole EF.SMSP body as record 1 and wrote one
encoded record back as the whole body. EF.SMSP is linear fixed and a
profile can declare more than one record: both TS.48 v5 profiles in
smdpp-data/upp carry a fileDescriptor with record length 42 and no
record count, and efFileSize 84, so two records. While pySim takes the
record count from the template (one record) this goes unnoticed; once
the count follows efFileSize, the body holds both records, decoding all
84 bytes as one record fails on the alpha identifier, and
test_configurable_parameters fails.

Decode and encode record 1 only, and keep the records after it.

The folder osmocom-pysim-saip-record-count of
hampushellsberg-dev/PySIM-upstream-patches on GitHub carries this patch
next to the record count fix that needs it.

Change-Id: I47b1abc97d7b8caad0c74d7af2e5da38e9a895b1
---
M pySim/esim/saip/personalization.py
1 file changed, 8 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/83/43983/1

diff --git a/pySim/esim/saip/personalization.py 
b/pySim/esim/saip/personalization.py
index 5ccface..46cb80a 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -614,8 +614,10 @@
             #print("SMSP (orig): %s" % f_smsp.body)
             # instantiate the pySim.ts_51_011.EF_SMSP class for decode/encode
             ef_smsp = EF_SMSP()
-            # decode the existing file body
-            ef_smsp_dec = ef_smsp.decode_record_bin(f_smsp.body, 1)
+            # decode the first record; a profile may declare more than one 
(efFileSize), and the
+            # File body then holds all of them
+            rec_len = f_smsp.rec_len
+            ef_smsp_dec = ef_smsp.decode_record_bin(f_smsp.body[:rec_len], 1)
             # patch the actual number
             ef_smsp_dec['tp_sc_addr']['call_number'] = digits
             # patch the NPI to isdn_e164
@@ -644,8 +646,9 @@
             # f_smsp.rec_len = 42
             # but leave rec_len unchanged to keep the same length as was found 
in the eSIM template.

-            # re-encode into the File body.
-            f_smsp.body = ef_smsp.encode_record_bin(ef_smsp_dec, 1, 
total_len=f_smsp.rec_len)
+            # re-encode the first record into the File body, keeping any 
records after it.
+            record = ef_smsp.encode_record_bin(ef_smsp_dec, 1, 
total_len=rec_len)
+            f_smsp.body = record + (f_smsp.body[rec_len:] if rec_len else b'')
             # re-generate the pe.decoded member from the File instance
             pe.file2pe(f_smsp)

@@ -654,7 +657,7 @@
         for pe in pes.get_pes_for_type('usim'):
             f_smsp = pe.files['ef-smsp']
             ef_smsp = EF_SMSP()
-            ef_smsp_dec = ef_smsp.decode_record_bin(f_smsp.body, 1)
+            ef_smsp_dec = 
ef_smsp.decode_record_bin(f_smsp.body[:f_smsp.rec_len], 1)

             tp_sc_addr = ef_smsp_dec.get('tp_sc_addr', None)


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

Reply via email to