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