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 onomondo-eim[master]: crypto_utils: fix sourcecode formatting
by laforge 10 Sep '26

10 Sep '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/onomondo-eim/+/43613?usp=email ) Change subject: crypto_utils: fix sourcecode formatting ...................................................................... crypto_utils: fix sourcecode formatting Related: SYS#8100 Change-Id: Ie4d6b4d44a015e97606f6ca6e01398bcf385f542 --- M src/crypto_utils.erl 1 file changed, 3 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/src/crypto_utils.erl b/src/crypto_utils.erl index 4a43407..49f5a25 100644 --- a/src/crypto_utils.erl +++ b/src/crypto_utils.erl @@ -40,7 +40,7 @@ % Read the AssociationToken {ok, AssociationToken} = mnesia_db_euicc:state_get(EidValue, associationToken), - %Format message to be signed + % Format message to be signed {ok, EuiccPackageSignedEnc} = 'SGP32Definitions':encode( 'EuiccPackageSigned', EuiccPackageSigned ), @@ -48,13 +48,13 @@ EuiccPackageSignedEnc, enc_association_token(AssociationToken) ]), - %Load private key from eIM certificate + % Load private key from eIM certificate {ok, EimKeyPath} = utils:get_env_priv_file_path(onomondo_eim, eim_key), {ok, EimKeyPem} = file:read_file(EimKeyPath), [EimKeyPemEntry] = public_key:pem_decode(EimKeyPem), EimKeyECPrivateKey = public_key:pem_entry_decode(EimKeyPemEntry), - %Sign message + % Sign message % We use SHA-256 as signature hash/digest, see also GSMA SGP.22, section 2.6.5 and % https://www.erlang.org/doc/apps/public_key/public_key#sign/4 der_to_plain(public_key:sign(MsgToBeSigned, sha256, EimKeyECPrivateKey)). -- To view, visit https://gerrit.osmocom.org/c/onomondo-eim/+/43613?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: onomondo-eim Gerrit-Branch: master Gerrit-Change-Id: Ie4d6b4d44a015e97606f6ca6e01398bcf385f542 Gerrit-Change-Number: 43613 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
1 0
0 0
[XS] Change in onomondo-eim[master]: crypto_utils: fix sourcecode formatting
by laforge 10 Sep '26

