Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1 | /* Osmocom MSC+VLR end-to-end tests */ |
| 2 | |
| 3 | /* (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <getopt.h> |
| 25 | #include <stdlib.h> |
| 26 | |
| 27 | #include <osmocom/core/logging.h> |
| 28 | #include <osmocom/core/utils.h> |
| 29 | #include <osmocom/core/msgb.h> |
| 30 | #include <osmocom/core/application.h> |
| 31 | #include <osmocom/gsm/protocol/gsm_04_11.h> |
| 32 | #include <osmocom/gsm/gsup.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 33 | #include <osmocom/msc/gsup_client_mux.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 34 | #include <osmocom/msc/gsm_04_11.h> |
| 35 | #include <osmocom/msc/debug.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 36 | #include <osmocom/msc/gsm_04_08.h> |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 37 | #include <osmocom/msc/transaction.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 38 | #include <osmocom/msc/ran_msg.h> |
| 39 | #include <osmocom/msc/msc_a.h> |
| 40 | #include <osmocom/msc/msc_i.h> |
| 41 | #include <osmocom/msc/msc_t.h> |
| 42 | #include <osmocom/msc/call_leg.h> |
| 43 | #include <osmocom/msc/rtp_stream.h> |
Neels Hofmeyr | 62bfa37 | 2022-10-31 18:51:07 +0100 | [diff] [blame] | 44 | #include <osmocom/msc/codec_mapping.h> |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 45 | |
| 46 | #include "msc_vlr_tests.h" |
| 47 | |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 48 | void *msc_vlr_tests_ctx = NULL; |
Neels Hofmeyr | dbb3c72 | 2021-02-07 23:53:07 +0100 | [diff] [blame] | 49 | void *msgb_ctx = NULL; |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 50 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 51 | bool _log_lines = false; |
| 52 | |
| 53 | struct gsm_network *net = NULL; |
| 54 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 55 | const char *gsup_tx_expected = NULL; |
| 56 | bool gsup_tx_confirmed; |
| 57 | |
| 58 | struct msgb *dtap_tx_expected = NULL; |
| 59 | bool dtap_tx_confirmed; |
| 60 | |
| 61 | enum result_sent lu_result_sent; |
| 62 | enum result_sent cm_service_result_sent; |
| 63 | bool auth_request_sent; |
| 64 | const char *auth_request_expect_rand; |
| 65 | const char *auth_request_expect_autn; |
| 66 | bool cipher_mode_cmd_sent; |
| 67 | bool cipher_mode_cmd_sent_with_imeisv; |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 68 | const char *cipher_mode_expect_kc; |
| 69 | bool security_mode_ctrl_sent; |
| 70 | const char *security_mode_expect_ck; |
| 71 | const char *security_mode_expect_ik; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 72 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 73 | bool iu_release_expected = false; |
| 74 | bool iu_release_sent = false; |
| 75 | bool bssap_clear_expected = false; |
| 76 | bool bssap_clear_sent = false; |
| 77 | |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 78 | bool bssap_assignment_expected = false; |
| 79 | bool bssap_assignment_sent = false; |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 80 | struct gsm0808_channel_type bssap_assignment_command_last_channel_type; |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 81 | bool iu_rab_assignment_expected = false; |
| 82 | bool iu_rab_assignment_sent = false; |
| 83 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 84 | uint32_t cc_to_mncc_tx_expected_msg_type = 0; |
| 85 | const char *cc_to_mncc_tx_expected_imsi = NULL; |
| 86 | bool cc_to_mncc_tx_confirmed = false; |
| 87 | uint32_t cc_to_mncc_tx_got_callref = 0; |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 88 | char cc_to_mncc_tx_last_sdp[1024] = {}; |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 89 | |
Neels Hofmeyr | 81938fd | 2022-01-14 03:39:58 +0100 | [diff] [blame] | 90 | bool expecting_crcx[2] = {}; |
| 91 | bool got_crcx[2] = {}; |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 92 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 93 | extern int ran_dec_dtap_undup_pdisc_ctr_bin(uint8_t pdisc); |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 94 | |
| 95 | /* static state variables for the L3 send sequence numbers */ |
| 96 | static uint8_t n_sd[4]; |
| 97 | |
| 98 | /* patch a correct send sequence number into the given message */ |
| 99 | static void patch_l3_seq_nr(struct msgb *msg) |
| 100 | { |
| 101 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 102 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 103 | uint8_t *msg_type_oct = &msg->l3h[1]; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 104 | int bin = ran_dec_dtap_undup_pdisc_ctr_bin(pdisc); |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 105 | |
| 106 | if (bin >= 0 && bin < ARRAY_SIZE(n_sd)) { |
| 107 | /* patch in n_sd into the msg_type octet */ |
| 108 | *msg_type_oct = (*msg_type_oct & 0x3f) | ((n_sd[bin] & 0x3) << 6); |
| 109 | //fprintf(stderr, "pdisc=0x%02x bin=%d, patched n_sd=%u\n\n", pdisc, bin, n_sd[bin] & 3); |
| 110 | /* increment N(SD) */ |
| 111 | n_sd[bin] = (n_sd[bin] + 1) % 4; |
| 112 | } else { |
| 113 | //fprintf(stderr, "pdisc=0x%02x NO SEQ\n\n", pdisc); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* reset L3 sequence numbers (e.g. new RR connection) */ |
| 118 | static void reset_l3_seq_nr() |
| 119 | { |
| 120 | memset(n_sd, 0, sizeof(n_sd)); |
| 121 | } |
| 122 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 123 | struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex) |
| 124 | { |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 125 | struct msgb *msg = msgb_alloc_headroom(size, 4, label); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 126 | unsigned char *rc; |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 127 | msg->l2h = msg->data; |
| 128 | rc = msgb_put(msg, osmo_hexparse(hex, msg->data, msgb_tailroom(msg))); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 129 | OSMO_ASSERT(rc == msg->l2h); |
| 130 | return msg; |
| 131 | } |
| 132 | |
Max | d8d1a9e | 2018-02-06 15:50:20 +0100 | [diff] [blame] | 133 | static const char *gh_type_name(struct gsm48_hdr *gh) |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 134 | { |
| 135 | return gsm48_pdisc_msgtype_name(gsm48_hdr_pdisc(gh), |
| 136 | gsm48_hdr_msg_type(gh)); |
| 137 | } |
| 138 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 139 | void gsup_rx(const char *rx_hex, const char *expect_tx_hex) |
| 140 | { |
| 141 | int rc; |
| 142 | struct msgb *msg; |
| 143 | const char *label; |
| 144 | |
| 145 | gsup_expect_tx(expect_tx_hex); |
| 146 | |
| 147 | msg = msgb_from_hex("gsup", 1024, rx_hex); |
| 148 | label = osmo_gsup_message_type_name(msg->l2h[0]); |
| 149 | fprintf(stderr, "<-- GSUP rx %s: %s\n", label, |
| 150 | osmo_hexdump_nospc(msgb_l2(msg), msgb_l2len(msg))); |
Neels Hofmeyr | 834f94a | 2017-09-28 03:07:16 +0200 | [diff] [blame] | 151 | /* GSUP read cb takes ownership of msgb */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 152 | rc = gsup_client_mux_rx(net->gcm->gsup_client, msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 153 | fprintf(stderr, "<-- GSUP rx %s: vlr_gsupc_read_cb() returns %d\n", |
| 154 | label, rc); |
| 155 | if (expect_tx_hex) |
| 156 | OSMO_ASSERT(gsup_tx_confirmed); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 159 | bool conn_exists(const struct msub *msub) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 160 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 161 | struct msub *i; |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 162 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 163 | if (!msub) |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 164 | return false; |
| 165 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 166 | llist_for_each_entry(i, &msub_list, entry) { |
| 167 | if (i == msub) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 168 | return true; |
| 169 | } |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 170 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 171 | btw("msub gone"); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 172 | return false; |
| 173 | } |
| 174 | |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 175 | /* Simplified version of the cm_service_request_concludes() */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 176 | void conn_conclude_cm_service_req(struct msub *msub, const char *cm_service_use) |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 177 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 178 | int32_t count; |
| 179 | struct msc_a *msc_a = msub_msc_a(msub); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 180 | btw("Concluding CM Service Request"); |
| 181 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 182 | OSMO_ASSERT(conn_exists(msub)); |
| 183 | count = osmo_use_count_by(&msc_a->use_count, cm_service_use); |
| 184 | OSMO_ASSERT(count > 0); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 185 | |
Vadim Yanitskiy | d14422a | 2019-07-09 00:37:49 +0700 | [diff] [blame] | 186 | OSMO_ASSERT(osmo_use_count_get_put(&msc_a->use_count, cm_service_use, -count) == 0); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 187 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 188 | ASSERT_RELEASE_CLEAR(msc_a->c.ran->type); |
| 189 | } |
| 190 | |
| 191 | void dummy_msc_i_action(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 192 | { |
| 193 | } |
| 194 | |
| 195 | static const struct osmo_fsm_state dummy_msc_i_states[] = { |
| 196 | { |
| 197 | .name = "0", |
| 198 | .in_event_mask = 0xffffffff, |
| 199 | .action = dummy_msc_i_action, |
| 200 | }, |
| 201 | }; |
| 202 | |
| 203 | struct osmo_fsm dummy_msc_i_fsm = { |
| 204 | .name = "dummy_msc_i", |
| 205 | .states = dummy_msc_i_states, |
| 206 | .num_states = ARRAY_SIZE(dummy_msc_i_states), |
| 207 | .log_subsys = DMSC, |
| 208 | .event_names = msc_i_fsm_event_names, |
| 209 | }; |
| 210 | |
| 211 | struct msc_i *dummy_msc_i_alloc(struct msub *msub, struct ran_infra *ran) |
| 212 | { |
| 213 | return msub_role_alloc(g_msub, MSC_ROLE_I, &dummy_msc_i_fsm, struct msc_i, ran); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 214 | } |
| 215 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 216 | enum osmo_rat_type rx_from_ran = OSMO_RAT_GERAN_A; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 217 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 218 | struct msub *g_msub = NULL; |
Harald Welte | 977b548 | 2019-02-18 12:23:43 +0100 | [diff] [blame] | 219 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 220 | void dtap_expect_tx(const char *hex) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 221 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 222 | /* Has the previously expected dtap been received? */ |
| 223 | OSMO_ASSERT(!dtap_tx_expected); |
| 224 | if (!hex) |
| 225 | return; |
| 226 | dtap_tx_expected = msgb_from_hex("dtap_tx_expected", 1024, hex); |
| 227 | /* Mask the sequence number out */ |
| 228 | if (msgb_length(dtap_tx_expected) >= 2) |
| 229 | dtap_tx_expected->data[1] &= 0x3f; |
| 230 | dtap_tx_confirmed = false; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 233 | static int _validate_dtap(struct msgb *msg, enum osmo_rat_type to_ran) |
| 234 | { |
| 235 | struct gsm48_hdr *gh = (void*)msg->data; |
| 236 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 237 | uint8_t msgt = gsm48_hdr_msg_type(gh); |
| 238 | |
| 239 | btw("DTAP --%s--> MS: %s: %s", |
| 240 | osmo_rat_type_name(to_ran), gh_type_name((void*)msg->data), |
| 241 | osmo_hexdump_nospc(msg->data, msg->len)); |
| 242 | |
| 243 | if (pdisc == GSM48_PDISC_MM |
| 244 | && msgt == GSM48_MT_MM_CM_SERV_ACC) { |
| 245 | cm_service_result_sent |= RES_ACCEPT; |
| 246 | talloc_free(msg); |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | if (pdisc == GSM48_PDISC_MM |
| 251 | && msgt == GSM48_MT_MM_CM_SERV_REJ) { |
| 252 | cm_service_result_sent |= RES_REJECT; |
| 253 | talloc_free(msg); |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | OSMO_ASSERT(dtap_tx_expected); |
| 258 | |
| 259 | /* Mask the sequence number out before comparing */ |
| 260 | msg->data[1] &= 0x3f; |
Neels Hofmeyr | e0f906c | 2019-10-21 06:00:35 +0200 | [diff] [blame] | 261 | if (!msgb_eq_data_print(msg, dtap_tx_expected->data, dtap_tx_expected->len)) { |
| 262 | btw("Expected %s", osmo_hexdump(dtap_tx_expected->data, dtap_tx_expected->len)); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 263 | abort(); |
Neels Hofmeyr | e0f906c | 2019-10-21 06:00:35 +0200 | [diff] [blame] | 264 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 265 | |
| 266 | btw("DTAP matches expected message"); |
| 267 | |
| 268 | talloc_free(msg); |
| 269 | dtap_tx_confirmed = true; |
| 270 | talloc_free(dtap_tx_expected); |
| 271 | dtap_tx_expected = NULL; |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static void bssap_validate_clear_cmd() |
| 277 | { |
| 278 | OSMO_ASSERT(bssap_clear_expected); |
| 279 | bssap_clear_expected = false; |
| 280 | bssap_clear_sent = true; |
| 281 | } |
| 282 | |
| 283 | static void iucs_validate_clear_cmd() |
| 284 | { |
| 285 | OSMO_ASSERT(iu_release_expected); |
| 286 | iu_release_expected = false; |
| 287 | iu_release_sent = true; |
| 288 | } |
| 289 | |
| 290 | static int bssap_validate_cipher_mode_cmd(const struct ran_cipher_mode_command *cmd) |
| 291 | { |
| 292 | int i; |
| 293 | const char *got_key; |
| 294 | cipher_mode_cmd_sent = true; |
| 295 | cipher_mode_cmd_sent_with_imeisv = cmd->geran.retrieve_imeisv; |
| 296 | btw("sending Ciphering Mode Command: retrieve_imeisv=%d", cipher_mode_cmd_sent_with_imeisv); |
| 297 | for (i = 0; i < 7; i++) { |
| 298 | if (!(cmd->geran.a5_encryption_mask & (1 << i))) |
| 299 | continue; |
| 300 | btw("...perm algo: A5/%d", i); |
| 301 | } |
| 302 | got_key = osmo_hexdump_nospc(cmd->vec->kc, sizeof(cmd->vec->kc)); |
| 303 | btw("...key: %s", got_key); |
| 304 | |
| 305 | if (!cipher_mode_expect_kc |
| 306 | || strcmp(cipher_mode_expect_kc, got_key)) { |
| 307 | log("FAILURE: expected kc=%s", cipher_mode_expect_kc ? : "NULL"); |
| 308 | OSMO_ASSERT(false); |
| 309 | } |
| 310 | return 0; |
| 311 | } |
| 312 | |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 313 | static void bssap_validate_assignment_cmd(const struct ran_assignment_command *assignment_command) |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 314 | { |
| 315 | OSMO_ASSERT(bssap_assignment_expected); |
| 316 | bssap_assignment_expected = false; |
| 317 | bssap_assignment_sent = true; |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 318 | if (assignment_command->channel_type) |
| 319 | bssap_assignment_command_last_channel_type = *assignment_command->channel_type; |
| 320 | else |
| 321 | bssap_assignment_command_last_channel_type = (struct gsm0808_channel_type){}; |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 324 | static void iucs_validate_assignment_cmd(const struct ran_assignment_command *assignment_command) |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 325 | { |
| 326 | OSMO_ASSERT(iu_rab_assignment_expected); |
| 327 | iu_rab_assignment_expected = false; |
| 328 | iu_rab_assignment_sent = true; |
| 329 | } |
| 330 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 331 | static int iucs_validate_security_mode_ctrl(const struct ran_cipher_mode_command *cmd) |
| 332 | { |
| 333 | const char *got_ik; |
| 334 | got_ik = osmo_hexdump_nospc(cmd->vec->ik, sizeof(cmd->vec->ik)); |
| 335 | btw("sending SecurityModeControl: ik=%s", got_ik); |
| 336 | security_mode_ctrl_sent = true; |
| 337 | if (!security_mode_expect_ik |
| 338 | || strcmp(security_mode_expect_ik, got_ik)) { |
| 339 | log("FAILURE: expected ik=%s", security_mode_expect_ik ? : "NULL"); |
| 340 | OSMO_ASSERT(false); |
| 341 | } |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | struct msgb *dont_ran_encode(struct osmo_fsm_inst *caller_fi, const struct ran_msg *ran_enc_msg) |
| 346 | { |
| 347 | struct msc_role_common *c = caller_fi->priv; |
| 348 | enum osmo_rat_type ran_type = c->ran->type; |
| 349 | const char *ran_name = osmo_rat_type_name(ran_type); |
| 350 | LOG_RAN_ENC(caller_fi, DMSC, LOGL_INFO, "%s on %s\n", ran_msg_type_name(ran_enc_msg->msg_type), |
| 351 | ran_name); |
| 352 | |
| 353 | switch (ran_enc_msg->msg_type) { |
| 354 | case RAN_MSG_DTAP: |
| 355 | _validate_dtap(ran_enc_msg->dtap, ran_type); |
| 356 | break; |
| 357 | case RAN_MSG_CLEAR_COMMAND: |
| 358 | switch (ran_type) { |
| 359 | case OSMO_RAT_GERAN_A: |
| 360 | bssap_validate_clear_cmd(); |
| 361 | break; |
| 362 | case OSMO_RAT_UTRAN_IU: |
| 363 | iucs_validate_clear_cmd(); |
| 364 | break; |
| 365 | default: |
| 366 | OSMO_ASSERT(false); |
| 367 | } |
| 368 | break; |
| 369 | case RAN_MSG_CIPHER_MODE_COMMAND: |
| 370 | switch (ran_type) { |
| 371 | case OSMO_RAT_GERAN_A: |
| 372 | bssap_validate_cipher_mode_cmd(&ran_enc_msg->cipher_mode_command); |
| 373 | break; |
| 374 | case OSMO_RAT_UTRAN_IU: |
| 375 | iucs_validate_security_mode_ctrl(&ran_enc_msg->cipher_mode_command); |
| 376 | break; |
| 377 | default: |
| 378 | OSMO_ASSERT(false); |
| 379 | } |
| 380 | break; |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 381 | case RAN_MSG_ASSIGNMENT_COMMAND: |
| 382 | switch (ran_type) { |
| 383 | case OSMO_RAT_GERAN_A: |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 384 | bssap_validate_assignment_cmd(&ran_enc_msg->assignment_command); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 385 | break; |
| 386 | case OSMO_RAT_UTRAN_IU: |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 387 | iucs_validate_assignment_cmd(&ran_enc_msg->assignment_command); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 388 | break; |
| 389 | default: |
| 390 | OSMO_ASSERT(false); |
| 391 | } |
| 392 | break; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 393 | default: |
| 394 | break; |
| 395 | } |
| 396 | |
| 397 | /* We're testing MSC and VLR interaction, not message encoding. |
| 398 | * Return whatever. The test msc_i instance is a dummy and drops these. |
| 399 | * But it must be msg_free()-able. |
| 400 | */ |
| 401 | return msgb_alloc(1, "unused dummy msg"); |
| 402 | } |
| 403 | |
| 404 | struct ran_infra test_ran_infra[] = { |
| 405 | [OSMO_RAT_GERAN_A] = { |
| 406 | .type = OSMO_RAT_GERAN_A, |
| 407 | .an_proto = OSMO_GSUP_ACCESS_NETWORK_PROTOCOL_TS3G_48006, |
| 408 | .log_subsys = DBSSAP, |
| 409 | .tdefs = msc_tdefs_geran, |
| 410 | .ran_encode = dont_ran_encode, |
| 411 | }, |
| 412 | [OSMO_RAT_UTRAN_IU] = { |
| 413 | .type = OSMO_RAT_UTRAN_IU, |
| 414 | .an_proto = OSMO_GSUP_ACCESS_NETWORK_PROTOCOL_TS3G_25413, |
| 415 | .log_subsys = DIUCS, |
| 416 | .tdefs = msc_tdefs_utran, |
| 417 | .ran_encode = dont_ran_encode, |
Neels Hofmeyr | 1dc3961 | 2023-03-03 16:43:19 +0100 | [diff] [blame] | 418 | .force_mgw_codecs_to_ran = { |
| 419 | .count = 1, |
| 420 | .codec = { |
| 421 | { |
| 422 | .payload_type = 96, |
| 423 | .subtype_name = "VND.3GPP.IUFP", |
| 424 | .rate = 16000, |
| 425 | }, |
| 426 | }, |
| 427 | }, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 428 | }, |
| 429 | }; |
| 430 | |
| 431 | static int fake_msc_a_ran_dec(const struct ran_msg *ran_dec_msg) |
| 432 | { |
| 433 | struct msc_a_ran_dec_data d = { |
| 434 | .from_role = MSC_ROLE_I, |
| 435 | }; |
| 436 | return msc_a_ran_decode_cb(g_msub->role[MSC_ROLE_A], &d, ran_dec_msg); |
| 437 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 438 | |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 439 | void rx_from_ms(struct msgb *msg, const struct gsm0808_speech_codec_list *codec_list_bss_supported) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 440 | { |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 441 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 442 | struct ran_msg ran_dec_msg; |
| 443 | struct gsm0808_cell_id cell_id = { |
| 444 | .id_discr = CELL_IDENT_LAI_AND_LAC, |
| 445 | .id.lai_and_lac = { |
| 446 | .plmn = { |
| 447 | .mcc = 1, |
| 448 | .mnc = 2, |
| 449 | }, |
| 450 | .lac = 23, |
| 451 | }, |
| 452 | }; |
| 453 | struct msc_a *msc_a; |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 454 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 455 | log("MSC <--%s-- MS: %s", osmo_rat_type_name(rx_from_ran), gh_type_name(gh)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 456 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 457 | if (!conn_exists(g_msub)) |
| 458 | g_msub = NULL; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 459 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 460 | if (!g_msub) { |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 461 | log("new conn"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 462 | g_msub = msub_alloc(net); |
| 463 | msc_a_alloc(g_msub, &test_ran_infra[rx_from_ran]); |
| 464 | dummy_msc_i_alloc(g_msub, &test_ran_infra[rx_from_ran]); |
| 465 | |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 466 | reset_l3_seq_nr(); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 467 | ran_dec_msg = (struct ran_msg){ |
| 468 | .msg_type = RAN_MSG_COMPL_L3, |
| 469 | .compl_l3 = { |
| 470 | .cell_id = &cell_id, |
| 471 | .msg = msg, |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 472 | .codec_list_bss_supported = codec_list_bss_supported, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 473 | }, |
| 474 | }; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 475 | } else { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 476 | ran_dec_msg = (struct ran_msg){ |
| 477 | .msg_type = RAN_MSG_DTAP, |
| 478 | .dtap = msg, |
| 479 | }; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 482 | msc_a = msub_msc_a(g_msub); |
| 483 | msc_a_get(msc_a, __func__); |
| 484 | |
| 485 | patch_l3_seq_nr(msg); |
| 486 | fake_msc_a_ran_dec(&ran_dec_msg); |
| 487 | |
| 488 | msc_a_put(msc_a, __func__); |
| 489 | |
| 490 | if (!conn_exists(g_msub)) |
| 491 | g_msub = NULL; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | void ms_sends_msg(const char *hex) |
| 495 | { |
| 496 | struct msgb *msg; |
| 497 | |
| 498 | msg = msgb_from_hex("ms_sends_msg", 1024, hex); |
| 499 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 500 | rx_from_ms(msg, NULL); |
| 501 | msgb_free(msg); |
| 502 | } |
| 503 | |
| 504 | void ms_sends_msgf(const char *fmt, ...) |
| 505 | { |
| 506 | va_list ap; |
| 507 | char *hex; |
| 508 | |
| 509 | va_start(ap, fmt); |
| 510 | hex = talloc_vasprintf(msc_vlr_tests_ctx, fmt, ap); |
| 511 | va_end(ap); |
| 512 | |
| 513 | ms_sends_msg(hex); |
| 514 | talloc_free(hex); |
| 515 | } |
| 516 | |
| 517 | void ms_sends_compl_l3(const char *hex, const struct gsm0808_speech_codec_list *codec_list_bss_supported) |
| 518 | { |
| 519 | struct msgb *msg; |
| 520 | |
| 521 | msg = msgb_from_hex("ms_sends_msg", 1024, hex); |
| 522 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
| 523 | rx_from_ms(msg, codec_list_bss_supported); |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 524 | msgb_free(msg); |
| 525 | } |
| 526 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 527 | void ms_sends_classmark_update(const struct osmo_gsm48_classmark *classmark) |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 528 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 529 | struct ran_msg ran_dec = { |
| 530 | .msg_type = RAN_MSG_CLASSMARK_UPDATE, |
| 531 | .classmark_update = { |
| 532 | .classmark = classmark, |
| 533 | }, |
| 534 | }; |
| 535 | fake_msc_a_ran_dec(&ran_dec); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Max | d8d1a9e | 2018-02-06 15:50:20 +0100 | [diff] [blame] | 538 | static int ms_sends_msg_fake(uint8_t pdisc, uint8_t msg_type) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 539 | { |
| 540 | int rc; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 541 | struct ran_msg ran_dec; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 542 | struct msgb *msg; |
| 543 | struct gsm48_hdr *gh; |
| 544 | |
| 545 | msg = msgb_alloc(1024, "ms_sends_msg_fake"); |
| 546 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
| 547 | |
| 548 | gh = (struct gsm48_hdr*)msgb_put(msg, sizeof(*gh)); |
| 549 | gh->proto_discr = pdisc; |
| 550 | gh->msg_type = msg_type; |
| 551 | /* some amount of data, whatever */ |
| 552 | msgb_put(msg, 123); |
| 553 | |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 554 | patch_l3_seq_nr(msg); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 555 | |
| 556 | ran_dec = (struct ran_msg){ |
| 557 | .msg_type = RAN_MSG_DTAP, |
| 558 | .dtap = msg, |
| 559 | }; |
| 560 | rc = fake_msc_a_ran_dec(&ran_dec); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 561 | |
| 562 | talloc_free(msg); |
| 563 | return rc; |
| 564 | } |
| 565 | |
Max | 6817190 | 2018-02-06 17:55:19 +0100 | [diff] [blame] | 566 | static inline void ms_msg_log_err(uint8_t val, uint8_t msgtype) |
| 567 | { |
| 568 | int rc = ms_sends_msg_fake(val, msgtype); |
| 569 | if (rc != -EACCES) |
| 570 | log("Unexpected return value %u != %u for %s/%s", |
| 571 | -rc, -EACCES, gsm48_pdisc_name(val), gsm48_cc_msg_name(msgtype)); |
| 572 | } |
| 573 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 574 | void thwart_rx_non_initial_requests() |
| 575 | { |
| 576 | log("requests shall be thwarted"); |
Max | 6817190 | 2018-02-06 17:55:19 +0100 | [diff] [blame] | 577 | |
| 578 | ms_msg_log_err(GSM48_PDISC_CC, GSM48_MT_CC_SETUP); |
| 579 | ms_msg_log_err(GSM48_PDISC_MM, 0x33); /* nonexistent */ |
| 580 | ms_msg_log_err(GSM48_PDISC_RR, GSM48_MT_RR_SYSINFO_1); |
| 581 | ms_msg_log_err(GSM48_PDISC_SMS, GSM411_MT_CP_DATA); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | void send_sms(struct vlr_subscr *receiver, |
| 585 | struct vlr_subscr *sender, |
| 586 | char *str) |
| 587 | { |
Harald Welte | 39b5548 | 2018-04-09 19:19:33 +0200 | [diff] [blame] | 588 | struct gsm_sms *sms = sms_from_text(receiver, sender->msisdn, 0, str); |
Vadim Yanitskiy | 24e025e | 2018-11-22 15:42:39 +0700 | [diff] [blame] | 589 | gsm411_send_sms(net, receiver, sms); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | unsigned char next_rand_byte = 0; |
Max | 753c15d | 2017-12-21 14:50:44 +0100 | [diff] [blame] | 593 | /* override, requires '-Wl,--wrap=osmo_get_rand_id' */ |
| 594 | int __real_osmo_get_rand_id(uint8_t *buf, size_t num); |
| 595 | int __wrap_osmo_get_rand_id(uint8_t *buf, size_t num) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 596 | { |
Max | 753c15d | 2017-12-21 14:50:44 +0100 | [diff] [blame] | 597 | size_t i; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 598 | for (i = 0; i < num; i++) |
| 599 | buf[i] = next_rand_byte++; |
| 600 | return 1; |
| 601 | } |
| 602 | |
| 603 | /* override, requires '-Wl,--wrap=gsm340_gen_scts' */ |
| 604 | void __real_gsm340_gen_scts(uint8_t *scts, time_t time); |
| 605 | void __wrap_gsm340_gen_scts(uint8_t *scts, time_t time) |
| 606 | { |
Neels Hofmeyr | 05230ea | 2017-08-22 18:06:42 +0200 | [diff] [blame] | 607 | /* Write fixed time bytes for deterministic test results */ |
| 608 | osmo_hexparse("07101000000000", scts, 7); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | const char *paging_expecting_imsi = NULL; |
| 612 | uint32_t paging_expecting_tmsi; |
| 613 | bool paging_sent; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 614 | |
| 615 | void paging_expect_imsi(const char *imsi) |
| 616 | { |
| 617 | paging_expecting_imsi = imsi; |
| 618 | paging_expecting_tmsi = GSM_RESERVED_TMSI; |
| 619 | } |
| 620 | |
| 621 | void paging_expect_tmsi(uint32_t tmsi) |
| 622 | { |
| 623 | paging_expecting_tmsi = tmsi; |
| 624 | paging_expecting_imsi = NULL; |
| 625 | } |
| 626 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 627 | /* override, requires '-Wl,--wrap=ran_peers_down_paging' */ |
| 628 | int __real_ran_peers_down_paging(struct sccp_ran_inst *sri, enum CELL_IDENT page_where, struct vlr_subscr *vsub, |
| 629 | enum paging_cause cause); |
| 630 | int __wrap_ran_peers_down_paging(struct sccp_ran_inst *sri, enum CELL_IDENT page_where, struct vlr_subscr *vsub, |
| 631 | enum paging_cause cause) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 632 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 633 | log("paging request (%s) to %s on %s", paging_cause_name(cause), vlr_subscr_name(vsub), |
| 634 | osmo_rat_type_name(sri->ran->type)); |
| 635 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 636 | OSMO_ASSERT(paging_expecting_imsi || (paging_expecting_tmsi != GSM_RESERVED_TMSI)); |
| 637 | if (paging_expecting_imsi) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 638 | VERBOSE_ASSERT(strcmp(paging_expecting_imsi, vsub->imsi), == 0, "%d"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 639 | if (paging_expecting_tmsi != GSM_RESERVED_TMSI) { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 640 | VERBOSE_ASSERT(paging_expecting_tmsi, == vsub->tmsi, "0x%08x"); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 641 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 642 | paging_sent = true; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 643 | return 1; |
| 644 | } |
| 645 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 646 | void clear_vlr() |
| 647 | { |
| 648 | struct vlr_subscr *vsub, *n; |
| 649 | llist_for_each_entry_safe(vsub, n, &net->vlr->subscribers, list) { |
| 650 | vlr_subscr_free(vsub); |
| 651 | } |
| 652 | |
| 653 | net->authentication_required = false; |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 654 | net->a5_encryption_mask = (1 << 0); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 655 | net->vlr->cfg.check_imei_rqd = false; |
| 656 | net->vlr->cfg.assign_tmsi = false; |
Neels Hofmeyr | 54a706c | 2017-07-18 15:39:27 +0200 | [diff] [blame] | 657 | net->vlr->cfg.retrieve_imeisv_early = false; |
| 658 | net->vlr->cfg.retrieve_imeisv_ciphered = false; |
Neels Hofmeyr | 7b1418e | 2017-10-29 02:12:16 +0100 | [diff] [blame] | 659 | net->vlr->cfg.auth_tuple_max_reuse_count = 0; |
| 660 | net->vlr->cfg.auth_reuse_old_sets_on_error = false; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 661 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 662 | rx_from_ran = OSMO_RAT_GERAN_A; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 663 | auth_request_sent = false; |
| 664 | auth_request_expect_rand = NULL; |
| 665 | auth_request_expect_autn = NULL; |
| 666 | |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 667 | cipher_mode_cmd_sent = false; |
| 668 | cipher_mode_cmd_sent_with_imeisv = false; |
| 669 | cipher_mode_expect_kc = NULL; |
| 670 | |
| 671 | security_mode_ctrl_sent = false; |
| 672 | security_mode_expect_ck = NULL; |
| 673 | security_mode_expect_ik = NULL; |
| 674 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 675 | next_rand_byte = 0; |
| 676 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 677 | iu_release_expected = false; |
| 678 | iu_release_sent = false; |
| 679 | bssap_clear_expected = false; |
| 680 | bssap_clear_sent = false; |
| 681 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 682 | osmo_gettimeofday_override = false; |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 683 | |
Neels Hofmeyr | 81938fd | 2022-01-14 03:39:58 +0100 | [diff] [blame] | 684 | memset(expecting_crcx, 0, sizeof(expecting_crcx)); |
| 685 | memset(got_crcx, 0, sizeof(got_crcx)); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 686 | |
| 687 | bssap_assignment_expected = false; |
| 688 | bssap_assignment_sent = false; |
| 689 | iu_rab_assignment_expected = false; |
| 690 | iu_rab_assignment_sent = false; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | static struct log_info_cat test_categories[] = { |
| 694 | [DMSC] = { |
| 695 | .name = "DMSC", |
| 696 | .description = "Mobile Switching Center", |
| 697 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 698 | }, |
| 699 | [DRLL] = { |
| 700 | .name = "DRLL", |
| 701 | .description = "A-bis Radio Link Layer (RLL)", |
| 702 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 703 | }, |
| 704 | [DMM] = { |
| 705 | .name = "DMM", |
| 706 | .description = "Layer3 Mobility Management (MM)", |
| 707 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 708 | }, |
| 709 | [DRR] = { |
| 710 | .name = "DRR", |
| 711 | .description = "Layer3 Radio Resource (RR)", |
| 712 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 713 | }, |
| 714 | [DCC] = { |
| 715 | .name = "DCC", |
| 716 | .description = "Layer3 Call Control (CC)", |
Neels Hofmeyr | 12e17be | 2018-03-12 23:59:37 +0100 | [diff] [blame] | 717 | .enabled = 1, .loglevel = LOGL_DEBUG, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 718 | }, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 719 | [DVLR] = { |
| 720 | .name = "DVLR", |
| 721 | .description = "Visitor Location Register", |
| 722 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 723 | }, |
| 724 | [DREF] = { |
| 725 | .name = "DREF", |
| 726 | .description = "Reference Counting", |
| 727 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 728 | }, |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 729 | [DPAG] = { |
| 730 | .name = "DPAG", |
| 731 | .description = "Paging Subsystem", |
| 732 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 733 | }, |
| 734 | [DIUCS] = { |
| 735 | .name = "DIUCS", |
| 736 | .description = "Iu-CS Protocol", |
| 737 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 738 | }, |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 739 | [DMNCC] = { |
| 740 | .name = "DMNCC", |
| 741 | .description = "MNCC API for Call Control application", |
| 742 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 743 | }, |
Neels Hofmeyr | 46c06e2 | 2019-01-04 17:42:05 +0100 | [diff] [blame] | 744 | [DBSSAP] = { |
| 745 | .name = "DBSSAP", |
| 746 | .description = "BSSAP Protocol (A Interface)", |
| 747 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 748 | }, |
Neels Hofmeyr | 979b057 | 2019-05-09 15:24:49 +0200 | [diff] [blame] | 749 | [DSS] = { |
| 750 | .name = "DSS", |
| 751 | .description = "Supplementary Services", |
| 752 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 753 | }, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 754 | }; |
| 755 | |
| 756 | static struct log_info info = { |
| 757 | .cat = test_categories, |
| 758 | .num_cat = ARRAY_SIZE(test_categories), |
| 759 | }; |
| 760 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 761 | struct gsm_mncc *on_call_release_mncc_sends_to_cc_data = NULL; |
| 762 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 763 | int mncc_recv(struct gsm_network *net, struct msgb *msg) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 764 | { |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 765 | struct gsm_mncc *mncc = (void*)msg->data; |
Neels Hofmeyr | 3c323dc | 2022-01-14 03:35:08 +0100 | [diff] [blame] | 766 | if (mncc->msg_type == MNCC_RTP_CREATE) { |
| 767 | struct gsm_mncc_rtp *rtp = (void *)msg->data; |
| 768 | log("MSC --> MNCC: callref 0x%x: %s\n%s", rtp->callref, |
| 769 | get_mncc_name(rtp->msg_type), |
| 770 | rtp->sdp); |
| 771 | OSMO_STRLCPY_ARRAY(cc_to_mncc_tx_last_sdp, rtp->sdp); |
| 772 | } else { |
| 773 | log("MSC --> MNCC: callref 0x%x: %s\n%s", mncc->callref, |
| 774 | get_mncc_name(mncc->msg_type), |
| 775 | mncc->sdp); |
| 776 | OSMO_STRLCPY_ARRAY(cc_to_mncc_tx_last_sdp, mncc->sdp); |
| 777 | } |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 778 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 779 | if (mncc->msg_type == MNCC_REL_IND && on_call_release_mncc_sends_to_cc_data) { |
| 780 | |
| 781 | log("MNCC: callref 0x%x: Call Release triggering %s", mncc->callref, |
| 782 | get_mncc_name(on_call_release_mncc_sends_to_cc_data->msg_type)); |
| 783 | |
Neels Hofmeyr | 5255874 | 2019-05-09 01:23:09 +0200 | [diff] [blame] | 784 | mncc_tx_to_cc(net, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 785 | on_call_release_mncc_sends_to_cc_data); |
| 786 | |
| 787 | on_call_release_mncc_sends_to_cc_data = NULL; |
| 788 | return 0; |
| 789 | } |
| 790 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 791 | OSMO_ASSERT(cc_to_mncc_tx_expected_msg_type); |
| 792 | if (cc_to_mncc_tx_expected_msg_type != mncc->msg_type) { |
| 793 | log("Mismatch! Expected MNCC msg type: %s", |
| 794 | get_mncc_name(cc_to_mncc_tx_expected_msg_type)); |
| 795 | abort(); |
| 796 | } |
| 797 | |
| 798 | if (strcmp(cc_to_mncc_tx_expected_imsi, mncc->imsi)) { |
| 799 | log("Mismatch! Expected MNCC msg IMSI: '%s', got '%s'", |
| 800 | cc_to_mncc_tx_expected_imsi, |
| 801 | mncc->imsi); |
| 802 | abort(); |
| 803 | } |
| 804 | |
| 805 | cc_to_mncc_tx_confirmed = true; |
| 806 | cc_to_mncc_tx_got_callref = mncc->callref; |
| 807 | cc_to_mncc_tx_expected_imsi = NULL; |
| 808 | cc_to_mncc_tx_expected_msg_type = 0; |
| 809 | talloc_free(msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 810 | return 0; |
| 811 | } |
| 812 | |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 813 | struct osmo_gsup_client * |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 814 | __real_osmo_gsup_client_create2(struct ipaccess_unit *ipa_dev, const char *ip_addr, |
| 815 | unsigned int tcp_port, osmo_gsup_client_read_cb_t read_cb, |
| 816 | struct osmo_oap_client_config *oap_config); |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 817 | struct osmo_gsup_client * |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 818 | __wrap_osmo_gsup_client_create2(struct ipaccess_unit *ipa_dev, const char *ip_addr, |
| 819 | unsigned int tcp_port, osmo_gsup_client_read_cb_t read_cb, |
| 820 | struct osmo_oap_client_config *oap_config) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 821 | { |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 822 | struct osmo_gsup_client *gsupc; |
| 823 | gsupc = talloc_zero(msc_vlr_tests_ctx, struct osmo_gsup_client); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 824 | OSMO_ASSERT(gsupc); |
| 825 | return gsupc; |
| 826 | } |
| 827 | |
| 828 | /* override, requires '-Wl,--wrap=gsup_client_send' */ |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 829 | int __real_osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg); |
| 830 | int __wrap_osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 831 | { |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 832 | uint8_t buf[512]; |
| 833 | int len; |
| 834 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 835 | fprintf(stderr, "GSUP --> HLR: %s: %s\n", |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 836 | osmo_gsup_message_type_name(msg->data[0]), osmo_hexdump_nospc(msg->data, msg->len)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 837 | |
| 838 | OSMO_ASSERT(gsup_tx_expected); |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 839 | OSMO_ASSERT(strlen(gsup_tx_expected) <= (sizeof(buf) * 2)); |
| 840 | |
| 841 | len = osmo_hexparse(gsup_tx_expected, buf, sizeof(buf)); |
| 842 | if (len < 1) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 843 | abort(); |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 844 | |
Neels Hofmeyr | be5f033 | 2018-12-26 01:11:57 +0100 | [diff] [blame] | 845 | /* Compare only the length expected. Extra data is fine, to not care about new GSUP IEs invented later. */ |
| 846 | if (msg->len < len) { |
| 847 | fprintf(stderr, "ERROR: GSUP message too short, expected '%s'\n", gsup_tx_expected); |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 848 | abort(); |
Neels Hofmeyr | be5f033 | 2018-12-26 01:11:57 +0100 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | if (memcmp(msg->data, buf, len)) { |
| 852 | fprintf(stderr, "ERROR: GSUP message mismatch, expected it to start with '%s'\n", gsup_tx_expected); |
| 853 | abort(); |
| 854 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 855 | |
| 856 | talloc_free(msg); |
| 857 | gsup_tx_confirmed = true; |
| 858 | gsup_tx_expected = NULL; |
| 859 | return 0; |
| 860 | } |
| 861 | |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 862 | struct rtp_stream fake_rtp[2] = { |
| 863 | { |
| 864 | .dir = RTP_TO_RAN, |
| 865 | .local = { |
| 866 | .ip = "10.23.42.1", |
| 867 | .port = 99, |
| 868 | }, |
| 869 | .remote = { |
| 870 | .ip = "10.23.42.2", |
| 871 | .port = 100, |
| 872 | }, |
| 873 | }, |
| 874 | { |
| 875 | .dir = RTP_TO_CN, |
| 876 | .local = { |
| 877 | .ip = "10.23.42.1", |
| 878 | .port = 23, |
| 879 | }, |
| 880 | .remote = { |
| 881 | .ip = "10.23.42.2", |
| 882 | .port = 42, |
| 883 | }, |
| 884 | }, |
| 885 | }; |
| 886 | |
| 887 | void expect_crcx(enum rtp_direction towards) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 888 | { |
Neels Hofmeyr | 81938fd | 2022-01-14 03:39:58 +0100 | [diff] [blame] | 889 | OSMO_ASSERT(!expecting_crcx[towards]); |
| 890 | expecting_crcx[towards] = true; |
| 891 | got_crcx[towards] = false; |
| 892 | } |
| 893 | |
| 894 | bool crcx_scheduled(enum rtp_direction towards) |
| 895 | { |
| 896 | return got_crcx[towards]; |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /* override, requires '-Wl,--wrap=call_leg_ensure_ci' */ |
| 900 | int __real_call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans, |
Neels Hofmeyr | 62bfa37 | 2022-10-31 18:51:07 +0100 | [diff] [blame] | 901 | const struct sdp_audio_codecs *codecs_if_known, |
| 902 | const struct osmo_sockaddr_str *remote_addr_if_known); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 903 | int __wrap_call_leg_ensure_ci(struct call_leg *cl, enum rtp_direction dir, uint32_t call_id, struct gsm_trans *for_trans, |
Neels Hofmeyr | 62bfa37 | 2022-10-31 18:51:07 +0100 | [diff] [blame] | 904 | const struct sdp_audio_codecs *codecs_if_known, |
| 905 | const struct osmo_sockaddr_str *remote_addr_if_known) |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 906 | { |
| 907 | if (!cl->rtp[dir]) { |
Neels Hofmeyr | 62bfa37 | 2022-10-31 18:51:07 +0100 | [diff] [blame] | 908 | log("MGW <--CRCX to %s-- MSC: callref=0x%x codecs=%s", rtp_direction_name(dir), call_id, |
| 909 | codecs_if_known ? sdp_audio_codecs_to_str(codecs_if_known) : "unset"); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 910 | |
Neels Hofmeyr | 81938fd | 2022-01-14 03:39:58 +0100 | [diff] [blame] | 911 | OSMO_ASSERT(expecting_crcx[dir]); |
| 912 | expecting_crcx[dir] = false; |
| 913 | got_crcx[dir] = true; |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 914 | |
| 915 | call_leg_ensure_rtp_alloc(cl, dir, call_id, for_trans); |
Neels Hofmeyr | 62bfa37 | 2022-10-31 18:51:07 +0100 | [diff] [blame] | 916 | if (codecs_if_known) |
| 917 | rtp_stream_set_codecs(cl->rtp[dir], codecs_if_known); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 918 | if (remote_addr_if_known && osmo_sockaddr_str_is_nonzero(remote_addr_if_known)) |
| 919 | rtp_stream_set_remote_addr(cl->rtp[dir], remote_addr_if_known); |
| 920 | } |
| 921 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 922 | return 0; |
| 923 | } |
| 924 | |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 925 | void crcx_ok(enum rtp_direction dir) |
| 926 | { |
| 927 | struct msc_a *msc_a = msub_msc_a(g_msub); |
| 928 | struct call_leg *cl = msc_a->cc.call_leg; |
| 929 | OSMO_ASSERT(cl); |
| 930 | OSMO_ASSERT(cl->rtp[dir]); |
| 931 | osmo_sockaddr_str_from_str(&cl->rtp[dir]->local, "10.23.23.1", 23); |
| 932 | //osmo_sockaddr_str_from_str(&cl->rtp[dir].remote, "10.42.42.1", 42); |
| 933 | log("MGW --CRCX OK to %s--> MSC", rtp_direction_name(dir)); |
| 934 | osmo_fsm_inst_dispatch(cl->fi, CALL_LEG_EV_RTP_STREAM_ADDR_AVAILABLE, cl->rtp[dir]); |
| 935 | } |
| 936 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 937 | static int fake_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi) |
| 938 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 939 | struct msc_a *msc_a = msc_conn_ref; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 940 | if (send_tmsi == GSM_RESERVED_TMSI) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 941 | btw("sending LU Accept for %s", msc_a->c.fi->id); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 942 | else |
| 943 | btw("sending LU Accept for %s, with TMSI 0x%08x", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 944 | msc_a->c.fi->id, send_tmsi); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 945 | lu_result_sent |= RES_ACCEPT; |
| 946 | return 0; |
| 947 | } |
| 948 | |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 949 | static int fake_vlr_tx_lu_rej(void *msc_conn_ref, enum gsm48_reject_value cause) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 950 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 951 | struct msc_a *msc_a = msc_conn_ref; |
| 952 | btw("sending LU Reject for %s, cause %u", msc_a->c.fi->id, cause); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 953 | lu_result_sent |= RES_REJECT; |
| 954 | return 0; |
| 955 | } |
| 956 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 957 | static int fake_vlr_tx_cm_serv_rej(void *msc_conn_ref, enum osmo_cm_service_type cm_service_type, |
| 958 | enum gsm48_reject_value cause) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 959 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 960 | struct msc_a *msc_a = msc_conn_ref; |
| 961 | btw("sending CM Service Reject (%s) for %s, cause: %s", |
| 962 | osmo_cm_service_type_name(cm_service_type), msc_a->c.fi->id, gsm48_reject_value_name(cause)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 963 | cm_service_result_sent |= RES_REJECT; |
| 964 | return 0; |
| 965 | } |
| 966 | |
Neels Hofmeyr | 8b6e536 | 2018-11-30 02:57:33 +0100 | [diff] [blame] | 967 | static int fake_vlr_tx_auth_req(void *msc_conn_ref, struct vlr_auth_tuple *at, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 968 | bool send_autn) |
| 969 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 970 | struct msc_a *msc_a = msc_conn_ref; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 971 | char *hex; |
| 972 | bool ok = true; |
| 973 | btw("sending %s Auth Request for %s: tuple use_count=%d key_seq=%d auth_types=0x%x and...", |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 974 | send_autn? "UMTS" : "GSM", msc_a->c.fi->id, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 975 | at->use_count, at->key_seq, at->vec.auth_types); |
| 976 | |
| 977 | hex = osmo_hexdump_nospc((void*)&at->vec.rand, sizeof(at->vec.rand)); |
| 978 | btw("...rand=%s", hex); |
| 979 | if (!auth_request_expect_rand |
| 980 | || strcmp(hex, auth_request_expect_rand) != 0) { |
| 981 | ok = false; |
| 982 | log("FAILURE: expected rand=%s", |
| 983 | auth_request_expect_rand ? auth_request_expect_rand : "-"); |
| 984 | } |
| 985 | |
| 986 | if (send_autn) { |
| 987 | hex = osmo_hexdump_nospc((void*)&at->vec.autn, sizeof(at->vec.autn)); |
| 988 | btw("...autn=%s", hex); |
| 989 | if (!auth_request_expect_autn |
| 990 | || strcmp(hex, auth_request_expect_autn) != 0) { |
| 991 | ok = false; |
| 992 | log("FAILURE: expected autn=%s", |
| 993 | auth_request_expect_autn ? auth_request_expect_autn : "-"); |
| 994 | } |
| 995 | } else if (auth_request_expect_autn) { |
| 996 | ok = false; |
| 997 | log("FAILURE: no AUTN sent, expected AUTN = %s", |
| 998 | auth_request_expect_autn); |
| 999 | } |
| 1000 | |
| 1001 | if (send_autn) |
| 1002 | btw("...expecting res=%s", |
| 1003 | osmo_hexdump_nospc((void*)&at->vec.res, at->vec.res_len)); |
| 1004 | else |
| 1005 | btw("...expecting sres=%s", |
| 1006 | osmo_hexdump_nospc((void*)&at->vec.sres, sizeof(at->vec.sres))); |
| 1007 | |
| 1008 | auth_request_sent = ok; |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static int fake_vlr_tx_auth_rej(void *msc_conn_ref) |
| 1013 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1014 | struct msc_a *msc_a = msc_conn_ref; |
| 1015 | btw("sending Auth Reject for %s", msc_a->c.fi->id); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1016 | return 0; |
| 1017 | } |
| 1018 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1019 | void ms_sends_ciphering_mode_complete(const char *inner_ran_msg) |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 1020 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1021 | struct ran_msg ran_dec; |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 1022 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1023 | msc_a_get(msub_msc_a(g_msub), __func__); |
| 1024 | |
| 1025 | ran_dec = (struct ran_msg){ |
| 1026 | .msg_type = RAN_MSG_CIPHER_MODE_COMPLETE, |
| 1027 | }; |
| 1028 | fake_msc_a_ran_dec(&ran_dec); |
| 1029 | |
| 1030 | if (inner_ran_msg) { |
| 1031 | struct msgb *msg = msgb_from_hex("cipher_mode_complete_ran", 1024, inner_ran_msg); |
| 1032 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
| 1033 | ran_dec = (struct ran_msg){ |
| 1034 | .msg_type = RAN_MSG_DTAP, |
| 1035 | .dtap = msg, |
| 1036 | }; |
| 1037 | patch_l3_seq_nr(msg); |
| 1038 | fake_msc_a_ran_dec(&ran_dec); |
| 1039 | msgb_free(msg); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 1040 | } |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 1041 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1042 | msc_a_put(msub_msc_a(g_msub), __func__); |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 1043 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1044 | if (!conn_exists(g_msub)) |
| 1045 | g_msub = NULL; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Alexander Couzens | 2aaff75 | 2021-10-19 17:09:11 +0200 | [diff] [blame] | 1048 | void ms_sends_security_mode_complete(uint8_t utran_encryption) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1049 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1050 | struct ran_msg ran_dec; |
| 1051 | |
| 1052 | ran_dec = (struct ran_msg){ |
| 1053 | .msg_type = RAN_MSG_CIPHER_MODE_COMPLETE, |
Alexander Couzens | 2aaff75 | 2021-10-19 17:09:11 +0200 | [diff] [blame] | 1054 | .cipher_mode_complete.utran_encryption = utran_encryption, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1055 | }; |
| 1056 | fake_msc_a_ran_dec(&ran_dec); |
| 1057 | |
| 1058 | if (!conn_exists(g_msub)) |
| 1059 | g_msub = NULL; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
Neels Hofmeyr | cec51b3 | 2023-03-01 03:47:45 +0100 | [diff] [blame] | 1062 | void ms_sends_assignment_complete(const char *sdp_codec_name) |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 1063 | { |
| 1064 | struct ran_msg ran_dec; |
Neels Hofmeyr | cec51b3 | 2023-03-01 03:47:45 +0100 | [diff] [blame] | 1065 | const struct codec_mapping *m = codec_mapping_by_subtype_name(sdp_codec_name); |
| 1066 | OSMO_ASSERT(m); |
| 1067 | OSMO_ASSERT(m->has_gsm0808_speech_codec); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 1068 | |
| 1069 | ran_dec = (struct ran_msg){ |
| 1070 | .msg_type = RAN_MSG_ASSIGNMENT_COMPLETE, |
| 1071 | .assignment_complete = { |
Pau Espin Pedrol | 9de384a | 2022-01-07 16:27:04 +0100 | [diff] [blame] | 1072 | .codec_present = true, |
Neels Hofmeyr | cec51b3 | 2023-03-01 03:47:45 +0100 | [diff] [blame] | 1073 | .codec = m->gsm0808_speech_codec, |
| 1074 | .codec_with_iuup = (rx_from_ran == OSMO_RAT_UTRAN_IU), |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 1075 | }, |
| 1076 | }; |
Neels Hofmeyr | 8159c95 | 2022-08-06 16:23:31 +0200 | [diff] [blame] | 1077 | osmo_sockaddr_str_from_str(&ran_dec.assignment_complete.remote_rtp, "1.2.3.4", 1234); |
Neels Hofmeyr | 3f391dd | 2019-08-29 03:53:11 +0200 | [diff] [blame] | 1078 | fake_msc_a_ran_dec(&ran_dec); |
| 1079 | |
| 1080 | if (!conn_exists(g_msub)) |
| 1081 | g_msub = NULL; |
| 1082 | } |
| 1083 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1084 | void ran_sends_clear_complete() |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 1085 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1086 | struct ran_msg ran_dec; |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 1087 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1088 | ran_dec = (struct ran_msg){ |
| 1089 | .msg_type = RAN_MSG_CLEAR_COMPLETE, |
| 1090 | }; |
| 1091 | fake_msc_a_ran_dec(&ran_dec); |
| 1092 | |
| 1093 | if (!conn_exists(g_msub)) |
| 1094 | g_msub = NULL; |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1097 | const struct timeval fake_time_start_time = { 123, 456 }; |
| 1098 | |
| 1099 | void fake_time_start() |
| 1100 | { |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 1101 | struct timespec *clock_override; |
| 1102 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1103 | osmo_gettimeofday_override_time = fake_time_start_time; |
| 1104 | osmo_gettimeofday_override = true; |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 1105 | clock_override = osmo_clock_override_gettimespec(CLOCK_MONOTONIC); |
| 1106 | OSMO_ASSERT(clock_override); |
| 1107 | clock_override->tv_sec = fake_time_start_time.tv_sec; |
| 1108 | clock_override->tv_nsec = fake_time_start_time.tv_usec * 1000; |
| 1109 | osmo_clock_override_enable(CLOCK_MONOTONIC, true); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1110 | fake_time_passes(0, 0); |
| 1111 | } |
| 1112 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1113 | static struct { |
| 1114 | bool verbose; |
| 1115 | int run_test_nr; |
| 1116 | } cmdline_opts = { |
| 1117 | .verbose = false, |
| 1118 | .run_test_nr = -1, |
| 1119 | }; |
| 1120 | |
| 1121 | static void print_help(const char *program) |
| 1122 | { |
| 1123 | printf("Usage:\n" |
| 1124 | " %s [-v] [N [N...]]\n" |
| 1125 | "Options:\n" |
| 1126 | " -h --help show this text.\n" |
| 1127 | " -v --verbose print source file and line numbers\n" |
| 1128 | " N run only the Nth test (first test is N=1)\n", |
| 1129 | program |
| 1130 | ); |
| 1131 | } |
| 1132 | |
| 1133 | static void handle_options(int argc, char **argv) |
| 1134 | { |
| 1135 | while (1) { |
| 1136 | int option_index = 0, c; |
| 1137 | static struct option long_options[] = { |
| 1138 | {"help", 0, 0, 'h'}, |
| 1139 | {"verbose", 1, 0, 'v'}, |
| 1140 | {0, 0, 0, 0} |
| 1141 | }; |
| 1142 | |
| 1143 | c = getopt_long(argc, argv, "hv", |
| 1144 | long_options, &option_index); |
| 1145 | if (c == -1) |
| 1146 | break; |
| 1147 | |
| 1148 | switch (c) { |
| 1149 | case 'h': |
| 1150 | print_help(argv[0]); |
| 1151 | exit(0); |
| 1152 | case 'v': |
| 1153 | cmdline_opts.verbose = true; |
| 1154 | break; |
| 1155 | default: |
| 1156 | /* catch unknown options *as well as* missing arguments. */ |
| 1157 | fprintf(stderr, "Error in command line options. Exiting.\n"); |
| 1158 | exit(-1); |
| 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1164 | static void run_tests(int nr) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1165 | { |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1166 | int test_nr; |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 1167 | |
Max | 5e2e9bd | 2018-02-06 19:31:08 +0100 | [diff] [blame] | 1168 | nr--; /* arg's first test is 1, in here it's 0 */ |
| 1169 | for (test_nr = 0; msc_vlr_tests[test_nr]; test_nr++) { |
Neels Hofmeyr | dbb3c72 | 2021-02-07 23:53:07 +0100 | [diff] [blame] | 1170 | size_t talloc_blocks_before_test; |
| 1171 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1172 | if (nr >= 0 && test_nr != nr) |
| 1173 | continue; |
| 1174 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1175 | if (cmdline_opts.verbose) |
| 1176 | fprintf(stderr, "(test nr %d)\n", test_nr + 1); |
| 1177 | |
Neels Hofmeyr | dbb3c72 | 2021-02-07 23:53:07 +0100 | [diff] [blame] | 1178 | talloc_blocks_before_test = talloc_total_blocks(msc_vlr_tests_ctx); |
| 1179 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1180 | msc_vlr_tests[test_nr](); |
| 1181 | |
Neels Hofmeyr | dbb3c72 | 2021-02-07 23:53:07 +0100 | [diff] [blame] | 1182 | if (talloc_total_blocks(msc_vlr_tests_ctx) != talloc_blocks_before_test) { |
| 1183 | fprintf(stderr, "ERROR: talloc leak: %zu blocks\n", |
| 1184 | talloc_total_blocks(msc_vlr_tests_ctx) - talloc_blocks_before_test); |
| 1185 | talloc_report_full(msc_vlr_tests_ctx, stderr); |
| 1186 | fprintf(stderr, "\n"); |
| 1187 | } |
| 1188 | |
| 1189 | if (talloc_total_blocks(msgb_ctx) > 1) { |
| 1190 | fprintf(stderr, "ERROR: msgb leak:\n"); |
| 1191 | talloc_report_full(msgb_ctx, stderr); |
| 1192 | fprintf(stderr, "\n"); |
| 1193 | } |
| 1194 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1195 | if (cmdline_opts.verbose) |
| 1196 | fprintf(stderr, "(test nr %d)\n", test_nr + 1); |
Max | 29ce08a | 2018-02-06 18:46:57 +0100 | [diff] [blame] | 1197 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1198 | } |
| 1199 | |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 1200 | struct gsm_network *test_net(void *ctx) |
| 1201 | { |
Neels Hofmeyr | 7f48420 | 2018-02-27 12:59:45 +0100 | [diff] [blame] | 1202 | struct gsm_network *net = gsm_network_init(ctx, mncc_recv); |
Pau Espin Pedrol | b44cf2d | 2022-10-17 18:09:15 +0200 | [diff] [blame] | 1203 | struct mgcp_client *client; |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 1204 | |
| 1205 | net->gsup_server_addr_str = talloc_strdup(net, "no_gsup_server"); |
| 1206 | net->gsup_server_port = 0; |
| 1207 | |
| 1208 | OSMO_ASSERT(msc_vlr_alloc(net) == 0); |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 1209 | OSMO_ASSERT(net->vlr); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1210 | OSMO_ASSERT(msc_gsup_client_start(net) == 0); |
| 1211 | OSMO_ASSERT(net->gcm); |
| 1212 | OSMO_ASSERT(msc_vlr_start(net) == 0); |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 1213 | |
| 1214 | net->vlr->ops.tx_lu_acc = fake_vlr_tx_lu_acc; |
| 1215 | net->vlr->ops.tx_lu_rej = fake_vlr_tx_lu_rej; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1216 | net->vlr->ops.tx_cm_serv_acc = msc_vlr_tx_cm_serv_acc; |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 1217 | net->vlr->ops.tx_cm_serv_rej = fake_vlr_tx_cm_serv_rej; |
| 1218 | net->vlr->ops.tx_auth_req = fake_vlr_tx_auth_req; |
| 1219 | net->vlr->ops.tx_auth_rej = fake_vlr_tx_auth_rej; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1220 | net->vlr->ops.set_ciph_mode = msc_a_vlr_set_cipher_mode; |
| 1221 | |
| 1222 | /* Allocate fake SCCP Ran Instances */ |
| 1223 | net->a.sri = talloc_zero(net, struct sccp_ran_inst); |
| 1224 | *net->a.sri = (struct sccp_ran_inst){ |
| 1225 | .ran = &test_ran_infra[OSMO_RAT_GERAN_A], |
| 1226 | }; |
| 1227 | INIT_LLIST_HEAD(&net->a.sri->ran_peers); |
| 1228 | INIT_LLIST_HEAD(&net->a.sri->ran_conns); |
| 1229 | |
| 1230 | net->iu.sri = talloc_zero(net, struct sccp_ran_inst); |
| 1231 | *net->iu.sri = (struct sccp_ran_inst){ |
| 1232 | .ran = &test_ran_infra[OSMO_RAT_UTRAN_IU], |
| 1233 | }; |
| 1234 | INIT_LLIST_HEAD(&net->iu.sri->ran_peers); |
| 1235 | INIT_LLIST_HEAD(&net->iu.sri->ran_conns); |
| 1236 | |
| 1237 | net->mgw.tdefs = g_mgw_tdefs; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1238 | net->mgw.tdefs = g_mgw_tdefs; |
Pau Espin Pedrol | 9e3bab9 | 2023-06-13 19:57:57 +0200 | [diff] [blame] | 1239 | net->mgw.conf = mgcp_client_conf_alloc(net); |
Pau Espin Pedrol | b44cf2d | 2022-10-17 18:09:15 +0200 | [diff] [blame] | 1240 | net->mgw.mgw_pool = mgcp_client_pool_alloc(net); |
Pau Espin Pedrol | 9e3bab9 | 2023-06-13 19:57:57 +0200 | [diff] [blame] | 1241 | client = mgcp_client_init(net, net->mgw.conf); |
Pau Espin Pedrol | b44cf2d | 2022-10-17 18:09:15 +0200 | [diff] [blame] | 1242 | mgcp_client_pool_register_single(net->mgw.mgw_pool, client); |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 1243 | return net; |
| 1244 | } |
| 1245 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1246 | int main(int argc, char **argv) |
| 1247 | { |
| 1248 | handle_options(argc, argv); |
| 1249 | |
Neels Hofmeyr | e4f7e71 | 2019-03-24 21:07:33 +0100 | [diff] [blame] | 1250 | osmo_fsm_term_safely(true); |
| 1251 | |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 1252 | msc_vlr_tests_ctx = talloc_named_const(NULL, 0, "msc_vlr_tests_ctx"); |
| 1253 | msgb_ctx = msgb_talloc_ctx_init(msc_vlr_tests_ctx, 0); |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 1254 | osmo_init_logging2(msc_vlr_tests_ctx, &info); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1255 | |
| 1256 | _log_lines = cmdline_opts.verbose; |
| 1257 | |
| 1258 | OSMO_ASSERT(osmo_stderr_target); |
| 1259 | log_set_use_color(osmo_stderr_target, 0); |
| 1260 | log_set_print_timestamp(osmo_stderr_target, 0); |
Pau Espin Pedrol | cad22fd | 2021-02-19 13:37:00 +0100 | [diff] [blame] | 1261 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1262 | log_set_print_category(osmo_stderr_target, 1); |
Pau Espin Pedrol | 8d02d99 | 2021-02-19 13:36:47 +0100 | [diff] [blame] | 1263 | log_set_print_category_hex(osmo_stderr_target, 0); |
Max | 4813152 | 2019-01-16 12:47:39 +0100 | [diff] [blame] | 1264 | log_set_category_filter(osmo_stderr_target, DLSMS, 1, LOGL_DEBUG); |
Philipp Maier | ce1f973 | 2021-09-14 11:18:46 +0200 | [diff] [blame] | 1265 | log_set_category_filter(osmo_stderr_target, DLMGCP, 0, LOGL_NOTICE); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1266 | |
Neels Hofmeyr | 39cb0dd | 2018-12-18 02:30:18 +0100 | [diff] [blame] | 1267 | if (cmdline_opts.verbose) { |
Neels Hofmeyr | 39cb0dd | 2018-12-18 02:30:18 +0100 | [diff] [blame] | 1268 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME); |
| 1269 | log_set_print_filename_pos(osmo_stderr_target, LOG_FILENAME_POS_LINE_END); |
| 1270 | log_set_use_color(osmo_stderr_target, 1); |
| 1271 | log_set_print_level(osmo_stderr_target, 1); |
| 1272 | } |
Neels Hofmeyr | 3f5b780 | 2017-12-15 03:49:55 +0100 | [diff] [blame] | 1273 | |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 1274 | net = test_net(msc_vlr_tests_ctx); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1275 | |
| 1276 | osmo_fsm_log_addr(false); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1277 | osmo_fsm_log_timeouts(cmdline_opts.verbose); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1278 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1279 | call_leg_init(net); |
| 1280 | |
| 1281 | OSMO_ASSERT(osmo_fsm_register(&dummy_msc_i_fsm) == 0); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1282 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1283 | clear_vlr(); |
| 1284 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1285 | if (optind >= argc) |
| 1286 | run_tests(-1); |
| 1287 | else { |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1288 | int arg; |
| 1289 | long int nr; |
| 1290 | for (arg = optind; arg < argc; arg++) { |
Neels Hofmeyr | 9c848b5 | 2017-11-22 01:59:36 +0100 | [diff] [blame] | 1291 | errno = 0; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1292 | nr = strtol(argv[arg], NULL, 10); |
| 1293 | if (errno) { |
| 1294 | fprintf(stderr, "Invalid argument: %s\n", |
| 1295 | argv[arg]); |
| 1296 | exit(1); |
| 1297 | } |
| 1298 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1299 | run_tests(nr); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | printf("Done\n"); |
| 1304 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1305 | return 0; |
| 1306 | } |