lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

September 2026

  • 1 participants
  • 1894 discussions
[XS] Change in pysim[master]: cat: fix TS 102 223 8.61 Access technology coding
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43560?usp=email ) Change subject: cat: fix TS 102 223 8.61 Access technology coding ...................................................................... cat: fix TS 102 223 8.61 Access technology coding Spelling mistakes and new values missing. Change-Id: I74f361cd5b818079636f399cb8c1b1c609b9e1f2 --- M pySim/cat.py 1 file changed, 3 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/60/43560/1 diff --git a/pySim/cat.py b/pySim/cat.py index 2fda7c5..991dd40 100644 --- a/pySim/cat.py +++ b/pySim/cat.py @@ -536,9 +536,9 @@ # TS 102 223 Section 8.61 class AccessTechnology(COMPR_TLV_IE, tag=0xBF): - SingleAccessTech = Enum(Int8ub, gsm=0, tia_eia_533=1, tia_eia_136_270=2, utran=3, tetra=4, - tia_eia_95_b=5, cdma1000_1x=6, cdma2000_hrpd=7, eutran=8, - ehrpd=9, nr=0x0a) + SingleAccessTech = Enum(Int8ub, gsm=0, tia_eia_553=1, tia_eia_136_270=2, utran=3, tetra=4, + tia_eia_95_b=5, cdma2000_1x=6, cdma2000_hrpd=7, eutran=8, + ehrpd=9, nr=0x0a, satellite_nr=0x0b, satellite_eutran=0x0c) _construct = GreedyRange(SingleAccessTech) # TS 102 223 Section 8.63 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43560?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: I74f361cd5b818079636f399cb8c1b1c609b9e1f2 Gerrit-Change-Number: 43560 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[M] Change in pysim[master]: cat: fix Supported Radio Access Technologies state flag
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43559?usp=email ) Change subject: cat: fix Supported Radio Access Technologies state flag ...................................................................... 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(a)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 https://gerrit.osmocom.org/c/pysim/+/43559?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: I4dd16182eb06c99265aabab5d889967b890f6bf2 Gerrit-Change-Number: 43559 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[S] Change in pysim[master]: bip: answer proactive commands the relay does not implement
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43558?usp=email ) Change subject: bip: answer proactive commands the relay does not implement ...................................................................... bip: answer proactive commands the relay does not implement pySim-smpp2sim currently claims to support every feature flag that exists, but this immediately dies here with a SJA5: NotImplementedError: No handler method for ProvideLocalInformation(...) Answer anything unhandled with "performed_successfully" and log. Never "command_beyond_terminal_capability", tho, answering that for PROVIDE LOCAL INFORMATION refuses to open the session at all. Change-Id: I1e55d6f88c872a04b89a3946dd840d30b329621e --- M pySim/bip.py 1 file changed, 19 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/58/43558/1 diff --git a/pySim/bip.py b/pySim/bip.py index e5ec029..14c75bc 100644 --- a/pySim/bip.py +++ b/pySim/bip.py @@ -203,6 +203,25 @@ self.sms_sink = sms_sink self.channels = ProactChannels(on_data_available=self._on_channel_data_available) + def receive_fetch(self, pcmd: ProactiveCommand): + """Answer anything this handler has no specific handler for. + + A card coming up will usually issue PROVIDE LOCAL INFORMATION, + POLL INTERVAL or TIMER MANAGEMENT before it gets anywhere near a BIP channel + because we claim to support every feature flag there is. + + Note that this is not the spec-correct answer. TS 102 223 6.8.7 + says a successful TERMINAL RESPONSE to PROVIDE LOCAL INFORMATION "shall" carry the + requested Local information data object, and 6.8.13/6.8.14 says the same for TIMER + MANAGEMENT, this returns empty results for all of them, which works with real cards. + + Always "performed_successfully", never "command_beyond_terminal_capability" because + answering that to PROVIDE LOCAL INFORMATION makes a card refuse to open the session. + """ + logger.info("no handler for %s, answering performed_successfully", + type(pcmd.decoded).__name__) + return self.prepare_response(pcmd, 'performed_successfully') + @staticmethod def _find_first_element_of_type(instlist, cls): for i in instlist: -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43558?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: I1e55d6f88c872a04b89a3946dd840d30b329621e Gerrit-Change-Number: 43558 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[XS] Change in pysim[master]: osmo-smdpp: case insensitive comp of ES9+ SM-DP+ address
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43562?usp=email ) Change subject: osmo-smdpp: case insensitive comp of ES9+ SM-DP+ address ...................................................................... osmo-smdpp: case insensitive comp of ES9+ SM-DP+ address Do what the comment above the line already says.. Change-Id: Ie0738e810572ea3312c885ec8aaa2da4b8b12cd7 --- M osmo-smdpp.py 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/62/43562/1 diff --git a/osmo-smdpp.py b/osmo-smdpp.py index ef214a9..5ac08df 100755 --- a/osmo-smdpp.py +++ b/osmo-smdpp.py @@ -525,7 +525,7 @@ """See ES9+ InitiateAuthentication SGP.22 Section 5.6.1""" # Verify that the received address matches its own SM-DP+ address, where the comparison SHALL be # case-insensitive. Otherwise, the SM-DP+ SHALL return a status code "SM-DP+ Address - Refused". - if content['smdpAddress'] != self.server_hostname: + if content['smdpAddress'].lower() != self.server_hostname.lower(): raise ApiError('8.8.1', '3.8', 'Invalid SM-DP+ Address') euiccChallenge = b64decode(content['euiccChallenge']) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43562?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: Ie0738e810572ea3312c885ec8aaa2da4b8b12cd7 Gerrit-Change-Number: 43562 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[M] Change in pysim[master]: bip: refuse OPEN CHANNEL with a TERMINAL RESPONSE
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43563?usp=email ) Change subject: bip: refuse OPEN CHANNEL with a TERMINAL RESPONSE ...................................................................... bip: refuse OPEN CHANNEL with a TERMINAL RESPONSE handle_OpenChannel() raises where TS 102 223 demands a TERMINAL RESPONSE. Raising takes the whole proactive session down with it. All four are a BIP errors and differ only in the cause byte of 8.12.11. Change-Id: If8f01e6acb9cb3f7af952a0760fc093db81be53a --- M pySim/bip.py M tests/unittests/test_bip_relay.py 2 files changed, 106 insertions(+), 11 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/63/43563/1 diff --git a/pySim/bip.py b/pySim/bip.py index 14c75bc..8370b5b 100644 --- a/pySim/bip.py +++ b/pySim/bip.py @@ -356,26 +356,53 @@ other_addr_ie = Proact._find_first_element_of_type(pcmd.children, OtherAddress) bearer_desc_ie = Proact._find_first_element_of_type(pcmd.children, BearerDescription) buffer_size_ie = Proact._find_first_element_of_type(pcmd.children, BufferSize) - if transp_lvl_ie.decoded['protocol_type'] != 'tcp_uicc_client_remote': - raise ValueError('Unsupported protocol_type') - if other_addr_ie.decoded.get('type_of_address', None) != 'ipv4': - raise ValueError('Unsupported type_of_address') + + def refuse(additional_information: str, chan_nr: int = 0): + """TERMINAL RESPONSE refusing the OPEN CHANNEL + + - always a BIP error, only the cause byte of TS 102 223 8.12.11 differs + - chan_nr 0 -> "no channel available" in the Channel status, 8.56 + - 6.8.18, 6.8.20, 6.8.21 want chan status, Bearer desc and buf size + in a successful or unsuccessful response + """ + ies = [ChannelStatus(decoded=self._channel_status(chan_nr, established=False))] + ies += [ie for ie in (bearer_desc_ie, buffer_size_ie) if ie is not None] + return self._bip_response_head(pcmd, 'bearer_independent_protocol_error', + additional_information) + ies + + # UICC/terminal interface transport level is Optional, TS 102 223 6.6.27.x. Absent means + # the CAT application runs its own network and transport layer, which we do not do. + if transp_lvl_ie is None or transp_lvl_ie.decoded['protocol_type'] != 'tcp_uicc_client_remote': + logger.warning("OpenChannel: unsupported UICC/terminal interface transport level (%s) " + "-> refusing", transp_lvl_ie.decoded if transp_lvl_ie else '(absent)') + return refuse('requested_uicc_if_transp_level_not_available') + if other_addr_ie is None or other_addr_ie.decoded.get('type_of_address', None) != 'ipv4': + # No cause byte fits a wrong address family. '06' is about the transport level data + # object, and 8.12.11 leaves '14' ("IPv4 only allowed") reserved by 3GPP, so '00'. + logger.warning("OpenChannel: unsupported data destination address (%s) -> refusing", + other_addr_ie.decoded if other_addr_ie else '(absent)') + return refuse('no_specific_cause') addr_bytes = h2b(other_addr_ie.decoded['address']) if isinstance( other_addr_ie.decoded['address'], str) else other_addr_ie.decoded['address'] ipv4_str = '%u.%u.%u.%u' % (addr_bytes[0], addr_bytes[1], addr_bytes[2], addr_bytes[3]) port_nr = transp_lvl_ie.decoded['port_number'] logger.info("OpenChannel: connecting to %s:%u", ipv4_str, port_nr) - channel = self.channels.channel_create() + try: + channel = self.channels.channel_create() + except ValueError: + # TS 102 223 6.4.27.2 and 6.4.27.3: no channel left -> BIP error + logger.warning("OpenChannel: all %u channels are in use -> refusing", + len(self.channels.channels)) + return refuse('no_channel_availabile') # yes, blocking connect() try: channel.connect(ipv4_str, port_nr) except OSError as e: logger.warning("OpenChannel: connect to %s:%u failed: %s", ipv4_str, port_nr, e) self.channels.channel_delete(channel.chan_nr) - return self._bip_response_head(pcmd, 'bearer_independent_protocol_error', - 'channel_closed') + [ - ChannelStatus(decoded=self._channel_status(channel.chan_nr, established=False)), - bearer_desc_ie, buffer_size_ie] + # TS 102 223 6.4.30 is the only clause naming a cause for a link that could not be + # established: BIP error, channel closed. 6.4.27.4 lists no error cases at all. + return refuse('channel_closed', channel.chan_nr) # Terminal Response example: [ # {'command_details': {'command_number': 1, diff --git a/tests/unittests/test_bip_relay.py b/tests/unittests/test_bip_relay.py index cf11b7f..8716585 100644 --- a/tests/unittests/test_bip_relay.py +++ b/tests/unittests/test_bip_relay.py @@ -91,6 +91,17 @@ ]) +def _open_channel_raw(extra_ies, cmd_nr=1): + """OPEN CHANNEL with only the head data""" + return _pcmd([ + CommandDetails(decoded={'command_number': cmd_nr, 'type_of_command': 'open_channel', + 'command_qualifier': 3}).to_tlv(), + DeviceIdentities(decoded={'source_dev_id': 'uicc', 'dest_dev_id': 'terminal'}).to_tlv(), + BearerDescription(decoded={'bearer_type': 'default', 'bearer_parameters': b''}).to_tlv(), + BufferSize(decoded=1024).to_tlv(), + ] + extra_ies) + + def _send_data(payload, chan='channel_1', cmd_nr=1): return _pcmd([ CommandDetails(decoded={'command_number': cmd_nr, 'type_of_command': 'send_data', @@ -252,8 +263,65 @@ self.assertEqual(_first(til, ChannelDataLength).decoded, 0) -if __name__ == "__main__": - unittest.main() +class OpenChannelRefusalTest(unittest.TestCase): + """Refusal is a TERMINAL RESPONSE, not an exception, raising takes the whole + proactive session down and leaves the card wondering why""" + + ADDR = OtherAddress(decoded={'type_of_address': 'ipv4', 'address': bytes([127, 0, 0, 1])}) + TCP = UiccTransportLevel(decoded={'protocol_type': 'tcp_uicc_client_remote', 'port_number': 1234}) + + def setUp(self): + self.proact = Proact() + self.addCleanup(self._close_all_channels) + + def _close_all_channels(self): + for chan in list(self.proact.channels.channels.values()): + try: + chan.close() + except Exception: + pass + + def _assert_refused(self, til, additional_information, chan_nr=0): + b''.join(x.to_tlv() for x in til) # must serialise, the transport posts it + res = _first(til, Result).decoded + self.assertEqual(res['general_result'], 'bearer_independent_protocol_error') + self.assertEqual(res['additional_information'], additional_information) + self.assertEqual(_first(til, ChannelStatus).decoded, '%02x00' % chan_nr) # 8.56 + self.assertIsNotNone(_first(til, BearerDescription)) # 6.8.20 + self.assertIsNotNone(_first(til, BufferSize)) # 6.8.21 + self.assertEqual(b2h(_first(til, DeviceIdentities).to_tlv()), '82028281') # 6.8.2 + + def test_transport_level(self): + udp = UiccTransportLevel(decoded={'protocol_type': 'udp_uicc_client_remote', + 'port_number': 1234}) + for extra in ([self.ADDR.to_tlv()], # absent, 6.6.27.x Optional + [udp.to_tlv(), self.ADDR.to_tlv()]): # not TCP client remote + with self.subTest(extra=len(extra)): + self._assert_refused(self.proact.handle_OpenChannel(_open_channel_raw(extra)), + 'requested_uicc_if_transp_level_not_available') + + def test_destination_address(self): + v6 = OtherAddress(decoded={'type_of_address': 'ipv6', 'address': bytes(16)}) + for extra in ([self.TCP.to_tlv()], # absent + [self.TCP.to_tlv(), v6.to_tlv()]): # not IPv4 + with self.subTest(extra=len(extra)): + self._assert_refused(self.proact.handle_OpenChannel(_open_channel_raw(extra)), + 'no_specific_cause') + + def test_no_channel_left(self): + for _ in range(7): # 6.4.27.2, 6.4.27.3 + self.proact.channels.channel_create() + cmd = _open_channel_raw([self.TCP.to_tlv(), self.ADDR.to_tlv()]) + self._assert_refused(self.proact.handle_OpenChannel(cmd), 'no_channel_availabile') + + def test_connect_failure(self): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # port nothing listens on + s.bind(('127.0.0.1', 0)) + dead_port = s.getsockname()[1] + s.close() + til = self.proact.handle_OpenChannel(_open_channel(dead_port)) + self._assert_refused(til, 'channel_closed', chan_nr=1) # 6.4.30 + self.assertEqual(self.proact.channels.channels, {}) # channel given back class BipSinkTest(unittest.TestCase): -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43563?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: If8f01e6acb9cb3f7af952a0760fc093db81be53a Gerrit-Change-Number: 43563 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[M] Change in pysim[master]: cat: properly decode IMEI/IMEISV IE
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43561?usp=email ) Change subject: cat: properly decode IMEI/IMEISV IE ...................................................................... cat: properly decode IMEI/IMEISV IE Currently BcdAdapter(GreedyBytes), a plain swapped nibble digit string, which is wrong, it is not a bcd string. See TS 124.008 10.5.1.4 figure 10.5.4 + table 10.5.4 It currently - decodes framing nibble as digit - encodes a 15 digit IMEI as 7 bytes, wrong len, dropped last digit Fix this, while at it add the 8.74 IMEISV as well + tests for the framing because the current round trip missed all of this. Change-Id: Iad7aea77513d413c338edc18ef1bcc37488ae849 --- M pySim/cat.py M tests/unittests/test_cat.py M tests/unittests/test_tlvs.py 3 files changed, 115 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/61/43561/1 diff --git a/pySim/cat.py b/pySim/cat.py index 991dd40..8e072d8 100644 --- a/pySim/cat.py +++ b/pySim/cat.py @@ -22,7 +22,7 @@ from bidict import bidict from construct import Int8ub, Int16ub, Byte, BitsInteger from construct import Struct, Enum, BitStruct, this -from construct import Switch, GreedyRange, FlagsEnum +from construct import Switch, GreedyRange, FlagsEnum, Adapter from osmocom.tlv import TLV_IE, COMPR_TLV_IE, BER_TLV_IE, TLV_IE_Collection from osmocom.construct import PlmnAdapter, BcdAdapter, GsmStringAdapter, TonNpi, GsmString, Bytes, GreedyBytes from osmocom.utils import b2h, h2b @@ -320,9 +320,52 @@ class LocationInformation(COMPR_TLV_IE, tag=0x93): pass -# TS 102 223 Section 8.20 +class MobileIdentityAdapter(Adapter): + """TS 124.008 section 10.5.1.4 figure 10.5.4 + table 10.5.4 + + NOT a plain BCD string: + - bits 1-3 type of identity + odd/even bit 4 + - digit 1 in bits 5-8, following octets contain 2 digits, low nibble first + - if even length: high nibble of last octet 1111 + So IMEI IE of 8 bytes is 15 digits + framing nibble.""" + + # Table 10.5.4 bits 321 + TYPE_IMSI = 1 + TYPE_IMEI = 2 + TYPE_IMEISV = 3 + + def __init__(self, subcon, type_of_identity: int): + super().__init__(subcon) + self.type_of_identity = type_of_identity + + def _decode(self, obj, context, path): + data = bytes(obj) + if not data: + return '' + odd = bool(data[0] & 0x08) # bit 4: 1 = odd number of digits + digits = '%x' % (data[0] >> 4) # bits 5-8: digit 1 + for octet in data[1:]: + digits += '%x%x' % (octet & 0x0f, octet >> 4) + if not odd: + digits = digits[:-1] # drop the 1111 end mark + return digits + + def _encode(self, obj, context, path): + digits = str(obj) + odd = len(digits) % 2 + first = (int(digits[0], 16) << 4) | (0x08 if odd else 0x00) | self.type_of_identity + rest = digits[1:] if odd else digits[1:] + 'f' + return bytes([first]) + bytes((int(rest[i+1], 16) << 4) | int(rest[i], 16) + for i in range(0, len(rest), 2)) + +# TS 102 223 Section 8.20, len is fixed at 8: "The IMEI is coded [..] as the +# value part of the Mobile Identity IE as specified in TS 124 008", and the +# IMEI itself is the 15 digits of TS 123 003. class IMEI(COMPR_TLV_IE, tag=0x94): - _construct = BcdAdapter(GreedyBytes) + _test_de_encode = [ + ( '94081a32547698103254', '123456789012345' ), + ] + _construct = MobileIdentityAdapter(GreedyBytes, MobileIdentityAdapter.TYPE_IMEI) # TS 102 223 Section 8.21 class HelpRequest(COMPR_TLV_IE, tag=0x95): @@ -596,6 +639,14 @@ eutran_inter_rat_utran=0x08, eutran_inter_rat_nr=0x09) +# TS 102 223 Section 8.74, length is not fixed, because IMEISV is 16 digits per TS 123.003 +# -> even count needs the '1111' end mark and is 9 bytes long +class IMEISV(COMPR_TLV_IE, tag=0xE2): + _test_de_encode = [ + ( 'e2091332547698103254f6', '1234567890123456' ), + ] + _construct = MobileIdentityAdapter(GreedyBytes, MobileIdentityAdapter.TYPE_IMEISV) + # TS 102 223 Section 8.75 class NetworkSearchMode(COMPR_TLV_IE, tag=0xE5): _construct = Enum(Int8ub, manual=0, automatic=1) diff --git a/tests/unittests/test_cat.py b/tests/unittests/test_cat.py index 4e0450c..c6324c2 100644 --- a/tests/unittests/test_cat.py +++ b/tests/unittests/test_cat.py @@ -25,7 +25,66 @@ from osmocom.utils import b2h, h2b -from pySim.cat import SupportedRadioAccessTechnologies +from pySim.cat import IMEI, IMEISV, AccessTechnology, SupportedRadioAccessTechnologies + + +class IMEI_Test(unittest.TestCase): + """TS 102 223 8.20: the IMEI IE is 8 bytes, coded as valie part of Mobile Identity IE from 124 008""" + + IMEI_15 = '123456789012345' + ENCODED = '94081a32547698103254' + + def test_encode_is_eight_bytes(self): + """15 digits in 8 byte: 16 nibbles, one is type/parity framing.""" + tlv = IMEI(decoded=self.IMEI_15).to_tlv() + self.assertEqual(b2h(tlv), self.ENCODED) + self.assertEqual(tlv[1], 0x08) # spec len 8 + self.assertEqual(len(tlv) - 2, 8) + + def test_first_octet_framing(self): + """TS 24.008 table 10.5.4""" + octet1 = IMEI(decoded=self.IMEI_15).to_tlv()[2] + self.assertEqual(octet1 & 0x07, 2) # IMEI + self.assertEqual((octet1 >> 3) & 0x01, 1) # odd + self.assertEqual(octet1 >> 4, 1) # digit 1 + + def test_decodes_to_the_raw_imei(self): + """strip framing nibble""" + ie = IMEI() + ie.from_tlv(h2b(self.ENCODED)) + self.assertEqual(ie.decoded, self.IMEI_15) + + def test_even_digit_count_uses_the_end_mark(self): + """"end marker, IMEISV case""" + ie = IMEI(decoded='1234567890123456') + tlv = ie.to_tlv() + self.assertEqual(tlv[2] >> 3 & 0x01, 0) # even + self.assertEqual(tlv[-1] >> 4, 0x0f) # end mark + back = IMEI() + back.from_tlv(tlv) + self.assertEqual(back.decoded, '1234567890123456') + + +class IMEISV_Test(unittest.TestCase): + """TS 102 223 8.74, no fixed len, end marker""" + + IMEISV_16 = '1234567890123456' + ENCODED = 'e2091332547698103254f6' + + def test_encode(self): + self.assertEqual(b2h(IMEISV(decoded=self.IMEISV_16).to_tlv()), self.ENCODED) + + def test_type_of_identity_and_end_mark(self): + value = IMEISV(decoded=self.IMEISV_16).to_tlv()[2:] + self.assertEqual(value[0] & 0x07, 3) # IMEISV + self.assertEqual((value[0] >> 3) & 0x01, 0) # even + self.assertEqual(value[-1] >> 4, 0x0f) # end mark + self.assertEqual(len(value), 9) + + def test_decode(self): + ie = IMEISV() + ie.from_tlv(h2b(self.ENCODED)) + self.assertEqual(ie.decoded, self.IMEISV_16) class SupportedRadioAccessTechnologies_Test(unittest.TestCase): diff --git a/tests/unittests/test_tlvs.py b/tests/unittests/test_tlvs.py index 7f1b72b..71eaa05 100755 --- a/tests/unittests/test_tlvs.py +++ b/tests/unittests/test_tlvs.py @@ -21,6 +21,7 @@ from osmocom.utils import b2h, h2b, all_subclasses from osmocom.tlv import * +import pySim.cat import pySim.iso7816_4 import pySim.ts_102_221 import pySim.ts_102_222 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43561?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: Iad7aea77513d413c338edc18ef1bcc37488ae849 Gerrit-Change-Number: 43561 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[M] Change in pysim[master]: bip: report a location in PROVIDE LOCAL INFORMATION
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43565?usp=email ) Change subject: bip: report a location in PROVIDE LOCAL INFORMATION ...................................................................... bip: report a location in PROVIDE LOCAL INFORMATION TS 102 223 6.8.7: TERMINAL RESPONSE shall contain the data object the command qualifier (6.6.15) asked for. The card always asks for location information, so at least answer 00, with the GERAN form of TS 131.111 8.19.1, PLMN 262-01. Do not answer "terminal currently unable to process - no service"... Change-Id: I53547da2ea9f0a4ea7a4dd032985a546f2d4277f --- M pySim/bip.py M pySim/cat.py M tests/unittests/test_bip_relay.py 3 files changed, 56 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/65/43565/1 diff --git a/pySim/bip.py b/pySim/bip.py index b25fe5f..1880bd0 100644 --- a/pySim/bip.py +++ b/pySim/bip.py @@ -42,10 +42,16 @@ from pySim.cat import (ProactiveCommand, SendShortMessage, SMS_TPDU, SMSPPDownload, BearerDescription, DeviceIdentities, Address, OtherAddress, UiccTransportLevel, BufferSize, ChannelStatus, ChannelData, - ChannelDataLength, EventList, EventDownload, Result) + ChannelDataLength, EventList, EventDownload, Result, + CommandDetails, LocationInformation) logger = logging.getLogger(__name__) +# PROVIDE LOCAL INFORMATION location, GERAN TS 31.111 8.19.1 +# - 3 byte PLMN of TS 24.008 10.5.1.3 -> 262-01 +# - 2 byte LAC and a 2 byte cid. +DEFAULT_LOCATION = h2b('62f21000010001') + def terminal_profile(num_channels: int = 7) -> bytes: """TERMINAL PROFILE for what we implement, TS 102 223 5.2 and annex T. @@ -226,7 +232,7 @@ class Proact(ProactiveHandler): #def __init__(self, smpp_factory): # self.smpp_factory = smpp_factory - def __init__(self, data_available_sink=None, sms_sink=None): + def __init__(self, data_available_sink=None, sms_sink=None, location: bytes = DEFAULT_LOCATION): # data_available_sink(envelope_hex) delivers ENVELOPE EVENT DOWNLOAD # to the card when socket data arrives # None in card free/test mode @@ -235,8 +241,24 @@ # onwards; pySim-smpp2sim.py hands it to its SMPP server. None -> log # and drop. self.sms_sink = sms_sink + self.location = location self.channels = ProactChannels(on_data_available=self._on_channel_data_available) + def handle_ProvideLocalInformation(self, pcmd: ProactiveCommand): + """only location + + TS 102 223 6.8.7 says TERMINAL RESPONSE to PROVIDE LOCAL INFORMATION "shall" + contain the data object the command qualifier (6.6.15) asked for. At least answer '00', + location information, usually requested. + + answering "terminal currently unable to process - no service", which is a handset + out of coverage makes SJA5 believe it and postpones the entire session! + it registers a location status event, starts a ten minute timer and waits for coverage.""" + cmd_det_ie = Proact._find_first_element_of_type(pcmd.children, CommandDetails) + if cmd_det_ie is not None and cmd_det_ie.decoded['command_qualifier'] == 0x00: + return self.prepare_response(pcmd) + [LocationInformation(decoded=self.location)] + return self.prepare_response(pcmd) + def receive_fetch(self, pcmd: ProactiveCommand): """Answer anything this handler has no specific handler for. diff --git a/pySim/cat.py b/pySim/cat.py index 8e072d8..61526d8 100644 --- a/pySim/cat.py +++ b/pySim/cat.py @@ -318,7 +318,9 @@ # TS 102 223 Section 8.19 class LocationInformation(COMPR_TLV_IE, tag=0x93): - pass + # 8.19: coding is per access technology, and the lengths differ (TS 131.111 8.19.1-.4: GERAN 7, + # UTRAN/E-UTRAN 9, NG-RAN 11) with nothing in the IE to say which -> keep the value opaque. + _construct = GreedyBytes class MobileIdentityAdapter(Adapter): """TS 124.008 section 10.5.1.4 figure 10.5.4 + table 10.5.4 diff --git a/tests/unittests/test_bip_relay.py b/tests/unittests/test_bip_relay.py index e7229d7..5f36823 100644 --- a/tests/unittests/test_bip_relay.py +++ b/tests/unittests/test_bip_relay.py @@ -25,7 +25,7 @@ from pySim.cat import (ProactiveCommand, CommandDetails, DeviceIdentities, BearerDescription, BufferSize, UiccTransportLevel, OtherAddress, ChannelData, ChannelDataLength, ChannelStatus, - Result) + Result, LocationInformation) from pySim.bip import Proact, ProactChannels, terminal_profile @@ -324,6 +324,34 @@ self.assertEqual(self.proact.channels.channels, {}) # channel given back +class ProvideLocalInformationTest(unittest.TestCase): + """TS 102 223 6.8.7: only 00 gets a data object; the rest keeps the empty result.""" + + def _cmd(self, qualifier): + return _pcmd([ + CommandDetails(decoded={'command_number': 1, 'type_of_command': 'provide_local_info', + 'command_qualifier': qualifier}).to_tlv(), + DeviceIdentities(decoded={'source_dev_id': 'uicc', 'dest_dev_id': 'terminal'}).to_tlv()]) + + def test_location(self): + til = Proact().handle_ProvideLocalInformation(self._cmd(0x00)) + b''.join(x.to_tlv() for x in til) + self.assertEqual(_first(til, Result).decoded['general_result'], 'performed_successfully') + self.assertEqual(b2h(_first(til, LocationInformation).to_tlv()), '930762f21000010001') + self.assertEqual(b2h(_first(til, DeviceIdentities).to_tlv()), '82028281') # 6.8.2 + + def test_other_qualifiers_get_no_data_object(self): + for qualifier in (0x01, 0x03, 0x04, 0x1a): + with self.subTest(command_qualifier=qualifier): + til = Proact().handle_ProvideLocalInformation(self._cmd(qualifier)) + b''.join(x.to_tlv() for x in til) + self.assertIsNone(_first(til, LocationInformation)) + + def test_location_is_configurable(self): + til = Proact(location=h2b('26f8100539')).handle_ProvideLocalInformation(self._cmd(0x00)) + self.assertEqual(b2h(_first(til, LocationInformation).to_tlv()), '930526f8100539') + + class TerminalProfileTest(unittest.TestCase): """TS 102 223 5.2, one bit per CAT facility""" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43565?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: I53547da2ea9f0a4ea7a4dd032985a546f2d4277f Gerrit-Change-Number: 43565 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[M] Change in pysim[master]: contrib: add scp81 OTA trigger builder
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43566?usp=email ) Change subject: contrib: add scp81 OTA trigger builder ...................................................................... contrib: add scp81 OTA trigger builder Change-Id: Ic646626319cd7a26195d0ffff55900032abcddeb --- A contrib/scp81_trigger.py 1 file changed, 99 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/66/43566/1 diff --git a/contrib/scp81_trigger.py b/contrib/scp81_trigger.py new file mode 100644 index 0000000..00cd269 --- /dev/null +++ b/contrib/scp81_trigger.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +"""scp81_trigger.py -- build the OTA packet that asks the card to open an SCP81 admin session.""" + +# (C) 2026 by sysmocom - s.f.m.c. GmbH <info(a)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/>. + + +# Prints the apdu line for AdmSessTriggerParams TLV as the sms secured data, Expanded RFM mode, +# to be fed into pysim_shell.py +# +# security params supplied either +# - in the trigger +# - from the cards data object, +# trigger wins when both are present. +# --no-sec omits them from the trigger so the stored ones are used. +# +# example params: +# --psk-id 'PSK Identity 123' --kvn 0x41 --kid-ref 5 +# --ip 127.0.0.1 --port 8080 --buffer 512 +# --host 172.96.0.1 --uri '/server/adminagent?cmd=1' + +import argparse +import sys + +from osmocom.utils import b2h # noqa: E402 +from pySim.cat import (sms_pp_download_envelope, BearerDescription, # noqa: E402 + BufferSize, UiccTransportLevel, OtherAddress) +from pySim.global_platform.http import (AdmSessTriggerParams, AdmSessionParams, # noqa: E402 + SecurityParams, HttpPostParams, RasConnectionParams, + AdminHostParam, AdminUriParam) + + +def main(): + ap = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + ap.add_argument("--psk-id", help="PSK identity for ClientHello (required unless --no-sec)") + ap.add_argument("--kvn", type=lambda s: int(s, 0), help="key version of the PSK (required unless --no-sec)") + ap.add_argument("--kid-ref", type=lambda s: int(s, 0), help="PSK key id (required unless --no-sec)") + ap.add_argument("--host", help="HTTP Host header (required unless --no-http)") + ap.add_argument("--uri", help="HTTP request URI (required unless --no-http)") + ap.add_argument("--ip", help="administration server address, BIP (required unless --no-conn)") + ap.add_argument("--port", type=int, help="administration server port (required unless --no-conn)") + ap.add_argument("--buffer", type=int, help="BIP buffer size (required unless --no-conn)") + ap.add_argument("--no-conn", action="store_true", help="omit the connection params (tag 0x84)") + ap.add_argument("--no-sec", action="store_true", help="omit the security params (tag 0x85)") + ap.add_argument("--no-http", action="store_true", help="omit the HTTP POST params (tag 0x89)") + + args = ap.parse_args() + + missing = [] + if not args.no_conn: + missing += [n for n in ('ip', 'port', 'buffer') if getattr(args, n) is None] + if not args.no_sec: + missing += [n for n in ('psk_id', 'kvn', 'kid_ref') if getattr(args, n) is None] + if not args.no_http: + missing += [n for n in ('host', 'uri') if getattr(args, n) is None] + if missing: + ap.error("pass every value required: %s." % " ".join("--" + n.replace('_', '-') for n in missing)) + + session = [] + if not args.no_conn: + session.append(RasConnectionParams(children=[ + BearerDescription(decoded={'bearer_type': 'default', 'bearer_parameters': ''}), + BufferSize(decoded=args.buffer), + UiccTransportLevel(decoded={'protocol_type': 'tcp_uicc_client_remote', + 'port_number': args.port}), + OtherAddress(decoded={'type_of_address': 'ipv4', + 'address': bytes(int(b) for b in args.ip.split("."))})])) + if not args.no_sec: + session.append(SecurityParams(decoded={'psk_id': args.psk_id.encode(), 'kvn': args.kvn, + 'kid': args.kid_ref, 'sha_type': None})) + if not args.no_http: + session.append(HttpPostParams(children=[AdminHostParam(decoded=args.host), + AdminUriParam(decoded=args.uri)])) + trig = AdmSessTriggerParams(children=[AdmSessionParams(children=session)]).to_tlv() + + # stderr for logs, stdout for data + print("# trigger TLV %d B %s" % (len(trig), trig.hex()), file=sys.stderr) + print("# %-13s %d B %s" % ("secured data", len(trig), trig.hex()), file=sys.stderr) + print(trig.hex()) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43566?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: Ic646626319cd7a26195d0ffff55900032abcddeb Gerrit-Change-Number: 43566 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[M] Change in pysim[master]: bip/smpp2sim: TERMINAL PROFILE that matches what we do
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43564?usp=email ) Change subject: bip/smpp2sim: TERMINAL PROFILE that matches what we do ...................................................................... bip/smpp2sim: TERMINAL PROFILE that matches what we do pySim-smpp2sim sends "ff" * 32, that byte list tells every card the terminal has a display, a keypad, a second card slot, a radio it can query for location and NMR, five BIP bearers and six transport modes and a toaster and a dog according to TS 102 223 5.2 We only have the twelfth byte and one bit of the seventeenth and no dog. A card issues annoying weird things like PROVIDE LOCAL INFORMATION or UDP only because the profile said so, so stop pretending we know what any of that is. Annex T table T.1 lists what a Connected Entity (a CAT client that is not the modem) may announce. Announce that and the SMS-PP download and SEND SHORT MESSAGE bits the OTA path needs, only the bearer is obviously made up, it's the host TCP stack and 5.2 closest match is GPRS. We can still extend and change all of this, but for now something that works and constrains what the card asks for and is therefore actually reproducible is important. Change-Id: I91a60760fc3ad816b7385da8b26ec7330b462abd --- M pySim-smpp2sim.py M pySim/bip.py M tests/unittests/test_bip_relay.py 3 files changed, 76 insertions(+), 5 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/64/43564/1 diff --git a/pySim-smpp2sim.py b/pySim-smpp2sim.py index 95b9ccd..c1b2bb7 100755 --- a/pySim-smpp2sim.py +++ b/pySim-smpp2sim.py @@ -50,7 +50,7 @@ from pySim.sms import SMS_DELIVER, SMS_SUBMIT, AddressField -from pySim.bip import Proact +from pySim.bip import Proact, terminal_profile from pySim.transport import LinkBase, ProactiveHandler, argparse_add_reader_args, init_reader, ApduTracer from pySim.commands import SimCardCommands from pySim.cards import UiccCardBase @@ -126,8 +126,7 @@ self.scc.sel_ctrl = "0004" self.card.read_aids() self.card.select_adf_by_aid(adf='usim') - # FIXME: create a more realistic profile than ffffff - self.scc.terminal_profile('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') + self.scc.terminal_profile(b2h(terminal_profile())) # Connect the BIP relay inbound path to the card. # relay socket receives data -> ME initiated ENVELOPE EVENT DOWNLOA # -> triggers RECEIVE DATA proactive session. diff --git a/pySim/bip.py b/pySim/bip.py index 8370b5b..b25fe5f 100644 --- a/pySim/bip.py +++ b/pySim/bip.py @@ -46,6 +46,35 @@ logger = logging.getLogger(__name__) + +def terminal_profile(num_channels: int = 7) -> bytes: + """TERMINAL PROFILE for what we implement, TS 102 223 5.2 and annex T. + + Annex T table T.1 lists what a Connected Entity, a CAT client that is not the modem + which is pretty much what we are, may announce, and its inverse is what only a modem may announce. + """ + if not 0 <= num_channels <= ProactChannels.MAX_CHANNELS: + raise ValueError('num_channels must be 0..%u' % ProactChannels.MAX_CHANNELS) + profile = bytearray(32) + # 1 (Download): b1 profile download, b2+b5 SMS-PP data download. Both of the latter, per the + # note in TS 31.111 5.2: "several bits may need to be set to 1 for the support of the same + # facility ... because of backward compatibility with SAT". The relay is OTA over SMS-PP. + profile[0] = 0x01 | 0x02 | 0x10 + profile[1] = 0x01 # 2 (Other): b1 command result + profile[2] = 0x80 # 3: b8 REFRESH (empty result is a valid answer, 6.4.7) + profile[3] = 0x02 # 4: b2 SEND SHORT MESSAGE (the OTA response path) + profile[4] = 0x01 # 5: b1 SET UP EVENT LIST + profile[5] = 0x04 | 0x08 # 6: b3 Event Data available, b4 Event Channel status + # 12 (class "e"): b1..b5 OPEN CHANNEL, CLOSE CHANNEL, RECEIVE DATA, SEND DATA, GET CHANNEL + # STATUS. + profile[11] = 0x1f + # 13 (class "e" supported bearers): b2 GPRS, and b6..b8 the number of channels. + profile[12] = 0x02 | (num_channels << 5) + profile[13] = 0x40 | 0x20 # 14: b6 no display capability, b7 no keypad available + profile[16] = 0x01 # 15: b1 TCP, UICC in client mode, remote connection + return bytes(profile) + + class ProactChannel: """Representation of a single BIP channel, backed by a blocking TCP socket. @@ -168,6 +197,11 @@ class ProactChannels: """Wrapper class for maintaining state of proactive channels.""" + + # TS 102 223 8.56 channel identifier in 3 bits as "1 to 7", 0 == no channel available + # TERMINAL PROFILE has to agree with byte 13 , "number of channels supported by terminal" + MAX_CHANNELS = 7 + def __init__(self, on_data_available=None): self.channels = {} # called from a channel rx reader thread on empty->non-empty buf @@ -176,7 +210,7 @@ def channel_create(self) -> ProactChannel: """Create a new proactive channel, allocating its integer number.""" - for i in range(1, 8): + for i in range(1, self.MAX_CHANNELS + 1): if not i in self.channels: self.channels[i] = ProactChannel(self, i) return self.channels[i] diff --git a/tests/unittests/test_bip_relay.py b/tests/unittests/test_bip_relay.py index 8716585..e7229d7 100644 --- a/tests/unittests/test_bip_relay.py +++ b/tests/unittests/test_bip_relay.py @@ -27,7 +27,7 @@ OtherAddress, ChannelData, ChannelDataLength, ChannelStatus, Result) -from pySim.bip import Proact +from pySim.bip import Proact, ProactChannels, terminal_profile class _EchoServer: @@ -324,6 +324,44 @@ self.assertEqual(self.proact.channels.channels, {}) # channel given back +class TerminalProfileTest(unittest.TestCase): + """TS 102 223 5.2, one bit per CAT facility""" + + def setUp(self): + self.profile = terminal_profile() + + def byte(self, n): + return self.profile[n - 1] # 1-based, as 5.2 numbers them + + def test_announced(self): + self.assertEqual(len(self.profile), 32) + self.assertEqual(self.byte(1), 0x13) # profile download, SMS-PP download b2+b5 + self.assertEqual(self.byte(4), 0x02) # SEND SHORT MESSAGE + self.assertEqual(self.byte(5) & 0x01, 0x01) # SET UP EVENT LIST + self.assertEqual(self.byte(6), 0x0c) # events: data available, channel status + self.assertEqual(self.byte(12), 0x1f) # OPEN/CLOSE CHANNEL, RECEIVE/SEND DATA, STATUS + self.assertEqual(self.byte(13) >> 5, ProactChannels.MAX_CHANNELS) + self.assertEqual(self.byte(14), 0x60) # class ND, class NK + self.assertEqual(self.byte(17), 0x01) # TCP, UICC client mode, remote + + def test_not_announced(self): + self.assertEqual(self.byte(3) & 0x60, 0) # POLL INTERVAL, POLLING OFF + self.assertEqual(self.byte(4) & 0xc0, 0) # PROVIDE LOCAL INFORMATION, NMR + self.assertEqual(self.byte(12) & 0xe0, 0) # SERVICE SEARCH/INFORMATION, DECLARE SERVICE + self.assertEqual(self.byte(14) & 0x1f, 0) # no characters down the display + for n in (7, 9, 10, 11, 15, 16, 18): # class "a", class "d", display, ESN/IMEISV + self.assertEqual(self.byte(n), 0) + + def test_channel_count(self): + self.assertEqual(terminal_profile(3)[12] >> 5, 3) + with self.assertRaises(ValueError): # 8.56: 1 to 7 + terminal_profile(8) + + +if __name__ == "__main__": + unittest.main() + + class BipSinkTest(unittest.TestCase): """Both sinks are optional, a driver with no SMS path at all must not crash and burn with a card that sends one, and one that has one must get the PDU.""" -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43564?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: I91a60760fc3ad816b7385da8b26ec7330b462abd Gerrit-Change-Number: 43564 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[S] Change in pysim[master]: tests: stop test_log from leaking the print callback
by Hoernchen 08 Sep '26

