Attention is currently required from: canghaiwuhen, fixeria.
laforge has posted comments on this change by canghaiwuhen. ( https://gerrit.osmocom.org/c/osmo-sgsn/+/41948?usp=email )
Change subject: Modified to dynamically adjust the returned QoS length to ensure compatibility with older modules.
......................................................................
Patch Set 8: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/41948?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: I872d882de4ce186f644b1b3ab684963050709d4f
Gerrit-Change-Number: 41948
Gerrit-PatchSet: 8
Gerrit-Owner: canghaiwuhen <canghaiwuhen(a)gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: canghaiwuhen <canghaiwuhen(a)gmail.com>
Gerrit-Comment-Date: Wed, 28 Jan 2026 10:04:54 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38015?usp=email )
Change subject: pySim.esim.saip: Don't try to generate file contents for MF/DF/ADF
......................................................................
pySim.esim.saip: Don't try to generate file contents for MF/DF/ADF
only EFs have data content
Change-Id: I02a54a3b2f73a0e9118db87f8b514d1dbf53971f
---
M pySim/esim/saip/__init__.py
1 file changed, 2 insertions(+), 0 deletions(-)
Approvals:
Jenkins Builder: Verified
dexter: Looks good to me, approved
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 51b9d1f..6962ee8 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -441,6 +441,8 @@
into the asn.1 encoder. If optimize is True, it will try to encode only the differences from the
fillFileContent of the profile template. Otherwise, the entire file contents will be encoded
as-is."""
+ if not self.file_type in ['TR', 'LF', 'CY', 'BT']:
+ return []
if not optimize:
# simplistic approach: encode the full file, ignoring the template/default
return [('fillFileContent', self.body)]
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38015?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I02a54a3b2f73a0e9118db87f8b514d1dbf53971f
Gerrit-Change-Number: 38015
Gerrit-PatchSet: 6
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/38014?usp=email )
Change subject: pySim.esim.saip: Implement optimized file content encoding
......................................................................
pySim.esim.saip: Implement optimized file content encoding
Make sure we make use of the fill pattern when encoding file contents:
Only encode the differences to the fill pattern of the file, in order
to reduce the profile download size.
Change-Id: I61e4a5e04beba5c9092979fc546292d5ef3d7aad
---
M pySim/esim/saip/__init__.py
M tests/unittests/test_esim_saip.py
2 files changed, 86 insertions(+), 6 deletions(-)
Approvals:
dexter: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 6b6c01c..51b9d1f 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -21,6 +21,8 @@
import os
from typing import Tuple, List, Optional, Dict, Union
from collections import OrderedDict
+from difflib import SequenceMatcher, Match
+
import asn1tools
import zipfile
from pySim import javacard
@@ -44,6 +46,29 @@
logger = logging.getLogger(__name__)
+class NonMatch(Match):
+ """Representing a contiguous non-matching block of data; the opposite of difflib.Match"""
+ @classmethod
+ def from_matchlist(cls, l: List[Match], size:int) -> List['NonMatch']:
+ """Build a list of non-matching blocks of data from its inverse (list of matching blocks).
+ The caller must ensure that the input list is ordered, non-overlapping and only contains
+ matches at equal offsets in a and b."""
+ res = []
+ cur = 0
+ for match in l:
+ if match.a != match.b:
+ raise ValueError('only works for equal-offset matches')
+ assert match.a >= cur
+ nm_len = match.a - cur
+ if nm_len > 0:
+ # there's no point in generating zero-lenth non-matching sections
+ res.append(cls(a=cur, b=cur, size=nm_len))
+ cur = match.a + match.size
+ if size > cur:
+ res.append(cls(a=cur, b=cur, size=size-cur))
+
+ return res
+
class Naa:
"""A class defining a Network Access Application (NAA)"""
name = None
@@ -411,12 +436,38 @@
return ValueError("Unknown key '%s' in tuple list" % k)
return stream.getvalue()
- def file_content_to_tuples(self) -> List[Tuple]:
- # FIXME: simplistic approach. needs optimization. We should first check if the content
- # matches the expanded default value from the template. If it does, return empty list.
- # Next, we should compute the diff between the default value and self.body, and encode
- # that as a sequence of fillFileOffset and fillFileContent tuples.
- return [('fillFileContent', self.body)]
+ def file_content_to_tuples(self, optimize:bool = False) -> List[Tuple]:
+ """Encode the file contents into a list of fillFileContent / fillFileOffset tuples that can be fed
+ into the asn.1 encoder. If optimize is True, it will try to encode only the differences from the
+ fillFileContent of the profile template. Otherwise, the entire file contents will be encoded
+ as-is."""
+ if not optimize:
+ # simplistic approach: encode the full file, ignoring the template/default
+ return [('fillFileContent', self.body)]
+ # Try to 'compress' the file body, based on the default file contents.
+ if self.template:
+ default = self.template.expand_default_value_pattern(length=len(self.body))
+ if not default:
+ sm = SequenceMatcher(a=b'\xff'*len(self.body), b=self.body)
+ else:
+ if default == self.body:
+ # 100% match: return an empty tuple list to make eUICC use the default
+ return []
+ sm = SequenceMatcher(a=default, b=self.body)
+ else:
+ # no template at all: we can only remove padding
+ sm = SequenceMatcher(a=b'\xff'*len(self.body), b=self.body)
+ matching_blocks = sm.get_matching_blocks()
+ # we can only make use of matches that have the same offset in 'a' and 'b'
+ matching_blocks = [x for x in matching_blocks if x.size > 0 and x.a == x.b]
+ non_matching_blocks = NonMatch.from_matchlist(matching_blocks, self.file_size)
+ ret = []
+ cur = 0
+ for block in non_matching_blocks:
+ ret.append(('fillFileOffset', block.a - cur))
+ ret.append(('fillFileContent', self.body[block.a:block.a+block.size]))
+ cur += block.size
+ return ret
def __str__(self) -> str:
return "File(%s)" % self.pe_name
diff --git a/tests/unittests/test_esim_saip.py b/tests/unittests/test_esim_saip.py
index e7e324d..edf6d8d 100755
--- a/tests/unittests/test_esim_saip.py
+++ b/tests/unittests/test_esim_saip.py
@@ -90,5 +90,34 @@
self.assertTrue(oid.OID('1.0.1') > oid.OID('1.0'))
self.assertTrue(oid.OID('1.0.2') > oid.OID('1.0.1'))
+class NonMatchTest(unittest.TestCase):
+ def test_nonmatch(self):
+ # non-matches before, in between and after matches
+ match_list = [Match(a=10, b=10, size=5), Match(a=20, b=20, size=4)]
+ nm_list = NonMatch.from_matchlist(match_list, 26)
+ self.assertEqual(nm_list, [NonMatch(a=0, b=0, size=10), NonMatch(a=15, b=15, size=5),
+ NonMatch(a=24, b=24, size=2)])
+
+ def test_nonmatch_beg(self):
+ # single match at beginning
+ match_list = [Match(a=0, b=0, size=5)]
+ nm_list = NonMatch.from_matchlist(match_list, 20)
+ self.assertEqual(nm_list, [NonMatch(a=5, b=5, size=15)])
+
+ def test_nonmatch_end(self):
+ # single match at end
+ match_list = [Match(a=19, b=19, size=5)]
+ nm_list = NonMatch.from_matchlist(match_list, 24)
+ self.assertEqual(nm_list, [NonMatch(a=0, b=0, size=19)])
+
+ def test_nonmatch_none(self):
+ # no match at all
+ match_list = []
+ nm_list = NonMatch.from_matchlist(match_list, 24)
+ self.assertEqual(nm_list, [NonMatch(a=0, b=0, size=24)])
+
+
+
+
if __name__ == "__main__":
unittest.main()
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38014?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I61e4a5e04beba5c9092979fc546292d5ef3d7aad
Gerrit-Change-Number: 38014
Gerrit-PatchSet: 7
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Attention is currently required from: laforge.
dexter has posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/pysim/+/37925?usp=email )
Change subject: pySim-trace: pySim.apdu_source.stdin_hex
......................................................................
Patch Set 6: Code-Review+2
(1 comment)
File pySim/apdu_source/stdin_hex.py:
https://gerrit.osmocom.org/c/pysim/+/37925/comment/781b7925_2851b5fe?usp=em… :
PS6, Line 36: response = '9000'
Maybe one last suggestion: We should check if the input is empty, otherwise '9000' ends up in parse_cmd_bytes and this may produce error messages that may be confusing to the user.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37925?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I5aacf13b7c27cea9efd42f01dacca61068c3aa33
Gerrit-Change-Number: 37925
Gerrit-PatchSet: 6
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Wed, 28 Jan 2026 09:40:10 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: laforge, neels.
dexter has posted comments on this change by laforge. ( https://gerrit.osmocom.org/c/pysim/+/38015?usp=email )
Change subject: pySim.esim.saip: Don't try to generate file contents for MF/DF/ADF
......................................................................
Patch Set 6: Code-Review+2
(1 comment)
Patchset:
PS6:
I didn't try it out but I had a closer look at the file types described in templates.py. To me this patch looks correct.
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38015?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I02a54a3b2f73a0e9118db87f8b514d1dbf53971f
Gerrit-Change-Number: 38015
Gerrit-PatchSet: 6
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Wed, 28 Jan 2026 09:37:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: canghaiwuhen, fixeria.
pespin has posted comments on this change by canghaiwuhen. ( https://gerrit.osmocom.org/c/osmo-sgsn/+/41948?usp=email )
Change subject: Modified to dynamically adjust the returned QoS length to ensure compatibility with older modules.
......................................................................
Patch Set 8: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/41948?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: I872d882de4ce186f644b1b3ab684963050709d4f
Gerrit-Change-Number: 41948
Gerrit-PatchSet: 8
Gerrit-Owner: canghaiwuhen <canghaiwuhen(a)gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: canghaiwuhen <canghaiwuhen(a)gmail.com>
Gerrit-Comment-Date: Tue, 27 Jan 2026 17:36:36 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes