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
This commit is contained in:
Eric Wild
2026-09-23 17:51:04 +02:00
parent 456c7873eb
commit 6b40fe8546
2 changed files with 69 additions and 1 deletions
+5 -1
View File
@@ -729,8 +729,12 @@ class DnsServerAddress(COMPR_TLV_IE, tag=0xC0):
# 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
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
"""Tests for the CAT (Card Application Toolkit) COMPREHENSION-TLV data objects"""
# (C) 2026 by sysmocom - s.f.m.c. GmbH
# All Rights Reserved
#
# Author: Eric Wild <ewild@sysmocom.de>
#
# 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_encode_technology_enabled(self):
"""The flag used to have a bitmask 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_encode_technology_disabled(self):
ie = SupportedRadioAccessTechnologies(
decoded=[{'technology': 'eutran', 'state': {'enabled': False}}])
self.assertEqual(b2h(ie.to_tlv()), 'b4020800')
def test_decode_technology(self):
"""old 0 bitmask = 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]['technology'], 'eutran')
self.assertEqual(ie.decoded[0]['state']['enabled'], enabled)
def test_decode_technology_multiple(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()