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