08 Sep '26
Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/43539?usp=email ) Change subject: tests: stop test_log from leaking the print callback ...................................................................... tests: stop test_log from leaking the print callback PySimLogger.setup() installs a process-global print callback. PySimLogger_Test sets one, a helper that asserts the message equals a global expected_message, and never removes it, so from the moment test_log runs, every PySimLogger message emitted anywhere in the process is checked against whatever string that global happens to hold. Fortunately unittest discovery runs modules in sorted order, and today the PySimLogger users that log during tests all sort before test_log, so this only breaks as soon as I try to add tests, just like anything else breaks as soon as I try to use it. Change-Id: I481e2c443fe0f412380b0f1acf6da5971ffca147 --- M tests/unittests/test_log.py 1 file changed, 11 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/39/43539/1 diff --git a/tests/unittests/test_log.py b/tests/unittests/test_log.py index a8e38dd..ac651ae 100755 --- a/tests/unittests/test_log.py +++ b/tests/unittests/test_log.py @@ -37,6 +37,17 @@ class PySimLogger_Test(unittest.TestCase): + def setUp(self): + # PySimLogger.setup() is global, so a print callback left installed here fires for + # every PySimLogger message emitted by any test module that runs later in the same process + # ... where it asserts against a stale 'expected_message' and fails a test that has nothing + # to do with logging. Great fun! + # Restore before each test. + saved = (PySimLogger.print_callback, PySimLogger.verbose) + def _restore(): + PySimLogger.print_callback, PySimLogger.verbose = saved + self.addCleanup(_restore) + def __test_01_safe_defaults_one(self, callback, message:str): # When log messages are sent to an unconfigured PySimLogger class, we expect the unmodified message being # logged to stdout, just as if it were printed via a normal print() statement. -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43539?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: I481e2c443fe0f412380b0f1acf6da5971ffca147 Gerrit-Change-Number: 43539 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • ...
  • 190
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.