10 Sep '26
Attention is currently required from: dexter. laforge has posted comments on this change by dexter. ( https://gerrit.osmocom.org/c/onomondo-eim/+/43613?usp=email ) Change subject: crypto_utils: fix sourcecode formatting ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/onomondo-eim/+/43613?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: onomondo-eim Gerrit-Branch: master Gerrit-Change-Id: Ie4d6b4d44a015e97606f6ca6e01398bcf385f542 Gerrit-Change-Number: 43613 Gerrit-PatchSet: 1 Gerrit-Owner: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Thu, 10 Sep 2026 13:12:45 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in pysim[master]: ota: add TS 102 226 5.2 Expanded Remote Application data format
by laforge 10 Sep '26

10 Sep '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/43541?usp=email ) Change subject: ota: add TS 102 226 5.2 Expanded Remote Application data format ...................................................................... ota: add TS 102 226 5.2 Expanded Remote Application data format TS 102 226 section 5.2 "Command and Response Scripting templates" The advantage over compact RFM/RAM commands is one C-APDU TLV per command and one R-APDU TLV per result, so multiple commands return the response of each one rather than only that of the last. encode_expanded_cmd() builds the Command Scripting template decode_expanded_resp() decodes the Response Scripting template into a Container. The 'truncated' key must be checked! OtaDialect.encode_cmd()/decode_resp() now has a remote_format param for compact and expanded formats, default stays compact,so existing code is unaffected. Change-Id: Idec00d16fd1a7d4a7129b2a3b6f0ef37dabcecb7 --- M pySim/ota.py M tests/unittests/test_ota.py 2 files changed, 410 insertions(+), 9 deletions(-) Approvals: dexter: Looks good to me, but someone else must approve Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim/ota.py b/pySim/ota.py index 3d2da15..adbf56b 100644 --- a/pySim/ota.py +++ b/pySim/ota.py @@ -18,10 +18,12 @@ import zlib import abc import struct -from typing import Optional, Tuple +from typing import Optional, Tuple, List, Union from construct import Enum, Int8ub, Int16ub, Struct, BitsInteger, BitStruct from construct import Flag, Padding, Switch, this, PrefixedArray, GreedyRange +from construct import Const, Prefixed, Select, Construct, SizeofError, stream_read, stream_write from osmocom.construct import * +from osmocom.tlv import bertlv_encode_len from osmocom.utils import b2h from pySim.sms import UserDataHeader @@ -56,6 +58,172 @@ 'last_status_word'/HexAdapter(Bytes(2)), 'last_response_data'/HexAdapter(GreedyBytes)) +###################################################################### +# Expanded Remote Application data format, ETSI TS 102 226 V19.0.0 (2025-11) Section 5.2 +# 5.2.1 Expanded Remote command structure +# 5.2.1.1 C-APDU TLV +# 5.2.1.2 Immediate Action TLV +# 5.2.1.3 Error Action TLV +# 5.2.1.4 Script Chaining TLV +# 5.2.2 Expanded Remote response structure (tables 5.10 .. 5.16) +# +# BER-TLV tag values from ETSI TS 101 220 V19.0.0 tables 7.18, 7.19, 7.20 +# C-APDU / R-APDU ETSI TS 102 223 Section 8.35 + 8.36 +# inside these the CR flag of the tag is 0 (TS 101 220 tables 7.19/7.20), +# so tag bytes are 22 and 23 and not A2/A3. +# +# This layer sits above the TS 102 225 security layer. +###################################################################### + +class BerTlvLength(Construct): + """A definite-length BER-TLV length field used by the "expanded remote + application data format" from ISO/IEC 8825-1 referenced by TS 102 226 5.2 + + - short form (0..127 -> single octet) + - long form (128.. -> 0x8N followed by N length octets) + Indefinite length coding (first octet 0x80, TS 102 226 tables 5.2a/5.10a) + is omitted here because it is only recommended for HTTPS/CoAP transport, not SMS.""" + def _parse(self, stream, context, path): + first = stream_read(stream, 1, path)[0] + if first < 0x80: + return first + num_octets = first & 0x7f + if num_octets == 0: + raise NotImplementedError('indefinite coding is not supported') + return int.from_bytes(stream_read(stream, num_octets, path), 'big') + + def _build(self, obj, stream, context, path): + encoded = bertlv_encode_len(obj) + stream_write(stream, encoded, len(encoded), path) + return obj + + def _sizeof(self, context, path): + raise SizeofError('BER-TLV length has a variable size?!') + +BerTlvLen = BerTlvLength() + +class _RApduValueAdapter(Adapter): + """Split/join value of R-APDU COMPREHENSION-TLV TS 102 223 8.36 + [R-APDU data (x-2 bytes)] SW1 SW2.""" + def _decode(self, obj, context, path): + raw = bytes(obj) + return Container(response_data=b2h(raw[:-2]), status_word=b2h(raw[-2:])) + + def _encode(self, obj, context, path): + return h2b(obj['response_data']) + h2b(obj['status_word']) + +#### Command Scripting template TS 102 226 table 5.2, TS 101 220 tables 7.18/7.19 + +# TS 102 223 8.35 +ExpandedC_APDU = Struct('_tag'/Const(b'\x22'), + 'c_apdu'/Prefixed(BerTlvLen, HexAdapter(GreedyBytes))) + +ExpandedCmd = Struct('_tag'/Const(b'\xaa'), + 'commands'/Prefixed(BerTlvLen, GreedyRange(ExpandedC_APDU))) + +#### Response Scripting template TS 102 226 tables 5.10-5.16, TS 101 220 table 7.20 + +# TS 102 223 8.36 +ExpandedR_APDU = Struct('_tag'/Const(b'\x23'), + 'r_apdu'/Prefixed(BerTlvLen, _RApduValueAdapter(GreedyBytes))) + +# TS 102 226 table 5.11 +# Value is an integer per ISO/IEC 8825-1, likely just one octet. +ExpandedNumExecuted = Struct('_tag'/Const(b'\x80'), + 'number_of_commands'/Prefixed(BerTlvLen, GreedyInteger())) + +# TS 102 226 table 5.12 +ExpandedBadFormat = Struct('_tag'/Const(b'\x90'), + 'bad_format'/Prefixed(BerTlvLen, + Enum(Int8ub, unknown_tag=1, wrong_length=2, length_not_found=3))) + +# TS 102 226 table 5.14 +ExpandedImmediateActionResp = Struct('_tag'/Const(b'\x81'), + 'immediate_action_response'/Prefixed(BerTlvLen, + Enum(Int8ub, suspension_error=1))) + +# TS 102 226 table 5.16 +ExpandedScriptChainingResp = Struct('_tag'/Const(b'\x83'), + 'script_chaining_response'/Prefixed(BerTlvLen, + Enum(Int8ub, no_previous_script=1, + not_supported=2, unable_to_process=3))) + +# - starts with the "Number of executed command TLV objects" (table 5.10/5.13/5.15) +# - followed by a sequence of R-APDU TLVs +# - and/or one of the error # response TLVs +ExpandedRemoteResp = Struct('_tag'/Const(b'\xab'), + 'body'/Prefixed(BerTlvLen, Struct( + 'num_executed'/ExpandedNumExecuted, + 'responses'/GreedyRange(Select(ExpandedR_APDU, + ExpandedBadFormat, + ExpandedImmediateActionResp, + ExpandedScriptChainingResp))))) + + +def encode_expanded_cmd(apdus: Union[bytes, List[bytes]]) -> bytes: + """builds the Command Scripting template, TS 102 226 5.2.1, definite length coding + + Args: + apdus: single C-APDU bytes or list of C-APDUs bytes. Each + C-APDU is wrapped into a C-APDU TLV- This function does not add + or modify Le. + Returns: + encoded Command Scripting template (AA...) as bytes + """ + if isinstance(apdus, (bytes, bytearray)): + apdus = [apdus] + return ExpandedCmd.build({'commands': [{'c_apdu': b2h(a)} for a in apdus]}) + + +def decode_expanded_resp(data: bytes) -> Container: + """Decode a Response Scripting template, TS 102 226 5.2.2 definite length + coding + + returned Container has: + number_of_commands -- "number of executed command TLV objects" table 5.11 + commands -- list of Containers, one per R-APDU TLV, each + with 'response_data' and 'status_word' hexstr + last_response_data -- response_data of the last R-APDU or '' + last_status_word -- status_word of the last R-APDU or None + truncated -- True if any R-APDU has SW 62F1. + 5.2.1.1 states card sets that status when it had to truncate + C-APDU response data, and "this shall terminate the + processing of the command list". + so the response is short AND the remaining commands never ran. + bad_format -- error type of a trailing Bad format TLV if present + immediate_action_response -- Immediate Action Response TLV, if there was a suspension error + script_chaining_response -- Script Chaining Response TLV, if there was a chaining error + + The 'last_response_data'/'last_status_word'/'number_of_commands' keys are compatible with + CompactRemoteResp so existing callers keep working.""" + if isinstance(data, str): + data = h2b(data) + parsed = ExpandedRemoteResp.parse(data) + commands = [] + bad_format = None + immediate_action_response = None + script_chaining_response = None + for item in parsed['body']['responses']: + if 'r_apdu' in item: + commands.append(Container(response_data=item['r_apdu']['response_data'], + status_word=item['r_apdu']['status_word'])) + elif 'bad_format' in item: + bad_format = item['bad_format'] + elif 'immediate_action_response' in item: + immediate_action_response = item['immediate_action_response'] + elif 'script_chaining_response' in item: + script_chaining_response = item['script_chaining_response'] + # TS 102 226 5.2.1.1: 62F1 means response of a C-APDU was truncated, processing terminated + truncated = any(c['status_word'].lower() == '62f1' for c in commands) + return Container(number_of_commands=parsed['body']['num_executed']['number_of_commands'], + commands=commands, + last_response_data=commands[-1]['response_data'] if commands else '', + last_status_word=commands[-1]['status_word'] if commands else None, + truncated=truncated, + bad_format=bad_format, + immediate_action_response=immediate_action_response, + script_chaining_response=script_chaining_response) + RC_CC_DS = Enum(BitsInteger(2), no_rc_cc_ds=0, rc=1, cc=2, ds=3) CNTR_REQ = Enum(BitsInteger(2), no_counter=0, counter_no_replay_or_seq=1, counter_must_be_higher=2, counter_must_be_lower=3) POR_REQ = Enum(BitsInteger(2), no_por=0, por_required=1, por_only_when_error=2) @@ -149,13 +317,23 @@ raise ValueError("Invalid rc_cc_ds: %s" % spi['rc_cc_ds']) @abc.abstractmethod - def encode_cmd(self, otak: OtaKeyset, tar: bytes, spi: dict, apdu: bytes) -> bytes: + def encode_cmd(self, otak: OtaKeyset, tar: bytes, spi: dict, + apdu: Union[bytes, List[bytes]], remote_format: str = 'compact') -> bytes: + """Encode a command for a format. + + remote_format: + 'compact' TS 102 226 5.1, DEFAULT assumes apdus are opaque already-concatenated command strings + 'expanded' TS 102 226 5.2 wraps a single C-APDU or list of C-APDUs in a Command Scripting template.""" pass @abc.abstractmethod - def decode_resp(self, otak: OtaKeyset, spi: dict, apdu: bytes) -> (object, Optional["CompactRemoteResp"]): - """Decode a response into a response packet and, if indicted (by a - response status of `"por_ok"`) a decoded response. + def decode_resp(self, otak: OtaKeyset, spi: dict, apdu: bytes, + remote_format: str = 'compact') -> (object, Optional[object]): + """Decode response into response packet + a decoded response if por_ok. + + remote_format: + 'compact' -> DEFAULT TS 102 226 5.1.2 CompactRemoteResp2 + 'expanded' -> container returned by decode_expanded_resp(), TS 102 226 5.2.2 The response packet's common characteristics are not fully determined, and (so far) completely proprietary per dialect.""" @@ -335,7 +513,16 @@ 'secured_data'/GreedyBytes) hdr_construct = Struct('chl'/Int8ub, 'spi'/SPI, 'kic'/KIC, 'kid'/KID_CC, 'tar'/Bytes(3)) - def encode_cmd(self, otak: OtaKeyset, tar: bytes, spi: dict, apdu: bytes) -> bytes: + def encode_cmd(self, otak: OtaKeyset, tar: bytes, spi: dict, + apdu: Union[bytes, List[bytes]], remote_format: str = 'compact') -> bytes: + # as above: + # expanded format is a Command Scripting template wrapping the C-APDU(s) + # compact format passes already concatenated command string + if remote_format == 'expanded': + apdu = encode_expanded_cmd(apdu) + elif remote_format != 'compact': + raise ValueError("Invalid remote_format: %s" % remote_format) + # length of signature in octets len_sig = self._compute_sig_len(spi) pad_cnt = 0 @@ -446,7 +633,10 @@ return hdr_dec['tar'], spi, apdu - def decode_resp(self, otak: OtaKeyset, spi: dict, data: bytes) -> ("OtaDialectSms.SmsResponsePacket", Optional["CompactRemoteResp"]): + def decode_resp(self, otak: OtaKeyset, spi: dict, data: bytes, + remote_format: str = 'compact') -> ("OtaDialectSms.SmsResponsePacket", Optional[object]): + if remote_format not in ('compact', 'expanded'): + raise ValueError("Invalid remote_format: %s ?!" % remote_format) if isinstance(data, str): data = h2b(data) # plain-text POR: 027100000e0ab000110000000000000001612f @@ -492,9 +682,11 @@ else: raise OtaCheckError('Unknown por_rc_cc_ds: %s' % spi['por_rc_cc_ds']) - # TODO: ExpandedRemoteResponse according to TS 102 226 5.2.2 if res.response_status == 'por_ok' and len(res['secured_data']): - dec = CompactRemoteResp.parse(res['secured_data']) + if remote_format == 'expanded': + dec = decode_expanded_resp(res['secured_data']) + else: + dec = CompactRemoteResp.parse(res['secured_data']) else: dec = None return (res, dec) diff --git a/tests/unittests/test_ota.py b/tests/unittests/test_ota.py index 888f828..e7c7230 100644 --- a/tests/unittests/test_ota.py +++ b/tests/unittests/test_ota.py @@ -300,5 +300,214 @@ self.assertEqual(d.last_status_word, t['response']['last_status_word']) self.assertEqual(d.last_response_data, t['response']['last_response_data']) + +###################################################################### +# Expanded Remote Application data format (ETSI TS 102 226 Section 5.2) +###################################################################### + +class BerTlvLengthTestCase(unittest.TestCase): + """The definite-length BER-TLV length field (ISO/IEC 8825-1) used by the + expanded format, incl. the multi-byte (>127) forms (0x81xx / 0x82xxxx).""" + def test_roundtrip(self): + # (length value, expected encoded bytes) + vectors = [ + (0, '00'), + (1, '01'), + (127, '7f'), + (128, '8180'), + (198, '81c6'), # big ~198 byte GET STATUS registry from a sja5 + (255, '81ff'), + (256, '820100'), + (65535, '82ffff'), + ] + for length, encoded in vectors: + with self.subTest(length=length): + built = BerTlvLen.build(length) + self.assertEqual(b2h(built), encoded) + self.assertEqual(BerTlvLen.parse(built), length) + + +class ExpandedCmdTestCase(unittest.TestCase): + """Command Scripting template TS 102 226 5.2.1""" + + def test_single_capdu_golden(self): + # GP GET STATUS, Le=00, TS 102 226 5.2.1.1 R-APDU + out = encode_expanded_cmd(h2b('80f24002024f0000')) + # aa = TS 101 220 table 7.18 Command Scripting template tag + # 0a = length 10 + # 22 = TS 101 220 table 7.19 C-APDU tag + # 08 = length + # + C-APDU + self.assertEqual(b2h(out), 'aa0a220880f24002024f0000') + + def test_multi_capdu_golden(self): + out = encode_expanded_cmd([h2b('80f24002024f0000'), h2b('00a40004023f0000')]) + self.assertEqual(b2h(out), 'aa14220880f24002024f0000220800a40004023f0000') + + def test_multibyte_length_golden(self): + # C-APDU: 4 header + 1 Lc + 195 data = 200 bytes. + # 200 byte C-APDU forces long form BER lengths: + # C-APDU TLV, 200 -> 81c8 + template 203 -> 81cb + capdu = h2b('80f24000') + bytes([195]) + bytes(range(195)) + self.assertEqual(len(capdu), 200) + out = encode_expanded_cmd(capdu) + # aa 81 cb | 22 81 c8 | <200 byte capdu> + self.assertEqual(b2h(out[:6]), 'aa81cb2281c8') + self.assertEqual(out[6:], capdu) + + def test_roundtrip(self): + for apdus in [[h2b('80f24002024f0000')], + [h2b('00a40004023f00'), h2b('80f24002024f0000')], + [h2b('00'*250)]]: + with self.subTest(n=len(apdus)): + out = encode_expanded_cmd(apdus) + parsed = ExpandedCmd.parse(out) + self.assertEqual([h2b(c.c_apdu) for c in parsed.commands], apdus) + + +class ExpandedRespTestCase(unittest.TestCase): + """Decoding of the Response Scripting template (TS 102 226 5.2.2).""" + + def test_registry_golden(self): + # real card case: GET STATUS returns a ~198 byte registry TLV + SW 9000 + # R-APDU = 198 data + 2 SW = 200/81c8 + # 'number of executed' TLV 80 01 01. + registry = bytes(range(198)) + data = ExpandedRemoteResp.build(dict(body=dict( + num_executed=dict(number_of_commands=1), + responses=[dict(r_apdu=dict(response_data=b2h(registry), status_word='9000'))]))) + # ab | 81 ce | 80 01 01 | 23 81 c8 | <198 data> 90 00 + self.assertEqual(b2h(data[:9]), 'ab81ce8001012381c8') + dec = decode_expanded_resp(data) + self.assertEqual(dec.number_of_commands, 1) + self.assertEqual(len(dec.commands), 1) + self.assertEqual(dec.last_status_word, '9000') + self.assertEqual(dec.last_response_data, b2h(registry)) + + def test_status_only_golden(self): + # last command, no response data, SW 6132 + data = ExpandedRemoteResp.build(dict(body=dict( + num_executed=dict(number_of_commands=1), + responses=[dict(r_apdu=dict(response_data='', status_word='6132'))]))) + self.assertEqual(b2h(data), 'ab0780010123026132') + dec = decode_expanded_resp(data) + self.assertEqual(dec.last_status_word, '6132') + self.assertEqual(dec.last_response_data, '') + + def test_multi_command(self): + data = ExpandedRemoteResp.build(dict(body=dict( + num_executed=dict(number_of_commands=2), + responses=[dict(r_apdu=dict(response_data='6f21', status_word='9000')), + dict(r_apdu=dict(response_data='', status_word='6a82'))]))) + dec = decode_expanded_resp(data) + self.assertEqual(dec.number_of_commands, 2) + self.assertEqual([(c.status_word, c.response_data) for c in dec.commands], + [('9000', '6f21'), ('6a82', '')]) + # last == final R-APDU, error status included + self.assertEqual(dec.last_status_word, '6a82') + self.assertEqual(dec.last_response_data, '') + + def test_bad_format(self): + # ab | 06 | 80 01 01 | 90 01 01 + data = h2b('ab06800101900101') + dec = decode_expanded_resp(data) + self.assertEqual(str(dec.bad_format), 'unknown_tag') + self.assertIsNone(dec.last_status_word) + + def test_immediate_action_error(self): + # ab | 06 | 80 01 01 | 81 01 01 + data = h2b('ab06800101810101') + dec = decode_expanded_resp(data) + self.assertEqual(str(dec.immediate_action_response), 'suspension_error') + + def test_script_chaining_error(self): + # ab | 06 | 80 01 01 | 83 01 02 + data = h2b('ab06800101830102') + dec = decode_expanded_resp(data) + self.assertEqual(str(dec.script_chaining_response), 'not_supported') + + def test_truncation_is_flagged(self): + """TS 102 226 5.2.1.1: SW 62F1 means the C-APDU response data was truncated, and + "this shall terminate the processing of the command list" + halves are invisible in the R-APDU list, truncated + aborted script must not pass as complete""" + # second command truncated -> processing stopped at that point + data = ExpandedRemoteResp.build(dict(body=dict( + num_executed=dict(number_of_commands=2), + responses=[dict(r_apdu=dict(response_data='6f21', status_word='9000')), + dict(r_apdu=dict(response_data='aabb', status_word='62f1'))]))) + dec = decode_expanded_resp(data) + self.assertTrue(dec.truncated) + self.assertEqual(dec.last_status_word, '62f1') + + def test_untruncated_response_is_not_flagged(self): + data = ExpandedRemoteResp.build(dict(body=dict( + num_executed=dict(number_of_commands=1), + responses=[dict(r_apdu=dict(response_data='6f21', status_word='9000'))]))) + self.assertFalse(decode_expanded_resp(data).truncated) + # 62xx that is not 62F1 is warning, not truncation + data = ExpandedRemoteResp.build(dict(body=dict( + num_executed=dict(number_of_commands=1), + responses=[dict(r_apdu=dict(response_data='', status_word='6282'))]))) + self.assertFalse(decode_expanded_resp(data).truncated) + + +class ExpandedSmsPipelineTestCase(unittest.TestCase): + """expanded format + TS 102 225 SMS security witj 3DES keyset, + to ensure remote_format does not affect the compact path""" + def __init__(self, methodName='runTest', **kwargs): + super().__init__(methodName, **kwargs) + self.od = OtaKeyset(algo_crypt='triple_des_cbc2', kic_idx=3, + kic=h2b('C21DD66ACAC13CB3BC8B331B24AFB57B'), + algo_auth='triple_des_cbc2', kid_idx=3, + kid=h2b('12110C78E678C25408233076AA033615')) + self.dialect = OtaDialectSms() + self.tar = h2b('000000') + + def test_cmd_expanded_secured_roundtrip(self): + spi = SPI_CC_POR_CIPHERED_CC + enc = self.dialect.encode_cmd(self.od, self.tar, spi, h2b('80f24002024f0000'), + remote_format='expanded') + # decode_cmd returns opaque 'Command Scripting template' + dec_tar, dec_spi, dec_secured = self.dialect.decode_cmd(self.od, enc) + self.assertEqual(b2h(dec_tar), b2h(self.tar)) + self.assertEqual(dec_spi, spi) + self.assertEqual(b2h(dec_secured), 'aa0a220880f24002024f0000') + + def test_cmd_expanded_list(self): + spi = SPI_CC_POR_CIPHERED_CC + enc = self.dialect.encode_cmd(self.od, self.tar, spi, + [h2b('80f24002024f0000'), h2b('00a40004023f0000')], + remote_format='expanded') + _, _, dec_secured = self.dialect.decode_cmd(self.od, enc) + parsed = ExpandedCmd.parse(dec_secured) + self.assertEqual([c.c_apdu for c in parsed.commands], + ['80f24002024f0000', '00a40004023f0000']) + + def test_resp_expanded_plaintext(self): + # plaintext (u:nciphered + no CC) expanded response SMS + # containing a 198 byte GP registry + SW 9000 as above, decode it through decode_resp(). + spi = SPI_CC_POR_UNCIPHERED_NOCC + registry = bytes(range(198)) + secured = ExpandedRemoteResp.build(dict(body=dict( + num_executed=dict(number_of_commands=1), + responses=[dict(r_apdu=dict(response_data=b2h(registry), status_word='9000'))]))) + rpl = 1 + 3 + 5 + 1 + 1 + len(secured) # RHL-STS + secured data + resp_body = rpl.to_bytes(2, 'big') + b'\x0a' + self.tar + b'\x00'*5 + b'\x00' + b'\x00' + secured + sms = b'\x02\x71\x00' + resp_body + r, dec = self.dialect.decode_resp(self.od, spi, sms, remote_format='expanded') + self.assertEqual(r.response_status, 'por_ok') + self.assertEqual(dec.number_of_commands, 1) + self.assertEqual(dec.last_status_word, '9000') + self.assertEqual(dec.last_response_data, b2h(registry)) + + def test_compact_still_default(self): + # no remote_format -> compact default + spi = SPI_CC_POR_UNCIPHERED_NOCC + r, d = self.dialect.decode_resp(self.od, spi, '027100000e0ab000110000000000000001612f') + self.assertEqual(d.number_of_commands, 1) + self.assertEqual(d.last_status_word, '612f') + self.assertEqual(d.last_response_data, '') + + if __name__ == "__main__": unittest.main() -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43541?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: Idec00d16fd1a7d4a7129b2a3b6f0ef37dabcecb7 Gerrit-Change-Number: 43541 Gerrit-PatchSet: 2 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
1 0
0 0
[L] Change in pysim[master]: bip: move the BIP relay into pySim.bip
by laforge 10 Sep '26

10 Sep '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/43540?usp=email ) Change subject: bip: move the BIP relay into pySim.bip ...................................................................... bip: move the BIP relay into pySim.bip Move the code from pySim-smpp2sim.py to its own file, so it can be properly extended. The current file parses argv, opens a reader and starts the Twisted reactor at import time, so nothing else can import it. No functional changes yet, improvements follow in later commits. Change-Id: Ifd8a15684939977d29ea83a6b669daee14484e88 --- M pySim-smpp2sim.py A pySim/bip.py A tests/unittests/test_bip_relay.py 3 files changed, 311 insertions(+), 220 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-smpp2sim.py b/pySim-smpp2sim.py index fa670e5..9420130 100755 --- a/pySim-smpp2sim.py +++ b/pySim-smpp2sim.py @@ -33,7 +33,7 @@ import colorlog from twisted.protocols import basic -from twisted.internet import defer, endpoints, protocol, reactor, task +from twisted.internet import defer, endpoints, reactor, task from twisted.cred.portal import IRealm from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse from twisted.cred.portal import Portal @@ -47,6 +47,7 @@ from pySim.sms import SMS_DELIVER, SMS_SUBMIT, AddressField +from pySim.bip import Proact from pySim.transport import LinkBase, ProactiveHandler, argparse_add_reader_args, init_reader, ApduTracer from pySim.commands import SimCardCommands from pySim.cards import UiccCardBase @@ -71,224 +72,6 @@ print("-> %s %s" % (cmd[:10], cmd[10:])) print("<- %s: %s" % (sw, resp)) -class TcpProtocol(protocol.Protocol): - def dataReceived(self, data): - pass - - def connectionLost(self, reason): - pass - - -def tcp_connected_callback(p: protocol.Protocol): - """called by twisted TCP client.""" - logger.error("%s: connected!" % p) - -class ProactChannel: - """Representation of a single protective channel.""" - def __init__(self, channels: 'ProactChannels', chan_nr: int): - self.channels = channels - self.chan_nr = chan_nr - self.ep = None - - def close(self): - """Close the channel.""" - if self.ep: - self.ep.disconnect() - self.channels.channel_delete(self.chan_nr) - -class ProactChannels: - """Wrapper class for maintaining state of proactive channels.""" - def __init__(self): - self.channels = {} - - def channel_create(self) -> ProactChannel: - """Create a new proactive channel, allocating its integer number.""" - for i in range(1, 9): - if not i in self.channels: - self.channels[i] = ProactChannel(self, i) - return self.channels[i] - raise ValueError('Cannot allocate another channel: All channels active') - - def channel_delete(self, chan_nr: int): - del self.channels[chan_nr] - -class Proact(ProactiveHandler): - #def __init__(self, smpp_factory): - # self.smpp_factory = smpp_factory - def __init__(self): - self.channels = ProactChannels() - - @staticmethod - def _find_first_element_of_type(instlist, cls): - for i in instlist: - if isinstance(i, cls): - return i - return None - - """Call-back which the pySim transport core calls whenever it receives a - proactive command from the SIM.""" - def handle_SendShortMessage(self, pcmd: ProactiveCommand): - # {'smspp_download': [{'device_identities': {'source_dev_id': 'network', - # 'dest_dev_id': 'uicc'}}, - # {'address': {'ton_npi': {'ext': True, - # 'type_of_number': 'international', - # 'numbering_plan_id': 'isdn_e164'}, - # 'call_number': '79'}}, - # {'sms_tpdu': {'tpdu': '40048111227ff6407070611535004d02700000481516011212000001fe4c0943aea42e45021c078ae06c66afc09303608874b72f58bacadb0dcf665c29349c799fbb522e61709c9baf1890015e8e8e196e36153106c8b92f95153774'}} - # ]} - """Card requests sending a SMS. We need to pass it on to the ESME via SMPP.""" - logger.info("SendShortMessage") - logger.info(pcmd) - # Relevant parts in pcmd: Address, SMS_TPDU - addr_ie = Proact._find_first_element_of_type(pcmd.children, Address) - sms_tpdu_ie = Proact._find_first_element_of_type(pcmd.children, SMS_TPDU) - raw_tpdu = sms_tpdu_ie.decoded['tpdu'] - submit = SMS_SUBMIT.from_bytes(raw_tpdu) - submit.tp_da = AddressField(addr_ie.decoded['call_number'], addr_ie.decoded['ton_npi']['type_of_number'], - addr_ie.decoded['ton_npi']['numbering_plan_id']) - logger.info(submit) - self.send_sms_via_smpp(submit) - - def handle_OpenChannel(self, pcmd: ProactiveCommand): - """Card requests opening a new channel via a UDP/TCP socket.""" - # {'open_channel': [{'command_details': {'command_number': 1, - # 'type_of_command': 'open_channel', - # 'command_qualifier': 3}}, - # {'device_identities': {'source_dev_id': 'uicc', - # 'dest_dev_id': 'terminal'}}, - # {'bearer_description': {'bearer_type': 'default', - # 'bearer_parameters': ''}}, - # {'buffer_size': 1024}, - # {'uicc_transport_level': {'protocol_type': 'tcp_uicc_client_remote', - # 'port_number': 32768}}, - # {'other_address': {'type_of_address': 'ipv4', - # 'address': '01020304'}} - # ]} - logger.info("OpenChannel") - logger.info(pcmd) - transp_lvl_ie = Proact._find_first_element_of_type(pcmd.children, UiccTransportLevel) - 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') - ipv4_bytes = h2b(other_addr_ie.decoded['address']) - ipv4_str = '%u.%u.%u.%u' % (ipv4_bytes[0], ipv4_bytes[1], ipv4_bytes[2], ipv4_bytes[3]) - port_nr = transp_lvl_ie.decoded['port_number'] - print("%s:%u" % (ipv4_str, port_nr)) - channel = self.channels.channel_create() - channel.ep = endpoints.TCP4ClientEndpoint(reactor, ipv4_str, port_nr) - channel.prot = TcpProtocol() - d = endpoints.connectProtocol(channel.ep, channel.prot) - # FIXME: why is this never called despite the client showing the inbound connection? - d.addCallback(tcp_connected_callback) - - # Terminal Response example: [ - # {'command_details': {'command_number': 1, - # 'type_of_command': 'open_channel', - # 'command_qualifier': 3}}, - # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, - # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, - # {'channel_status': '8100'}, - # {'bearer_description': {'bearer_type': 'default', 'bearer_parameters': ''}}, - # {'buffer_size': 1024} - # ] - return self.prepare_response(pcmd) + [ChannelStatus(decoded='8100'), bearer_desc_ie, buffer_size_ie] - - def handle_CloseChannel(self, pcmd: ProactiveCommand): - """Close a channel.""" - logger.info("CloseChannel") - logger.info(pcmd) - - def handle_ReceiveData(self, pcmd: ProactiveCommand): - """Receive/read data from the socket.""" - # {'receive_data': [{'command_details': {'command_number': 1, - # 'type_of_command': 'receive_data', - # 'command_qualifier': 0}}, - # {'device_identities': {'source_dev_id': 'uicc', - # 'dest_dev_id': 'channel_1'}}, - # {'channel_data_length': 9} - # ]} - logger.info("ReceiveData") - logger.info(pcmd) - # Terminal Response example: [ - # {'command_details': {'command_number': 1, - # 'type_of_command': 'receive_data', - # 'command_qualifier': 0}}, - # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, - # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, - # {'channel_data': '16030100040e000000'}, - # {'channel_data_length': 0} - # ] - return self.prepare_response(pcmd) + [] - - def handle_SendData(self, pcmd: ProactiveCommand): - """Send/write data received from the SIM to the socket.""" - # {'send_data': [{'command_details': {'command_number': 1, - # 'type_of_command': 'send_data', - # 'command_qualifier': 1}}, - # {'device_identities': {'source_dev_id': 'uicc', - # 'dest_dev_id': 'channel_1'}}, - # {'channel_data': '160301003c010000380303d0f45e12b52ce5bb522750dd037738195334c87a46a847fe2b6886cada9ea6bf00000a00ae008c008b00b0002c010000050001000101'} - # ]} - logger.info("SendData") - logger.info(pcmd) - dev_id_ie = Proact._find_first_element_of_type(pcmd.children, DeviceIdentities) - chan_data_ie = Proact._find_first_element_of_type(pcmd.children, ChannelData) - chan_str = dev_id_ie.decoded['dest_dev_id'] - chan_nr = 1 # FIXME - chan = self.channels.channels.get(chan_nr, None) - # FIXME chan.prot.transport.write(h2b(chan_data_ie.decoded)) - # Terminal Response example: [ - # {'command_details': {'command_number': 1, - # 'type_of_command': 'send_data', - # 'command_qualifier': 1}}, - # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, - # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, - # {'channel_data_length': 255} - # ] - return self.prepare_response(pcmd) + [ChannelDataLength(decoded=255)] - - def handle_SetUpEventList(self, pcmd: ProactiveCommand): - # {'set_up_event_list': [{'command_details': {'command_number': 1, - # 'type_of_command': 'set_up_event_list', - # 'command_qualifier': 0}}, - # {'device_identities': {'source_dev_id': 'uicc', - # 'dest_dev_id': 'terminal'}}, - # {'event_list': ['data_available', 'channel_status']} - # ]} - logger.info("SetUpEventList") - logger.info(pcmd) - # Terminal Response example: [ - # {'command_details': {'command_number': 1, - # 'type_of_command': 'set_up_event_list', - # 'command_qualifier': 0}}, - # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, - # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}} - # ] - return self.prepare_response(pcmd) - - def getChannelStatus(self, pcmd: ProactiveCommand): - logger.info("GetChannelStatus") - logger.info(pcmd) - return self.prepare_response(pcmd) + [] - - def send_sms_via_smpp(self, submit: SMS_SUBMIT): - # while in a normal network the phone/ME would *submit* a message to the SMSC, - # we are actually emulating the SMSC itself, so we must *deliver* the message - # to the ESME - deliver = SMS_DELIVER.from_submit(submit) - deliver_smpp = deliver.to_smpp() - - hackish_global_smpp.sendDataRequest(deliver_smpp) -# # obtain the connection/binding of system_id to be used for delivering MO-SMS to the ESME -# connection = smpp_server.getBoundConnections[system_id].getNextBindingForDelivery() -# connection.sendDataRequest(deliver_smpp) - - - def dcs_is_8bit(dcs): if dcs == pdu_types.DataCoding(pdu_types.DataCodingScheme.DEFAULT, pdu_types.DataCodingDefault.OCTET_UNSPECIFIED): @@ -416,7 +199,8 @@ opts = option_parser.parse_args() - tp = init_reader(opts, proactive_handler = Proact()) + tp = init_reader(opts, proactive_handler = Proact( + sms_sink=lambda pdu: hackish_global_smpp.sendDataRequest(pdu))) if tp is None: exit(1) tp.connect() diff --git a/pySim/bip.py b/pySim/bip.py new file mode 100644 index 0000000..ececf6d --- /dev/null +++ b/pySim/bip.py @@ -0,0 +1,262 @@ +# -*- coding: utf-8 -*- +"""Bearer Independent Protocol relay""" + +# +# (C) 2023-2024 by Harald Welte <laforge(a)osmocom.org> +# +# 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/>. + +import logging +import socket +import threading +import time + +from twisted.internet import endpoints, protocol, reactor + +from osmocom.utils import b2h, h2b + +from pySim.transport import ProactiveHandler +from pySim.sms import SMS_DELIVER, SMS_SUBMIT, AddressField +from pySim.cat import (ProactiveCommand, SendShortMessage, SMS_TPDU, SMSPPDownload, + BearerDescription, DeviceIdentities, Address, OtherAddress, + UiccTransportLevel, BufferSize, ChannelStatus, ChannelData, + ChannelDataLength, EventList, EventDownload, Result) + +logger = logging.getLogger(__name__) + +class TcpProtocol(protocol.Protocol): + def dataReceived(self, data): + pass + + def connectionLost(self, reason): + pass + + +def tcp_connected_callback(p: protocol.Protocol): + """called by twisted TCP client.""" + logger.error("%s: connected!" % p) + +class ProactChannel: + """Representation of a single protective channel.""" + def __init__(self, channels: 'ProactChannels', chan_nr: int): + self.channels = channels + self.chan_nr = chan_nr + self.ep = None + + def close(self): + """Close the channel.""" + if self.ep: + self.ep.disconnect() + self.channels.channel_delete(self.chan_nr) + +class ProactChannels: + """Wrapper class for maintaining state of proactive channels.""" + def __init__(self): + self.channels = {} + + def channel_create(self) -> ProactChannel: + """Create a new proactive channel, allocating its integer number.""" + for i in range(1, 9): + if not i in self.channels: + self.channels[i] = ProactChannel(self, i) + return self.channels[i] + raise ValueError('Cannot allocate another channel: All channels active') + + def channel_delete(self, chan_nr: int): + del self.channels[chan_nr] + +class Proact(ProactiveHandler): + #def __init__(self, smpp_factory): + # self.smpp_factory = smpp_factory + def __init__(self, sms_sink=None): + # sms_sink(pdu) delivers an MO-SMS the card sent (SEND SHORT MESSAGE) + # onwards; pySim-smpp2sim.py hands it to its SMPP server. None -> log + # and drop. + self.sms_sink = sms_sink + self.channels = ProactChannels() + + @staticmethod + def _find_first_element_of_type(instlist, cls): + for i in instlist: + if isinstance(i, cls): + return i + return None + + """Call-back which the pySim transport core calls whenever it receives a + proactive command from the SIM.""" + def handle_SendShortMessage(self, pcmd: ProactiveCommand): + # {'smspp_download': [{'device_identities': {'source_dev_id': 'network', + # 'dest_dev_id': 'uicc'}}, + # {'address': {'ton_npi': {'ext': True, + # 'type_of_number': 'international', + # 'numbering_plan_id': 'isdn_e164'}, + # 'call_number': '79'}}, + # {'sms_tpdu': {'tpdu': '40048111227ff6407070611535004d02700000481516011212000001fe4c0943aea42e45021c078ae06c66afc09303608874b72f58bacadb0dcf665c29349c799fbb522e61709c9baf1890015e8e8e196e36153106c8b92f95153774'}} + # ]} + """Card requests sending a SMS. We need to pass it on to the ESME via SMPP.""" + logger.info("SendShortMessage") + logger.info(pcmd) + # Relevant parts in pcmd: Address, SMS_TPDU + addr_ie = Proact._find_first_element_of_type(pcmd.children, Address) + sms_tpdu_ie = Proact._find_first_element_of_type(pcmd.children, SMS_TPDU) + raw_tpdu = sms_tpdu_ie.decoded['tpdu'] + submit = SMS_SUBMIT.from_bytes(raw_tpdu) + submit.tp_da = AddressField(addr_ie.decoded['call_number'], addr_ie.decoded['ton_npi']['type_of_number'], + addr_ie.decoded['ton_npi']['numbering_plan_id']) + logger.info(submit) + self.send_sms_via_smpp(submit) + + def handle_OpenChannel(self, pcmd: ProactiveCommand): + """Card requests opening a new channel via a UDP/TCP socket.""" + # {'open_channel': [{'command_details': {'command_number': 1, + # 'type_of_command': 'open_channel', + # 'command_qualifier': 3}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'terminal'}}, + # {'bearer_description': {'bearer_type': 'default', + # 'bearer_parameters': ''}}, + # {'buffer_size': 1024}, + # {'uicc_transport_level': {'protocol_type': 'tcp_uicc_client_remote', + # 'port_number': 32768}}, + # {'other_address': {'type_of_address': 'ipv4', + # 'address': '01020304'}} + # ]} + logger.info("OpenChannel") + logger.info(pcmd) + transp_lvl_ie = Proact._find_first_element_of_type(pcmd.children, UiccTransportLevel) + 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') + ipv4_bytes = h2b(other_addr_ie.decoded['address']) + ipv4_str = '%u.%u.%u.%u' % (ipv4_bytes[0], ipv4_bytes[1], ipv4_bytes[2], ipv4_bytes[3]) + port_nr = transp_lvl_ie.decoded['port_number'] + print("%s:%u" % (ipv4_str, port_nr)) + channel = self.channels.channel_create() + channel.ep = endpoints.TCP4ClientEndpoint(reactor, ipv4_str, port_nr) + channel.prot = TcpProtocol() + d = endpoints.connectProtocol(channel.ep, channel.prot) + # FIXME: why is this never called despite the client showing the inbound connection? + d.addCallback(tcp_connected_callback) + + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'open_channel', + # 'command_qualifier': 3}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, + # {'channel_status': '8100'}, + # {'bearer_description': {'bearer_type': 'default', 'bearer_parameters': ''}}, + # {'buffer_size': 1024} + # ] + return self.prepare_response(pcmd) + [ChannelStatus(decoded='8100'), bearer_desc_ie, buffer_size_ie] + + def handle_CloseChannel(self, pcmd: ProactiveCommand): + """Close a channel.""" + logger.info("CloseChannel") + logger.info(pcmd) + + def handle_ReceiveData(self, pcmd: ProactiveCommand): + """Receive/read data from the socket.""" + # {'receive_data': [{'command_details': {'command_number': 1, + # 'type_of_command': 'receive_data', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'channel_1'}}, + # {'channel_data_length': 9} + # ]} + logger.info("ReceiveData") + logger.info(pcmd) + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'receive_data', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, + # {'channel_data': '16030100040e000000'}, + # {'channel_data_length': 0} + # ] + return self.prepare_response(pcmd) + [] + + def handle_SendData(self, pcmd: ProactiveCommand): + """Send/write data received from the SIM to the socket.""" + # {'send_data': [{'command_details': {'command_number': 1, + # 'type_of_command': 'send_data', + # 'command_qualifier': 1}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'channel_1'}}, + # {'channel_data': '160301003c010000380303d0f45e12b52ce5bb522750dd037738195334c87a46a847fe2b6886cada9ea6bf00000a00ae008c008b00b0002c010000050001000101'} + # ]} + logger.info("SendData") + logger.info(pcmd) + dev_id_ie = Proact._find_first_element_of_type(pcmd.children, DeviceIdentities) + chan_data_ie = Proact._find_first_element_of_type(pcmd.children, ChannelData) + chan_str = dev_id_ie.decoded['dest_dev_id'] + chan_nr = 1 # FIXME + chan = self.channels.channels.get(chan_nr, None) + # FIXME chan.prot.transport.write(h2b(chan_data_ie.decoded)) + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'send_data', + # 'command_qualifier': 1}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, + # {'channel_data_length': 255} + # ] + return self.prepare_response(pcmd) + [ChannelDataLength(decoded=255)] + + def handle_SetUpEventList(self, pcmd: ProactiveCommand): + # {'set_up_event_list': [{'command_details': {'command_number': 1, + # 'type_of_command': 'set_up_event_list', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'terminal'}}, + # {'event_list': ['data_available', 'channel_status']} + # ]} + logger.info("SetUpEventList") + logger.info(pcmd) + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'set_up_event_list', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}} + # ] + return self.prepare_response(pcmd) + + def getChannelStatus(self, pcmd: ProactiveCommand): + logger.info("GetChannelStatus") + logger.info(pcmd) + return self.prepare_response(pcmd) + [] + + def send_sms_via_smpp(self, submit: SMS_SUBMIT): + # while in a normal network the phone/ME would *submit* a message to the SMSC, + # we are actually emulating the SMSC itself, so we must *deliver* the message + # to the ESME + deliver = SMS_DELIVER.from_submit(submit) + deliver_smpp = deliver.to_smpp() + + if self.sms_sink is None: + logger.info('no sms_sink: dropping MO-SMS %s', deliver_smpp) + return + self.sms_sink(deliver_smpp) +# # obtain the connection/binding of system_id to be used for delivering MO-SMS to the ESME +# connection = smpp_server.getBoundConnections[system_id].getNextBindingForDelivery() +# connection.sendDataRequest(deliver_smpp) + + + diff --git a/tests/unittests/test_bip_relay.py b/tests/unittests/test_bip_relay.py new file mode 100644 index 0000000..e2e7ff8 --- /dev/null +++ b/tests/unittests/test_bip_relay.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +# (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/>. + +import unittest + +from pySim.bip import Proact +from pySim.sms import SMS_SUBMIT, AddressField + + +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.""" + + def _submit(self): + return SMS_SUBMIT(tp_da=AddressField('12345', 'unknown', 'unknown'), + tp_ud=b'\x01\x02', tp_udl=2, tp_dcs=0xf6) + + def test_sinks_default_to_none(self): + p = Proact() + self.assertIsNone(p.sms_sink) + + def test_mo_sms_goes_to_the_sink(self): + seen = [] + Proact(sms_sink=seen.append).send_sms_via_smpp(self._submit()) + self.assertEqual(len(seen), 1) + + def test_no_sms_sink_drops_instead_of_raising(self): + with self.assertLogs('pySim.bip', level='INFO'): + Proact().send_sms_via_smpp(self._submit()) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43540?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: Ifd8a15684939977d29ea83a6b669daee14484e88 Gerrit-Change-Number: 43540 Gerrit-PatchSet: 2 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
1 0
0 0
[M] Change in pysim[master]: smpp-ota-tool: add --format compact,expanded for TS 102 226 5.2
by laforge 10 Sep '26

10 Sep '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/43542?usp=email ) Change subject: smpp-ota-tool: add --format compact,expanded for TS 102 226 5.2 ...................................................................... smpp-ota-tool: add --format compact,expanded for TS 102 226 5.2 Add --format expanded flag to send C-APDUs in the expanded remote application data format. Each --apdu becomes its own C-APDU TLV, and the tool logs the full per-command R-APDU list decoded from the Response Scripting template and warns if the card reports a truncated response. Default stays 'compact', unchanged. Change-Id: Idad90756f85bb7e54ef720f6067bb5d6dcff0c42 --- M contrib/smpp-ota-tool.py M docs/smpp-ota-tool.rst 2 files changed, 64 insertions(+), 7 deletions(-) Approvals: dexter: Looks good to me, approved Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve diff --git a/contrib/smpp-ota-tool.py b/contrib/smpp-ota-tool.py index 28c13bf..3698001 100755 --- a/contrib/smpp-ota-tool.py +++ b/contrib/smpp-ota-tool.py @@ -70,6 +70,8 @@ option_parser.add_argument('--src-addr', default='12', type=str, help='SMS source address (MSISDN)') option_parser.add_argument('--dest-addr', default='23', type=str, help='SMS destination address (MSISDN)') option_parser.add_argument('--timeout', default=10, type=int, help='Maximum response waiting time') +option_parser.add_argument('--format', choices=['compact', 'expanded'], default='compact', + help="Remote Application data format: 'compact' or 'expanded'") option_parser.add_argument('-a', '--apdu', action='append', required=True, type=is_hexstr, help='C-APDU to send') class SmppHandler: @@ -77,7 +79,8 @@ def __init__(self, host: str, port: int, system_id: str, password: str, - ota_keyset: OtaKeyset, spi: dict, tar: bytes): + ota_keyset: OtaKeyset, spi: dict, tar: bytes, + remote_format: str = 'compact'): """ Initialize connection to SMPP server and set static OTA SMS-TPDU ciphering parameters Args: @@ -88,6 +91,7 @@ ota_keyset: OTA keyset to be used for SMS-TPDU ciphering spi: Security Parameter Indicator (SPI) to be used for SMS-TPDU ciphering tar: Toolkit Application Reference (TAR) of the targeted card application + remote_format: Remote Application data format ('compact' or 'expanded', TS 102 226) """ # Create and connect SMPP client @@ -103,6 +107,7 @@ self.ota_keyset = ota_keyset self.tar = tar self.spi = spi + self.remote_format = remote_format def __del__(self): if self.client: @@ -113,14 +118,16 @@ if pdu.short_message: logger.info("SMS-TPDU received: %s", b2h(pdu.short_message)) try: - dec = self.ota_dialect.decode_resp(self.ota_keyset, self.spi, pdu.short_message) + dec = self.ota_dialect.decode_resp(self.ota_keyset, self.spi, pdu.short_message, + remote_format=self.remote_format) except ValueError: # Retry to decoding with ciphering disabled (in case the card has problems to decode the SMS-TDPU # we have sent, the response will contain an unencrypted error message) spi = self.spi.copy() spi['por_shall_be_ciphered'] = False spi['por_rc_cc_ds'] = 'no_rc_cc_ds' - dec = self.ota_dialect.decode_resp(self.ota_keyset, spi, pdu.short_message) + dec = self.ota_dialect.decode_resp(self.ota_keyset, spi, pdu.short_message, + remote_format=self.remote_format) logger.info("SMS-TPDU decoded: %s", dec) self.response = dec return None @@ -183,10 +190,14 @@ tuple containing the last response data and the last status word as byte strings """ - logger.info("C-APDU sending: %s...", b2h(apdu)) + if isinstance(apdu, (list, tuple)): + logger.info("C-APDU(s) sending: %s...", [b2h(a) for a in apdu]) + else: + logger.info("C-APDU sending: %s...", b2h(apdu)) # translate to Secured OTA RFM - secured = self.ota_dialect.encode_cmd(self.ota_keyset, self.tar, self.spi, apdu=apdu) + secured = self.ota_dialect.encode_cmd(self.ota_keyset, self.tar, self.spi, apdu=apdu, + remote_format=self.remote_format) # add user data header tpdu = b'\x02\x70\x00' + secured # send via SMPP @@ -200,6 +211,17 @@ container_dict = dict(container) resp = container_dict.get('last_response_data') sw = container_dict.get('last_status_word') + # expanded format: decoded response carries + # per command R-APDU list; log each one. + for i, cmd in enumerate(container_dict.get('commands') or []): + logger.info("R-APDU[%u] received: %s %s", i, + cmd['response_data'], cmd['status_word']) + if container_dict.get('truncated'): + logger.warning("Response was TRUNCATED (SW 62F1): the card cut the response " + "data short and did not execute the rest of the script") + if container_dict.get('bad_format') is not None: + logger.warning("Response contains a Bad format TLV: %s", + container_dict['bad_format']) if resp is None: raise ValueError("Response does not contain any last_response_data, no R-APDU received!") if sw is None: @@ -233,8 +255,14 @@ 'por_shall_be_ciphered': not opts.por_no_ciphering, 'por_rc_cc_ds': opts.por_rc_cc_ds, 'por': opts.por_req} - apdu = h2b("".join(opts.apdu)) + if opts.format == 'expanded': + # TS 102 226 5.2.1.1: wrap each apdu in its own C-APDU TLV + apdu = [h2b(a) for a in opts.apdu] + else: + # compact: C-APDUs are concatenated as single command string + apdu = h2b("".join(opts.apdu)) - smpp_handler = SmppHandler(opts.host, opts.port, opts.system_id, opts.password, ota_keyset, spi, h2b(opts.tar)) + smpp_handler = SmppHandler(opts.host, opts.port, opts.system_id, opts.password, ota_keyset, spi, + h2b(opts.tar), remote_format=opts.format) resp, sw = smpp_handler.transceive_apdu(apdu, opts.src_addr, opts.dest_addr, opts.timeout) print("%s %s" % (b2h(resp), b2h(sw))) diff --git a/docs/smpp-ota-tool.rst b/docs/smpp-ota-tool.rst index beb494a..9dc0df6 100644 --- a/docs/smpp-ota-tool.rst +++ b/docs/smpp-ota-tool.rst @@ -170,6 +170,35 @@ .. note:: The replay-protection-counter is implemented as a 5 byte integer value (see also ETSI TS 102 225, Table 3). When the counter has reached its maximum, it will not overflow nor can it be reset. +Expanded remote application data format +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`smpp-ota-tool` uses the TS 102 226 section 5.1 compact remote application data format by default. This +format concatenates C-APDUs into one command string and only the result of the LAST executed command is reported back. +Retrieving the response data therefore requires a GET RESPONSE C-APDU, and only a single GET RESPONSE command may occur per script. + +The TS 102 226 section 5.2 expanded remote application data format removes these limitations: Each C-APDU is +wrapped in its own C-APDU TLV inside a Command Scripting template, and the response is a Response Scripting template that contains one R-APDU TLV with the full response data and status word per executed command. To use it, pass +``--format expanded``; every ``--apdu`` argument then becomes its own C-APDU TLV. + +.. note:: The expanded format does not use GET RESPONSE. To retrieve response data from a case 2 or case 4 + command, include an ``Le`` field in the C-APDU. i.e. ``Le='00'`` instructs the card to return all available + response data in the R-APDU, with no 256-byte limit (TS 102 226, section 5.2.1.1). Without the ``Le`` + field no response data is returned, except a status word for the last command!. + +For example, a GP GET STATUS of all applications (``80F24002024F00``) returns a registry that can be much +larger than 256 bytes. In the compact format the card would only answer with ``61xx`` procedure bytes. In the expanded +format, appending ``Le='00'`` (i.e. ``80F24002024F0000``) makes the card return the whole registry in one exchange: + +:: + + $ PYTHONPATH=./ ./contrib/smpp-ota-tool.py --kic <KIC> --kid <KID> --kid-idx 1 --kic-idx 1 \ + --algo-crypt triple_des_cbc2 --algo-auth triple_des_cbc2 --tar 000000 --cntr-req no_counter \ + --format expanded --apdu 80F24002024F0000 + +The response data (a concatenation of GlobalPlatform registry TLVs) can then be decoded with +``pySim.global_platform.GpRegistryRelatedData.from_tlv()``. + smpp-ota-tool syntax ~~~~~~~~~~~~~~~~~~~~ -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43542?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: Idad90756f85bb7e54ef720f6067bb5d6dcff0c42 Gerrit-Change-Number: 43542 Gerrit-PatchSet: 2 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
1 0
0 0
[L] Change in pysim[master]: ota: add TS 102 226 5.2 Expanded Remote Application data format
by laforge 10 Sep '26

10 Sep '26
Attention is currently required from: Hoernchen, dexter. laforge has posted comments on this change by Hoernchen. ( https://gerrit.osmocom.org/c/pysim/+/43541?usp=email ) Change subject: ota: add TS 102 226 5.2 Expanded Remote Application data format ...................................................................... Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43541?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: Idec00d16fd1a7d4a7129b2a3b6f0ef37dabcecb7 Gerrit-Change-Number: 43541 Gerrit-PatchSet: 2 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: Hoernchen <ewild(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Thu, 10 Sep 2026 13:10:39 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in pysim[master]: bip: move the BIP relay into pySim.bip
by laforge 10 Sep '26

10 Sep '26
Attention is currently required from: Hoernchen, dexter. laforge has posted comments on this change by Hoernchen. ( https://gerrit.osmocom.org/c/pysim/+/43540?usp=email ) Change subject: bip: move the BIP relay into pySim.bip ...................................................................... Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/43540?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: Ifd8a15684939977d29ea83a6b669daee14484e88 Gerrit-Change-Number: 43540 Gerrit-PatchSet: 2 Gerrit-Owner: Hoernchen <ewild(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: Hoernchen <ewild(a)sysmocom.de> Gerrit-Attention: dexter <pmaier(a)sysmocom.de> Gerrit-Comment-Date: Thu, 10 Sep 2026 13:10:04 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[XS] Change in osmo-ttcn3-hacks[master]: ipa: build with -DMEM_EMIT_DEBUG=ON
by osmith 10 Sep '26

10 Sep '26
osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43615?usp=email ) Change subject: ipa: build with -DMEM_EMIT_DEBUG=ON ...................................................................... ipa: build with -DMEM_EMIT_DEBUG=ON As requested by Andreas, always build onomondo-ipa with this option when building it with testenv. Depends: osmo-dev I2572ae781dd4d57e614813c90f5ed8bc76caf033 Change-Id: I6e9dfb6baf9cd0d760f0ea3d18983b56ed64f9be --- M _testenv/data/osmo-dev/testenv.opts 1 file changed, 1 insertion(+), 0 deletions(-) Approvals: pespin: Looks good to me, but someone else must approve fixeria: Looks good to me, but someone else must approve osmith: Looks good to me, approved jolly: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/_testenv/data/osmo-dev/testenv.opts b/_testenv/data/osmo-dev/testenv.opts index 15ab331..4ee524b 100644 --- a/_testenv/data/osmo-dev/testenv.opts +++ b/_testenv/data/osmo-dev/testenv.opts @@ -1,2 +1,3 @@ osmo-bts --enable-trx osmo-remsim --disable-remsim-client-ifdhandler +onomondo-ipa -DMEM_EMIT_DEBUG=ON -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43615?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I6e9dfb6baf9cd0d760f0ea3d18983b56ed64f9be Gerrit-Change-Number: 43615 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in osmo-ttcn3-hacks[master]: ipa: build with -DMEM_EMIT_DEBUG=ON
by osmith 10 Sep '26

10 Sep '26
osmith has posted comments on this change by osmith. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43615?usp=email ) Change subject: ipa: build with -DMEM_EMIT_DEBUG=ON ...................................................................... Patch Set 1: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43615?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I6e9dfb6baf9cd0d760f0ea3d18983b56ed64f9be Gerrit-Change-Number: 43615 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Thu, 10 Sep 2026 12:53:54 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in osmo-dev[master]: gen_makefile: allow passing opts to cmake, meson
by osmith 10 Sep '26

10 Sep '26
osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-dev/+/43614?usp=email ) Change subject: gen_makefile: allow passing opts to cmake, meson ...................................................................... gen_makefile: allow passing opts to cmake, meson We need to always build the cmake program onomondo-ipa with a specific option when building it through testenv with osmo-dev. Extend gen_makefile so we can pass options not only to autotools based projects, but also to cmake and while at it meson too. For example usage, see the related patch. Related: osmo-ttcn3-hacks I6e9dfb6baf9cd0d760f0ea3d18983b56ed64f9be Change-Id: I2572ae781dd4d57e614813c90f5ed8bc76caf033 --- M gen_makefile.py 1 file changed, 11 insertions(+), 3 deletions(-) Approvals: fixeria: Looks good to me, but someone else must approve jolly: Looks good to me, but someone else must approve Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve osmith: Looks good to me, approved diff --git a/gen_makefile.py b/gen_makefile.py index 203c7f5..4cfc313 100755 --- a/gen_makefile.py +++ b/gen_makefile.py @@ -378,7 +378,8 @@ -rm -rf {build_proj} mkdir -p {build_proj} cd {build_proj}; {cflags}meson setup {build_to_src} . \\ - --prefix {shlex.quote(args.install_prefix)} + --prefix {shlex.quote(args.install_prefix)} \\ + {configure_opts} touch $@ ''' elif buildsystem == "cmake": @@ -389,7 +390,8 @@ -rm -rf {build_proj} mkdir -p {build_proj} cd {build_proj}; cmake -S {build_to_src} -B . \\ - -DCMAKE_INSTALL_PREFIX={shlex.quote(args.install_prefix)} + -DCMAKE_INSTALL_PREFIX={shlex.quote(args.install_prefix)} \\ + {configure_opts} touch $@ ''' elif buildsystem in ["erlang", "python"]: @@ -753,9 +755,15 @@ content += 'all-install: \\\n\t' + ' \\\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps.items() ]) + '\n\n' for proj, deps in projects_deps.items(): + # Build a project-specific list of configure options all_config_opts = [] - all_config_opts.extend(configure_opts.get('ALL') or []) + if projects_buildsystems.get(proj, "autotools") == "autotools": + # Options for ALL are only applied to projects with the autotools build + # system. When applying unknown options to ./configure, they simply get + # ignored whereas other build systems will fail. + all_config_opts.extend(configure_opts.get('ALL') or []) all_config_opts.extend(configure_opts.get(proj) or []) + content += gen_make(proj, deps, all_config_opts, make_dir, src_dir, build_dir) # Replace spaces with tabs to avoid the common pitfall of inserting spaces -- To view, visit https://gerrit.osmocom.org/c/osmo-dev/+/43614?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-dev Gerrit-Branch: master Gerrit-Change-Id: I2572ae781dd4d57e614813c90f5ed8bc76caf033 Gerrit-Change-Number: 43614 Gerrit-PatchSet: 2 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • ...
  • 190
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.