laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/28214 )
Change subject: BSC_Tests: add TC_chan_alloc_algo_{a,de}scending
......................................................................
BSC_Tests: add TC_chan_alloc_algo_{a,de}scending
The aim of these new test cases is to verify both ascending and
descending modes of the BSC's channel allocator. Both tests are
using BTS2, which has 4 TRX instances.
The common test scenario can be described as follows:
1. Establish an SDCCH channel, send some dummy payload on it.
2. Send a BSSMAP Assignment Request for a TCH/F channel.
3. Expect RSL CHANnel ACTIVation for a TCH/F channel.
4. Respond with RSL CHANnel ACTIVation NACK (*).
5. Expect a BSSMAP Assignment Failure.
These steps are repeated several times. Note (*) that for the
sake of simplicity, I am aborting the assignment procedure by
sending a NACK, so that the requested logical channel becomes
BORKEN and behaves like an occupied one until the A-bis/OML
link is re-established. This reduces the overall complexity.
Change-Id: Ic74a9cd264320a9a17648f9331b67fb2c2404122
Related: SYS#5460
---
M bsc/BSC_Tests.ttcn
1 file changed, 66 insertions(+), 0 deletions(-)
Approvals:
laforge: Looks good to me, approved
pespin: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/bsc/BSC_Tests.ttcn b/bsc/BSC_Tests.ttcn
index ed56fc2..7070c9f 100644
--- a/bsc/BSC_Tests.ttcn
+++ b/bsc/BSC_Tests.ttcn
@@ -11576,6 +11576,68 @@
f_shutdown_helper();
}
+private function f_TC_chan_alloc_algo(DchanTuple dt, BtsTrxIdx idx)
+runs on test_CT {
+ /* MSC sends an Assignment Request */
+ var PDU_BSSAP ass_cmd := f_gen_ass_req();
+ ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
+ ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
+ BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
+
+ /* Expect the BSC to allocate a TCH channel on the given BTS/TRX */
+ var RSL_Message rsl_chan_act := f_exp_ipa_rx(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), idx);
+ /* Send CHAN ACT NACK, so that the requested TCH channel becomes BORKEN */
+ f_ipa_tx(ts_RSL_CHAN_ACT_NACK(rsl_chan_act.ies[0].body.chan_nr, RSL_ERR_EQUIPMENT_FAIL), idx);
+ /* Expect to receive an Assignment Failure */
+ BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail));
+}
+
+testcase TC_chan_alloc_algo_ascending() runs on test_CT {
+ /* We need to access BTS2, which has 4 TRXs */
+ f_init(nr_bts := 3);
+
+ /* HACK: work around "Couldn't find Expect for CRCX" */
+ vc_MGCP.stop;
+
+ f_vty_enter_cfg_bts(BSCVTY, 2);
+ f_vty_transceive(BSCVTY, "channel allocator ascending");
+ f_vty_transceive(BSCVTY, "end");
+
+ /* Expect the BSC to allocate 4 x TCH/F channels on BTS2/TRX0 */
+ for (var integer i := 0; i < 4; i := i + 1) {
+ var DchanTuple dt := f_est_dchan('23'O, 23, '00000000'O, {2, 0});
+ f_TC_chan_alloc_algo(dt, {2, 0});
+ f_perform_clear_test_ct(dt);
+ }
+
+ /* At this point all 4 x TCH/F channels are BORKEN, but they will be
+ * resurrected upon the A-bis/OML link re-establishment. */
+ f_shutdown_helper();
+}
+
+testcase TC_chan_alloc_algo_descending() runs on test_CT {
+ /* We need to access BTS2, which has 4 TRXs */
+ f_init(nr_bts := 3);
+
+ /* HACK: work around "Couldn't find Expect for CRCX" */
+ vc_MGCP.stop;
+
+ f_vty_enter_cfg_bts(BSCVTY, 2);
+ f_vty_transceive(BSCVTY, "channel allocator descending");
+ f_vty_transceive(BSCVTY, "end");
+
+ /* Expect the BSC to allocate 5 x TCH/F channels on BTS2/TRX3 */
+ for (var integer i := 0; i < 5; i := i + 1) {
+ var DchanTuple dt := f_est_dchan('23'O, 23, '00000000'O, {2, 0});
+ f_TC_chan_alloc_algo(dt, {2, 3});
+ f_perform_clear_test_ct(dt);
+ }
+
+ /* At this point all 5 x TCH/F channels are BORKEN, but they will be
+ * resurrected upon the A-bis/OML link re-establishment. */
+ f_shutdown_helper();
+}
+
control {
/* CTRL interface testing */
execute( TC_ctrl_msc_connection_status() );
@@ -11902,6 +11964,10 @@
execute( TC_lost_sdcch_during_assignment() );
+ /* Channel allocator */
+ execute( TC_chan_alloc_algo_ascending() );
+ execute( TC_chan_alloc_algo_descending() );
+
/* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
* with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
execute( TC_ho_out_of_this_bsc() );
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/28214
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ic74a9cd264320a9a17648f9331b67fb2c2404122
Gerrit-Change-Number: 28214
Gerrit-PatchSet: 6
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/28827 )
Change subject: reduce code dup in handle_cn_data_ind()
......................................................................
reduce code dup in handle_cn_data_ind()
Change-Id: I4bca25d1643693cf3a9d3c49f35b29ff1dce0859
---
M src/osmo-hnbgw/hnbgw_cn.c
1 file changed, 11 insertions(+), 21 deletions(-)
Approvals:
laforge: Looks good to me, approved
neels: Looks good to me, approved
dexter: Looks good to me, but someone else must approve
pespin: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/src/osmo-hnbgw/hnbgw_cn.c b/src/osmo-hnbgw/hnbgw_cn.c
index 75b1c94..0f1ed07 100644
--- a/src/osmo-hnbgw/hnbgw_cn.c
+++ b/src/osmo-hnbgw/hnbgw_cn.c
@@ -370,12 +370,11 @@
}
/* Intercept RAB Assignment Request, to map RTP and GTP between access and core */
- if (!map->is_ps) {
- /* Circuit-Switched. Set up mapping of RTP ports via MGW */
- message = talloc_zero(map, ranap_message);
- rc = ranap_ran_rx_co_decode(map, message, msgb_l2(oph->msg), msgb_l2len(oph->msg));
-
- if (rc == 0) {
+ message = talloc_zero(map, ranap_message);
+ rc = ranap_ran_rx_co_decode(map, message, msgb_l2(oph->msg), msgb_l2len(oph->msg));
+ if (rc == 0) {
+ if (!map->is_ps) {
+ /* Circuit-Switched. Set up mapping of RTP ports via MGW */
switch (message->procedureCode) {
case RANAP_ProcedureCode_id_RAB_Assignment:
/* mgw_fsm_alloc_and_handle_rab_ass_req() takes ownership of (ranap) message */
@@ -386,16 +385,8 @@
mgw_fsm_release(map);
break;
}
- ranap_ran_rx_co_free(message);
- }
-
- talloc_free(message);
- } else {
- /* Packet-Switched. Set up mapping of GTP ports via UPF */
- message = talloc_zero(map, ranap_message);
- rc = ranap_ran_rx_co_decode(map, message, msgb_l2(oph->msg), msgb_l2len(oph->msg));
-
- if (rc == 0) {
+ } else {
+ /* Packet-Switched. Set up mapping of GTP ports via UPF */
switch (message->procedureCode) {
case RANAP_ProcedureCode_id_RAB_Assignment:
@@ -412,16 +403,15 @@
break;
case RANAP_ProcedureCode_id_Iu_Release:
- /* Any IU Release will terminate the MGW FSM, the message itsself is not passed to the
- * FSM code. It is just forwarded normally by the rua_tx_dt() call below. */
+ /* An IU Release will terminate the PFCP sessions for all RABs (ps_rab FSM instances).
+ * Terminate all RABs and forward the IU Release directly by rua_tx_dt() below. */
hnbgw_gtpmap_release(map);
break;
}
- ranap_ran_rx_co_free(message);
}
-
- talloc_free(message);
+ ranap_ran_rx_co_free(message);
}
+ talloc_free(message);
return rua_tx_dt(map->hnb_ctx, map->is_ps, map->rua_ctx_id,
msgb_l2(oph->msg), msgb_l2len(oph->msg));
--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/28827
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: I4bca25d1643693cf3a9d3c49f35b29ff1dce0859
Gerrit-Change-Number: 28827
Gerrit-PatchSet: 3
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/28963 )
Change subject: pySim.transport: Add mechanism for handling for CAT/USAT proactive cmds
......................................................................
pySim.transport: Add mechanism for handling for CAT/USAT proactive cmds
This introduces an optional argument to the LinkBase class constructor,
where the application can pass an instance of a ProactiveHandler derived
class in order to handle the proactive commands that the LinkBase is
automatically fetching whenever the card indicates so.
Change-Id: I844504e2fc1b27ce4fc7ede20b2307e698baa0f6
---
M pySim/transport/__init__.py
1 file changed, 31 insertions(+), 5 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 9364b07..04e6b22 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -9,11 +9,12 @@
from pySim.exceptions import *
from pySim.construct import filter_dict
-from pySim.utils import sw_match, b2h, h2b, i2h
+from pySim.utils import sw_match, b2h, h2b, i2h, Hexstr
+from pySim.cat import ProactiveCommand
#
# Copyright (C) 2009-2010 Sylvain Munaut <tnt(a)246tNt.com>
-# Copyright (C) 2021 Harald Welte <laforge(a)osmocom.org>
+# Copyright (C) 2021-2022 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
@@ -37,13 +38,36 @@
def trace_response(self, cmd, sw, resp):
pass
+class ProactiveHandler(abc.ABC):
+ """Abstract base class representing the interface of some code that handles
+ the proactive commands, as returned by the card in responses to the FETCH
+ command."""
+ def receive_fetch_raw(self, payload: Hexstr):
+ # parse the proactive command
+ pcmd = ProactiveCommand()
+ parsed = pcmd.from_tlv(h2b(payload))
+ # try to find a generic handler like handle_SendShortMessage
+ handle_name = 'handle_%s' % type(parsed).__name__
+ if hasattr(self, handle_name):
+ handler = getattr(self, handle_name)
+ return handler(pcmd.decoded)
+ # fall back to common handler
+ return self.receive_fetch(pcmd)
+
+ def receive_fetch(self, pcmd: ProactiveCommand):
+ """Default handler for not otherwise handled proactive commands."""
+ raise NotImplementedError('No handler method for %s' % pcmd.decoded)
+
+
class LinkBase(abc.ABC):
"""Base class for link/transport to card."""
- def __init__(self, sw_interpreter=None, apdu_tracer=None):
+ def __init__(self, sw_interpreter=None, apdu_tracer=None,
+ proactive_handler: Optional[ProactiveHandler]=None):
self.sw_interpreter = sw_interpreter
self.apdu_tracer = apdu_tracer
+ self.proactive_handler = proactive_handler
@abc.abstractmethod
def _send_apdu_raw(self, pdu: str) -> Tuple[str, str]:
@@ -137,10 +161,12 @@
"""
rv = self.send_apdu(pdu)
- if sw == '9000' and sw_match(rv[1], '91xx'):
+ while sw == '9000' and sw_match(rv[1], '91xx'):
# proactive sim as per TS 102 221 Setion 7.4.2
rv = self.send_apdu_checksw('80120000' + rv[1][2:], sw)
- print("FETCH: %s", rv[0])
+ print("FETCH: %s" % rv[0])
+ if self.proactive_handler:
+ self.proactive_handler.receive_fetch_raw(rv[0])
if not sw_match(rv[1], sw):
raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter)
return rv
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28963
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I844504e2fc1b27ce4fc7ede20b2307e698baa0f6
Gerrit-Change-Number: 28963
Gerrit-PatchSet: 4
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/28965 )
Change subject: pySim-shell: Use pySim.cat definitions to print decoded proactive cmds
......................................................................
pySim-shell: Use pySim.cat definitions to print decoded proactive cmds
Register a ProactiveHandler with pySim.transport and call the decoder
from pySim.cat to print a decoded version:
Example usage (exact data only works on my specific card due to the
encrpyted payload):
pySIM-shell (MF/ADF.USIM)> envelope_sms 400881214365877ff6227052000000000302700000201506393535b000118dd46f4ad6b015922f62292350d60af4af191adcbbc35cf4
FETCH: d0378103011300820281838b2c410008812143658700f621027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c
SendShortMessage(CommandDetails({'command_number': 1, 'type_of_command': 19, 'command_qualifier': 0}),DeviceIdentities({'source_dev_id': 'uicc', 'dest_dev_id': 'network'}),SMS_TPDU({'tpdu': '410008812143658700f621027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c'}))
SW: 9000, data: d0378103011300820281838b2c410008812143658700f621027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c
Change-Id: Ia4cdf06a44f46184d0da318bdf67077bc8ac9a1a
---
M pySim-shell.py
1 file changed, 14 insertions(+), 4 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
diff --git a/pySim-shell.py b/pySim-shell.py
index ce6efb8..ef6a2b1 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -2,7 +2,7 @@
# Interactive shell for working with SIM / UICC / USIM / ISIM cards
#
-# (C) 2021 by Harald Welte <laforge(a)osmocom.org>
+# (C) 2021-2022 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
@@ -32,12 +32,14 @@
from pathlib import Path
from io import StringIO
+from pprint import pprint as pp
+
from pySim.exceptions import *
from pySim.commands import SimCardCommands
-from pySim.transport import init_reader, ApduTracer, argparse_add_reader_args
+from pySim.transport import init_reader, ApduTracer, argparse_add_reader_args, ProactiveHandler
from pySim.cards import card_detect, SimCard
from pySim.utils import h2b, swap_nibbles, rpad, b2h, JsonEncoder, bertlv_parse_one, sw_match
-from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str
+from pySim.utils import sanitize_pin_adm, tabulate_str_list, boxed_heading_str, Hexstr
from pySim.card_handler import CardHandler, CardHandlerAuto
from pySim.filesystem import RuntimeState, CardDF, CardADF, CardModel
@@ -49,6 +51,7 @@
from pySim.ara_m import CardApplicationARAM
from pySim.global_platform import CardApplicationISD
from pySim.gsm_r import DF_EIRENE
+from pySim.cat import ProactiveCommand
# we need to import this module so that the SysmocomSJA2 sub-class of
# CardModel is created, which will add the ATR-based matching and
@@ -902,6 +905,13 @@
self._cmd.poutput(
'Negotiated Duration: %u secs, Token: %s, SW: %s' % (duration, token, sw))
+class Proact(ProactiveHandler):
+ def receive_fetch(self, pcmd: ProactiveCommand):
+ # print its parsed representation
+ print(pcmd.decoded)
+ # TODO: implement the basics, such as SMS Sending, ...
+
+
option_parser = argparse.ArgumentParser(prog='pySim-shell', description='interactive SIM card shell',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
@@ -942,7 +952,7 @@
card_key_provider_register(CardKeyProviderCsv(csv_default))
# Init card reader driver
- sl = init_reader(opts)
+ sl = init_reader(opts, proactive_handler = Proact())
if sl is None:
exit(1)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/28965
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ia4cdf06a44f46184d0da318bdf67077bc8ac9a1a
Gerrit-Change-Number: 28965
Gerrit-PatchSet: 4
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: merged