Hoernchen has uploaded this change for review.

View Change

cat: fix Supported Radio Access Technologies state flag

TS 102 223 8.105 codes each supported technology in two bytes:
- the technology from 8.61
- state byte, b1 0 disabled/1 enabled
- b2-b8 RFU

Currently declared as FlagsEnum(Int8ub, enabled=0). kw value is used as
bitmask, so currently:

build {'enabled': True} -> b4 02 08 00 disabled
build {'enabled': False} -> b4 02 08 00 disabled
but parsed 08 00 / 08 01 / 08 ff -> all {'enabled': True}

Use the bit the spec names + tests because well this is so easy that we
don't need tests is apparently not the right approach here..

Change-Id: I4dd16182eb06c99265aabab5d889967b890f6bf2
---
M pySim/cat.py
A tests/unittests/test_cat.py
2 files changed, 67 insertions(+), 1 deletion(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/59/43559/1
diff --git a/pySim/cat.py b/pySim/cat.py
index 8959004..2fda7c5 100644
--- a/pySim/cat.py
+++ b/pySim/cat.py
@@ -729,8 +729,12 @@

# TS 102 223 Section 8.105
class SupportedRadioAccessTechnologies(COMPR_TLV_IE, tag=0xB4):
+ # 2 bytes/entry:
+ # - technology of 8.61
+ # - state byte b1 is 0 disabled/1 enabled
+ # - b2-b8 RFU.
AccessTechTuple = Struct('technology'/AccessTechnology.SingleAccessTech,
- 'state'/FlagsEnum(Int8ub, enabled=0))
+ 'state'/FlagsEnum(Int8ub, enabled=1))
_construct = GreedyRange(AccessTechTuple)

# TS 102 223 Section 8.107
diff --git a/tests/unittests/test_cat.py b/tests/unittests/test_cat.py
new file mode 100644
index 0000000..4e0450c
--- /dev/null
+++ b/tests/unittests/test_cat.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+"""Tests for the CAT (Card Application Toolkit) COMPREHENSION-TLV data objects"""
+
+# (C) 2026 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+#
+# Author: Eric Wild
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# IEs not properly coverd by test_tlvs.py
+
+
+import unittest
+
+from osmocom.utils import b2h, h2b
+
+from pySim.cat import SupportedRadioAccessTechnologies
+
+
+class SupportedRadioAccessTechnologies_Test(unittest.TestCase):
+ """TS 102 223 8.105"""
+
+ def test_enabled_is_encodable(self):
+ """The flag used to have a bm of 0 so enabled -> 00 (that is disabled..)"""
+ ie = SupportedRadioAccessTechnologies(
+ decoded=[{'technology': 'eutran', 'state': {'enabled': True}}])
+ self.assertEqual(b2h(ie.to_tlv()), 'b4020801')
+
+ def test_disabled_differs_from_enabled(self):
+ ie = SupportedRadioAccessTechnologies(
+ decoded=[{'technology': 'eutran', 'state': {'enabled': False}}])
+ self.assertEqual(b2h(ie.to_tlv()), 'b4020800')
+
+ def test_state_byte_is_read_back_faithfully(self):
+ """old 0 bm = all enabled, no way to disable"""
+ for encoded, enabled in [('b4020800', False), ('b4020801', True)]:
+ with self.subTest(encoded=encoded):
+ ie = SupportedRadioAccessTechnologies()
+ ie.from_tlv(h2b(encoded))
+ self.assertEqual(ie.decoded[0]['state']['enabled'], enabled)
+
+ def test_multiple_technologies(self):
+ ie = SupportedRadioAccessTechnologies()
+ ie.from_tlv(h2b('b40408010000'))
+ self.assertEqual([(e['technology'], e['state']['enabled']) for e in ie.decoded],
+ [('eutran', True), ('gsm', False)])
+
+
+
+if __name__ == "__main__":
+ unittest.main()

To view, visit change 43559. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4dd16182eb06c99265aabab5d889967b890f6bf2
Gerrit-Change-Number: 43559
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <ewild@sysmocom.de>