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> |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 33 | #include <osmocom/gsupclient/gsup_client.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 | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 38 | #include <osmocom/msc/a_iface_bssap.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 39 | |
| 40 | #if BUILD_IU |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 41 | #include <osmocom/msc/iucs_ranap.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 42 | #include <osmocom/ranap/iu_client.h> |
| 43 | #else |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 44 | #include <osmocom/msc/iu_dummy.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 45 | #endif |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 46 | |
| 47 | #include "msc_vlr_tests.h" |
| 48 | |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 49 | void *msc_vlr_tests_ctx = NULL; |
| 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 | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 78 | uint32_t cc_to_mncc_tx_expected_msg_type = 0; |
| 79 | const char *cc_to_mncc_tx_expected_imsi = NULL; |
| 80 | bool cc_to_mncc_tx_confirmed = false; |
| 81 | uint32_t cc_to_mncc_tx_got_callref = 0; |
| 82 | |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 83 | extern int gsm0407_pdisc_ctr_bin(uint8_t pdisc); |
| 84 | |
| 85 | /* static state variables for the L3 send sequence numbers */ |
| 86 | static uint8_t n_sd[4]; |
| 87 | |
| 88 | /* patch a correct send sequence number into the given message */ |
| 89 | static void patch_l3_seq_nr(struct msgb *msg) |
| 90 | { |
| 91 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 92 | uint8_t pdisc = gsm48_hdr_pdisc(gh); |
| 93 | uint8_t *msg_type_oct = &msg->l3h[1]; |
| 94 | int bin = gsm0407_pdisc_ctr_bin(pdisc); |
| 95 | |
| 96 | if (bin >= 0 && bin < ARRAY_SIZE(n_sd)) { |
| 97 | /* patch in n_sd into the msg_type octet */ |
| 98 | *msg_type_oct = (*msg_type_oct & 0x3f) | ((n_sd[bin] & 0x3) << 6); |
| 99 | //fprintf(stderr, "pdisc=0x%02x bin=%d, patched n_sd=%u\n\n", pdisc, bin, n_sd[bin] & 3); |
| 100 | /* increment N(SD) */ |
| 101 | n_sd[bin] = (n_sd[bin] + 1) % 4; |
| 102 | } else { |
| 103 | //fprintf(stderr, "pdisc=0x%02x NO SEQ\n\n", pdisc); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* reset L3 sequence numbers (e.g. new RR connection) */ |
| 108 | static void reset_l3_seq_nr() |
| 109 | { |
| 110 | memset(n_sd, 0, sizeof(n_sd)); |
| 111 | } |
| 112 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 113 | struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex) |
| 114 | { |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 115 | struct msgb *msg = msgb_alloc_headroom(size, 4, label); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 116 | unsigned char *rc; |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 117 | msg->l2h = msg->data; |
| 118 | rc = msgb_put(msg, osmo_hexparse(hex, msg->data, msgb_tailroom(msg))); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 119 | OSMO_ASSERT(rc == msg->l2h); |
| 120 | return msg; |
| 121 | } |
| 122 | |
Max | d8d1a9e | 2018-02-06 15:50:20 +0100 | [diff] [blame] | 123 | static const char *gh_type_name(struct gsm48_hdr *gh) |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 124 | { |
| 125 | return gsm48_pdisc_msgtype_name(gsm48_hdr_pdisc(gh), |
| 126 | gsm48_hdr_msg_type(gh)); |
| 127 | } |
| 128 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 129 | void dtap_expect_tx(const char *hex) |
| 130 | { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 131 | /* Has the previously expected dtap been received? */ |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 132 | OSMO_ASSERT(!dtap_tx_expected); |
| 133 | if (!hex) |
| 134 | return; |
| 135 | dtap_tx_expected = msgb_from_hex("dtap_tx_expected", 1024, hex); |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 136 | /* Mask the sequence number out */ |
| 137 | if (msgb_length(dtap_tx_expected) >= 2) |
| 138 | dtap_tx_expected->data[1] &= 0x3f; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 139 | dtap_tx_confirmed = false; |
| 140 | } |
| 141 | |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 142 | int vlr_gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 143 | |
| 144 | void gsup_rx(const char *rx_hex, const char *expect_tx_hex) |
| 145 | { |
| 146 | int rc; |
| 147 | struct msgb *msg; |
| 148 | const char *label; |
| 149 | |
| 150 | gsup_expect_tx(expect_tx_hex); |
| 151 | |
| 152 | msg = msgb_from_hex("gsup", 1024, rx_hex); |
| 153 | label = osmo_gsup_message_type_name(msg->l2h[0]); |
| 154 | fprintf(stderr, "<-- GSUP rx %s: %s\n", label, |
| 155 | osmo_hexdump_nospc(msgb_l2(msg), msgb_l2len(msg))); |
Neels Hofmeyr | 834f94a | 2017-09-28 03:07:16 +0200 | [diff] [blame] | 156 | /* GSUP read cb takes ownership of msgb */ |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 157 | rc = vlr_gsupc_read_cb(net->vlr->gsup_client, msg); |
| 158 | fprintf(stderr, "<-- GSUP rx %s: vlr_gsupc_read_cb() returns %d\n", |
| 159 | label, rc); |
| 160 | if (expect_tx_hex) |
| 161 | OSMO_ASSERT(gsup_tx_confirmed); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 164 | bool conn_exists(const struct ran_conn *conn) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 165 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 166 | struct ran_conn *c; |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 167 | |
| 168 | if (!conn) |
| 169 | return false; |
| 170 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 171 | llist_for_each_entry(c, &net->ran_conns, entry) { |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 172 | if (c == conn) |
| 173 | return true; |
| 174 | } |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 175 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 176 | return false; |
| 177 | } |
| 178 | |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 179 | /* Simplified version of the cm_service_request_concludes() */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 180 | void conn_conclude_cm_service_req(struct ran_conn *conn, |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 181 | enum osmo_rat_type via_ran) |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 182 | { |
| 183 | btw("Concluding CM Service Request"); |
| 184 | |
| 185 | OSMO_ASSERT(conn); |
| 186 | OSMO_ASSERT(conn->received_cm_service_request); |
| 187 | |
| 188 | conn->received_cm_service_request = false; |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 189 | ran_conn_put(conn, RAN_CONN_USE_CM_SERVICE); |
Vadim Yanitskiy | 2760585 | 2018-06-15 23:57:30 +0700 | [diff] [blame] | 190 | |
| 191 | ASSERT_RELEASE_CLEAR(via_ran); |
| 192 | } |
| 193 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 194 | enum osmo_rat_type rx_from_ran = OSMO_RAT_GERAN_A; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 195 | |
Harald Welte | 977b548 | 2019-02-18 12:23:43 +0100 | [diff] [blame] | 196 | /* SCCP user stub to make a_iface_tx_bssap() happy during test case execution */ |
| 197 | struct osmo_sccp_user { |
| 198 | uint8_t foo; |
| 199 | }; |
| 200 | static struct osmo_sccp_user g_scu; |
| 201 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 202 | struct ran_conn *conn_new(void) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 203 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 204 | struct ran_conn *conn; |
| 205 | conn = ran_conn_alloc(net, rx_from_ran, 23); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 206 | if (conn->via_ran == OSMO_RAT_UTRAN_IU) { |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 207 | struct ranap_ue_conn_ctx *ue_ctx = talloc_zero(conn, struct ranap_ue_conn_ctx); |
| 208 | *ue_ctx = (struct ranap_ue_conn_ctx){ |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 209 | .conn_id = 42, |
| 210 | }; |
| 211 | conn->iu.ue_ctx = ue_ctx; |
Harald Welte | 977b548 | 2019-02-18 12:23:43 +0100 | [diff] [blame] | 212 | } else { |
| 213 | conn->a.scu = &g_scu; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 214 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 215 | return conn; |
| 216 | } |
| 217 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 218 | struct ran_conn *g_conn = NULL; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 219 | |
| 220 | void rx_from_ms(struct msgb *msg) |
| 221 | { |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 222 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 223 | |
| 224 | log("MSC <--%s-- MS: %s", |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 225 | osmo_rat_type_name(rx_from_ran), |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 226 | gh_type_name(gh)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 227 | |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 228 | if (!conn_exists(g_conn)) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 229 | g_conn = NULL; |
| 230 | |
| 231 | if (!g_conn) { |
| 232 | log("new conn"); |
| 233 | g_conn = conn_new(); |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 234 | reset_l3_seq_nr(); |
| 235 | patch_l3_seq_nr(msg); |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 236 | ran_conn_compl_l3(g_conn, msg, 23); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 237 | } else { |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 238 | patch_l3_seq_nr(msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 239 | if ((gsm48_hdr_pdisc(gh) == GSM48_PDISC_RR) |
| 240 | && (gsm48_hdr_msg_type(gh) == GSM48_MT_RR_CIPH_M_COMPL)) |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 241 | ran_conn_cipher_mode_compl(g_conn, msg, 0); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 242 | else |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 243 | ran_conn_dtap(g_conn, msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 246 | if (!conn_exists(g_conn)) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 247 | g_conn = NULL; |
| 248 | } |
| 249 | |
| 250 | void ms_sends_msg(const char *hex) |
| 251 | { |
| 252 | struct msgb *msg; |
| 253 | |
| 254 | msg = msgb_from_hex("ms_sends_msg", 1024, hex); |
| 255 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
| 256 | rx_from_ms(msg); |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 257 | msgb_free(msg); |
| 258 | } |
| 259 | |
| 260 | void bss_sends_bssap_mgmt(const char *hex) |
| 261 | { |
| 262 | struct msgb *msg; |
| 263 | struct bssmap_header *bh; |
| 264 | struct a_conn_info a_conn_info; |
| 265 | |
| 266 | msg = msgb_from_hex("bss_sends_bssap_mgmt", 1024, hex); |
| 267 | msg->l3h = msg->data; |
| 268 | |
| 269 | msg->l2h = msgb_push(msg, sizeof(*bh)); |
| 270 | bh = (void*)msg->l2h; |
| 271 | bh->type = BSSAP_MSG_BSS_MANAGEMENT; |
| 272 | bh->length = msgb_l3len(msg); |
| 273 | |
Max | ba8a007 | 2018-10-25 17:58:43 +0200 | [diff] [blame] | 274 | if (!conn_exists(g_conn)) |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 275 | g_conn = NULL; |
| 276 | |
| 277 | OSMO_ASSERT(g_conn); |
| 278 | a_conn_info.network = net; |
| 279 | a_conn_info.conn_id = g_conn->a.conn_id; |
| 280 | |
| 281 | a_sccp_rx_dt((struct osmo_sccp_user*)0x1, &a_conn_info, msg); |
| 282 | msgb_free(msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Max | d8d1a9e | 2018-02-06 15:50:20 +0100 | [diff] [blame] | 285 | 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] | 286 | { |
| 287 | int rc; |
| 288 | struct msgb *msg; |
| 289 | struct gsm48_hdr *gh; |
| 290 | |
| 291 | msg = msgb_alloc(1024, "ms_sends_msg_fake"); |
| 292 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
| 293 | |
| 294 | gh = (struct gsm48_hdr*)msgb_put(msg, sizeof(*gh)); |
| 295 | gh->proto_discr = pdisc; |
| 296 | gh->msg_type = msg_type; |
| 297 | /* some amount of data, whatever */ |
| 298 | msgb_put(msg, 123); |
| 299 | |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 300 | patch_l3_seq_nr(msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 301 | rc = gsm0408_dispatch(g_conn, msg); |
| 302 | |
| 303 | talloc_free(msg); |
| 304 | return rc; |
| 305 | } |
| 306 | |
Max | 6817190 | 2018-02-06 17:55:19 +0100 | [diff] [blame] | 307 | static inline void ms_msg_log_err(uint8_t val, uint8_t msgtype) |
| 308 | { |
| 309 | int rc = ms_sends_msg_fake(val, msgtype); |
| 310 | if (rc != -EACCES) |
| 311 | log("Unexpected return value %u != %u for %s/%s", |
| 312 | -rc, -EACCES, gsm48_pdisc_name(val), gsm48_cc_msg_name(msgtype)); |
| 313 | } |
| 314 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 315 | void thwart_rx_non_initial_requests() |
| 316 | { |
| 317 | log("requests shall be thwarted"); |
Max | 6817190 | 2018-02-06 17:55:19 +0100 | [diff] [blame] | 318 | |
| 319 | ms_msg_log_err(GSM48_PDISC_CC, GSM48_MT_CC_SETUP); |
| 320 | ms_msg_log_err(GSM48_PDISC_MM, 0x33); /* nonexistent */ |
| 321 | ms_msg_log_err(GSM48_PDISC_RR, GSM48_MT_RR_SYSINFO_1); |
| 322 | ms_msg_log_err(GSM48_PDISC_SMS, GSM411_MT_CP_DATA); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void send_sms(struct vlr_subscr *receiver, |
| 326 | struct vlr_subscr *sender, |
| 327 | char *str) |
| 328 | { |
Harald Welte | 39b5548 | 2018-04-09 19:19:33 +0200 | [diff] [blame] | 329 | struct gsm_sms *sms = sms_from_text(receiver, sender->msisdn, 0, str); |
Vadim Yanitskiy | 24e025e | 2018-11-22 15:42:39 +0700 | [diff] [blame] | 330 | gsm411_send_sms(net, receiver, sms); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | unsigned char next_rand_byte = 0; |
Max | 753c15d | 2017-12-21 14:50:44 +0100 | [diff] [blame] | 334 | /* override, requires '-Wl,--wrap=osmo_get_rand_id' */ |
| 335 | int __real_osmo_get_rand_id(uint8_t *buf, size_t num); |
| 336 | int __wrap_osmo_get_rand_id(uint8_t *buf, size_t num) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 337 | { |
Max | 753c15d | 2017-12-21 14:50:44 +0100 | [diff] [blame] | 338 | size_t i; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 339 | for (i = 0; i < num; i++) |
| 340 | buf[i] = next_rand_byte++; |
| 341 | return 1; |
| 342 | } |
| 343 | |
| 344 | /* override, requires '-Wl,--wrap=gsm340_gen_scts' */ |
| 345 | void __real_gsm340_gen_scts(uint8_t *scts, time_t time); |
| 346 | void __wrap_gsm340_gen_scts(uint8_t *scts, time_t time) |
| 347 | { |
Neels Hofmeyr | 05230ea | 2017-08-22 18:06:42 +0200 | [diff] [blame] | 348 | /* Write fixed time bytes for deterministic test results */ |
| 349 | osmo_hexparse("07101000000000", scts, 7); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | const char *paging_expecting_imsi = NULL; |
| 353 | uint32_t paging_expecting_tmsi; |
| 354 | bool paging_sent; |
| 355 | bool paging_stopped; |
| 356 | |
| 357 | void paging_expect_imsi(const char *imsi) |
| 358 | { |
| 359 | paging_expecting_imsi = imsi; |
| 360 | paging_expecting_tmsi = GSM_RESERVED_TMSI; |
| 361 | } |
| 362 | |
| 363 | void paging_expect_tmsi(uint32_t tmsi) |
| 364 | { |
| 365 | paging_expecting_tmsi = tmsi; |
| 366 | paging_expecting_imsi = NULL; |
| 367 | } |
| 368 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 369 | static int _paging_sent(enum osmo_rat_type via_ran, const char *imsi, uint32_t tmsi, uint32_t lac) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 370 | { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 371 | log("%s sends out paging request to IMSI %s, TMSI 0x%08x, LAC %u", |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 372 | osmo_rat_type_name(via_ran), imsi, tmsi, lac); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 373 | OSMO_ASSERT(paging_expecting_imsi || (paging_expecting_tmsi != GSM_RESERVED_TMSI)); |
| 374 | if (paging_expecting_imsi) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 375 | VERBOSE_ASSERT(strcmp(paging_expecting_imsi, imsi), == 0, "%d"); |
| 376 | if (paging_expecting_tmsi != GSM_RESERVED_TMSI) { |
| 377 | VERBOSE_ASSERT(paging_expecting_tmsi, == tmsi, "0x%08x"); |
| 378 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 379 | paging_sent = true; |
| 380 | paging_stopped = false; |
| 381 | return 1; |
| 382 | } |
| 383 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 384 | /* override, requires '-Wl,--wrap=ranap_iu_page_cs' */ |
| 385 | int __real_ranap_iu_page_cs(const char *imsi, const uint32_t *tmsi, uint16_t lac); |
| 386 | int __wrap_ranap_iu_page_cs(const char *imsi, const uint32_t *tmsi, uint16_t lac) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 387 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 388 | return _paging_sent(OSMO_RAT_UTRAN_IU, imsi, tmsi ? *tmsi : GSM_RESERVED_TMSI, lac); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 391 | /* override, requires '-Wl,--wrap=a_iface_tx_paging' */ |
| 392 | int __real_a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac); |
| 393 | int __wrap_a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 394 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 395 | return _paging_sent(OSMO_RAT_GERAN_A, imsi, tmsi, lac); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* override, requires '-Wl,--wrap=msc_stop_paging' */ |
| 399 | void __real_msc_stop_paging(struct vlr_subscr *vsub); |
| 400 | void __wrap_msc_stop_paging(struct vlr_subscr *vsub) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 401 | { |
| 402 | paging_stopped = true; |
| 403 | } |
| 404 | |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 405 | |
| 406 | /* override, requires '-Wl,--wrap=osmo_sccp_tx_data_msg' */ |
| 407 | int __real_osmo_sccp_tx_data_msg(struct osmo_sccp_user *scu, uint32_t conn_id, |
| 408 | struct msgb *msg); |
| 409 | int __wrap_osmo_sccp_tx_data_msg(struct osmo_sccp_user *scu, uint32_t conn_id, |
| 410 | struct msgb *msg) |
| 411 | { |
| 412 | const char *proto_str; |
| 413 | const char *msg_str = gsm0808_bssmap_name(msg->l3h[2]); |
| 414 | switch (*msg->l3h) { |
| 415 | case BSSAP_MSG_BSS_MANAGEMENT: |
| 416 | proto_str = "BSSAP-BSS-MANAGEMENT"; |
| 417 | break; |
| 418 | case BSSAP_MSG_DTAP: |
| 419 | proto_str = "BSSAP-DTAP"; |
| 420 | break; |
| 421 | default: |
| 422 | proto_str = ""; |
| 423 | msg_str = ""; |
| 424 | break; |
| 425 | } |
| 426 | |
| 427 | log("BSC <--%s-- MSC: %s %s", proto_str, msg_str, msgb_hexdump(msg)); |
| 428 | msgb_free(msg); |
| 429 | return 0; |
| 430 | } |
| 431 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 432 | void clear_vlr() |
| 433 | { |
| 434 | struct vlr_subscr *vsub, *n; |
| 435 | llist_for_each_entry_safe(vsub, n, &net->vlr->subscribers, list) { |
| 436 | vlr_subscr_free(vsub); |
| 437 | } |
| 438 | |
| 439 | net->authentication_required = false; |
Harald Welte | 7b222aa | 2017-12-23 19:30:32 +0100 | [diff] [blame] | 440 | net->a5_encryption_mask = (1 << 0); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 441 | net->vlr->cfg.check_imei_rqd = false; |
| 442 | net->vlr->cfg.assign_tmsi = false; |
Neels Hofmeyr | 54a706c | 2017-07-18 15:39:27 +0200 | [diff] [blame] | 443 | net->vlr->cfg.retrieve_imeisv_early = false; |
| 444 | net->vlr->cfg.retrieve_imeisv_ciphered = false; |
Neels Hofmeyr | 7b1418e | 2017-10-29 02:12:16 +0100 | [diff] [blame] | 445 | net->vlr->cfg.auth_tuple_max_reuse_count = 0; |
| 446 | net->vlr->cfg.auth_reuse_old_sets_on_error = false; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 447 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 448 | rx_from_ran = OSMO_RAT_GERAN_A; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 449 | auth_request_sent = false; |
| 450 | auth_request_expect_rand = NULL; |
| 451 | auth_request_expect_autn = NULL; |
| 452 | |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 453 | cipher_mode_cmd_sent = false; |
| 454 | cipher_mode_cmd_sent_with_imeisv = false; |
| 455 | cipher_mode_expect_kc = NULL; |
| 456 | |
| 457 | security_mode_ctrl_sent = false; |
| 458 | security_mode_expect_ck = NULL; |
| 459 | security_mode_expect_ik = NULL; |
| 460 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 461 | next_rand_byte = 0; |
| 462 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 463 | iu_release_expected = false; |
| 464 | iu_release_sent = false; |
| 465 | bssap_clear_expected = false; |
| 466 | bssap_clear_sent = false; |
| 467 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 468 | osmo_gettimeofday_override = false; |
| 469 | } |
| 470 | |
| 471 | static struct log_info_cat test_categories[] = { |
| 472 | [DMSC] = { |
| 473 | .name = "DMSC", |
| 474 | .description = "Mobile Switching Center", |
| 475 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 476 | }, |
| 477 | [DRLL] = { |
| 478 | .name = "DRLL", |
| 479 | .description = "A-bis Radio Link Layer (RLL)", |
| 480 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 481 | }, |
| 482 | [DMM] = { |
| 483 | .name = "DMM", |
| 484 | .description = "Layer3 Mobility Management (MM)", |
| 485 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 486 | }, |
| 487 | [DRR] = { |
| 488 | .name = "DRR", |
| 489 | .description = "Layer3 Radio Resource (RR)", |
| 490 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 491 | }, |
| 492 | [DCC] = { |
| 493 | .name = "DCC", |
| 494 | .description = "Layer3 Call Control (CC)", |
Neels Hofmeyr | 12e17be | 2018-03-12 23:59:37 +0100 | [diff] [blame] | 495 | .enabled = 1, .loglevel = LOGL_DEBUG, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 496 | }, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 497 | [DVLR] = { |
| 498 | .name = "DVLR", |
| 499 | .description = "Visitor Location Register", |
| 500 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 501 | }, |
| 502 | [DREF] = { |
| 503 | .name = "DREF", |
| 504 | .description = "Reference Counting", |
| 505 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 506 | }, |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 507 | [DPAG] = { |
| 508 | .name = "DPAG", |
| 509 | .description = "Paging Subsystem", |
| 510 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 511 | }, |
| 512 | [DIUCS] = { |
| 513 | .name = "DIUCS", |
| 514 | .description = "Iu-CS Protocol", |
| 515 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 516 | }, |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 517 | [DMNCC] = { |
| 518 | .name = "DMNCC", |
| 519 | .description = "MNCC API for Call Control application", |
| 520 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 521 | }, |
Neels Hofmeyr | 46c06e2 | 2019-01-04 17:42:05 +0100 | [diff] [blame] | 522 | [DBSSAP] = { |
| 523 | .name = "DBSSAP", |
| 524 | .description = "BSSAP Protocol (A Interface)", |
| 525 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 526 | }, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 527 | }; |
| 528 | |
| 529 | static struct log_info info = { |
| 530 | .cat = test_categories, |
| 531 | .num_cat = ARRAY_SIZE(test_categories), |
| 532 | }; |
| 533 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 534 | int mncc_recv(struct gsm_network *net, struct msgb *msg) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 535 | { |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 536 | struct gsm_mncc *mncc = (void*)msg->data; |
| 537 | log("MSC --> MNCC: callref 0x%x: %s", mncc->callref, |
| 538 | get_mncc_name(mncc->msg_type)); |
| 539 | |
| 540 | OSMO_ASSERT(cc_to_mncc_tx_expected_msg_type); |
| 541 | if (cc_to_mncc_tx_expected_msg_type != mncc->msg_type) { |
| 542 | log("Mismatch! Expected MNCC msg type: %s", |
| 543 | get_mncc_name(cc_to_mncc_tx_expected_msg_type)); |
| 544 | abort(); |
| 545 | } |
| 546 | |
| 547 | if (strcmp(cc_to_mncc_tx_expected_imsi, mncc->imsi)) { |
| 548 | log("Mismatch! Expected MNCC msg IMSI: '%s', got '%s'", |
| 549 | cc_to_mncc_tx_expected_imsi, |
| 550 | mncc->imsi); |
| 551 | abort(); |
| 552 | } |
| 553 | |
| 554 | cc_to_mncc_tx_confirmed = true; |
| 555 | cc_to_mncc_tx_got_callref = mncc->callref; |
| 556 | cc_to_mncc_tx_expected_imsi = NULL; |
| 557 | cc_to_mncc_tx_expected_msg_type = 0; |
| 558 | talloc_free(msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 559 | return 0; |
| 560 | } |
| 561 | |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 562 | struct osmo_gsup_client * |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 563 | __real_osmo_gsup_client_create2(struct ipaccess_unit *ipa_dev, const char *ip_addr, |
| 564 | unsigned int tcp_port, osmo_gsup_client_read_cb_t read_cb, |
| 565 | struct osmo_oap_client_config *oap_config); |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 566 | struct osmo_gsup_client * |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 567 | __wrap_osmo_gsup_client_create2(struct ipaccess_unit *ipa_dev, const char *ip_addr, |
| 568 | unsigned int tcp_port, osmo_gsup_client_read_cb_t read_cb, |
| 569 | struct osmo_oap_client_config *oap_config) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 570 | { |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 571 | struct osmo_gsup_client *gsupc; |
| 572 | gsupc = talloc_zero(msc_vlr_tests_ctx, struct osmo_gsup_client); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 573 | OSMO_ASSERT(gsupc); |
| 574 | return gsupc; |
| 575 | } |
| 576 | |
| 577 | /* override, requires '-Wl,--wrap=gsup_client_send' */ |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 578 | int __real_osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg); |
| 579 | 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] | 580 | { |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 581 | uint8_t buf[512]; |
| 582 | int len; |
| 583 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 584 | fprintf(stderr, "GSUP --> HLR: %s: %s\n", |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 585 | 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] | 586 | |
| 587 | OSMO_ASSERT(gsup_tx_expected); |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 588 | OSMO_ASSERT(strlen(gsup_tx_expected) <= (sizeof(buf) * 2)); |
| 589 | |
| 590 | len = osmo_hexparse(gsup_tx_expected, buf, sizeof(buf)); |
| 591 | if (len < 1) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 592 | abort(); |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 593 | |
| 594 | if (!msgb_eq_data_print(msg, buf, len)) |
| 595 | abort(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 596 | |
| 597 | talloc_free(msg); |
| 598 | gsup_tx_confirmed = true; |
| 599 | gsup_tx_expected = NULL; |
| 600 | return 0; |
| 601 | } |
| 602 | |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 603 | static int _validate_dtap(struct msgb *msg, enum osmo_rat_type to_ran) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 604 | { |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 605 | btw("DTAP --%s--> MS: %s: %s", |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 606 | osmo_rat_type_name(to_ran), gh_type_name((void*)msg->data), |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 607 | osmo_hexdump_nospc(msg->data, msg->len)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 608 | |
| 609 | OSMO_ASSERT(dtap_tx_expected); |
Harald Welte | c200785 | 2018-02-03 21:08:26 +0100 | [diff] [blame] | 610 | |
| 611 | /* Mask the sequence number out before comparing */ |
| 612 | msg->data[1] &= 0x3f; |
Max | 34d306b | 2019-01-15 18:37:31 +0100 | [diff] [blame] | 613 | if (!msgb_eq_data_print(msg, dtap_tx_expected->data, dtap_tx_expected->len)) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 614 | abort(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 615 | |
| 616 | btw("DTAP matches expected message"); |
| 617 | |
| 618 | talloc_free(msg); |
| 619 | dtap_tx_confirmed = true; |
| 620 | talloc_free(dtap_tx_expected); |
| 621 | dtap_tx_expected = NULL; |
| 622 | return 0; |
| 623 | } |
| 624 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 625 | /* override, requires '-Wl,--wrap=ranap_iu_tx' */ |
| 626 | int __real_ranap_iu_tx(struct msgb *msg, uint8_t sapi); |
| 627 | int __wrap_ranap_iu_tx(struct msgb *msg, uint8_t sapi) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 628 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 629 | return _validate_dtap(msg, OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 630 | } |
| 631 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 632 | /* override, requires '-Wl,--wrap=ranap_iu_tx_release' */ |
| 633 | int __real_ranap_iu_tx_release(struct ranap_ue_conn_ctx *ctx, const struct RANAP_Cause *cause); |
| 634 | int __wrap_ranap_iu_tx_release(struct ranap_ue_conn_ctx *ctx, const struct RANAP_Cause *cause) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 635 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 636 | btw("Iu Release --%s--> MS", osmo_rat_type_name(OSMO_RAT_UTRAN_IU)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 637 | OSMO_ASSERT(iu_release_expected); |
| 638 | iu_release_expected = false; |
| 639 | iu_release_sent = true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | /* override, requires '-Wl,--wrap=iu_tx_common_id' */ |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 644 | int __real_ranap_iu_tx_common_id(struct ranap_ue_conn_ctx *ue_ctx, const char *imsi); |
| 645 | int __wrap_ranap_iu_tx_common_id(struct ranap_ue_conn_ctx *ue_ctx, const char *imsi) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 646 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 647 | btw("Iu Common ID --%s--> MS (IMSI=%s)", osmo_rat_type_name(OSMO_RAT_UTRAN_IU), imsi); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 651 | /* override, requires '-Wl,--wrap=a_iface_tx_dtap' */ |
| 652 | int __real_a_iface_tx_dtap(struct msgb *msg); |
| 653 | int __wrap_a_iface_tx_dtap(struct msgb *msg) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 654 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 655 | return _validate_dtap(msg, OSMO_RAT_GERAN_A); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 656 | } |
| 657 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 658 | /* override, requires '-Wl,--wrap=a_iface_tx_clear_cmd' */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 659 | int __real_a_iface_tx_clear_cmd(struct ran_conn *conn); |
| 660 | int __wrap_a_iface_tx_clear_cmd(struct ran_conn *conn) |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 661 | { |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 662 | btw("BSSAP Clear --%s--> MS", osmo_rat_type_name(OSMO_RAT_GERAN_A)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 663 | OSMO_ASSERT(bssap_clear_expected); |
| 664 | bssap_clear_expected = false; |
| 665 | bssap_clear_sent = true; |
| 666 | return 0; |
| 667 | } |
| 668 | |
Neels Hofmeyr | b16259f | 2018-12-20 02:57:56 +0100 | [diff] [blame] | 669 | /* override, requires '-Wl,--wrap=msc_mgcp_try_call_assignment' */ |
| 670 | int __real_msc_mgcp_try_call_assignment(struct gsm_trans *trans); |
| 671 | int __wrap_msc_mgcp_try_call_assignment(struct gsm_trans *trans) |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 672 | { |
| 673 | log("MS <--Call Assignment-- MSC: subscr=%s callref=0x%x", |
| 674 | vlr_subscr_name(trans->vsub), trans->callref); |
| 675 | return 0; |
| 676 | } |
| 677 | |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 678 | struct gsm_mncc *on_call_release_mncc_sends_to_cc_data = NULL; |
| 679 | |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 680 | /* override, requires '-Wl,--wrap=msc_mgcp_call_release' */ |
| 681 | void __real_msc_mgcp_call_release(struct gsm_trans *trans); |
| 682 | void __wrap_msc_mgcp_call_release(struct gsm_trans *trans) |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 683 | { |
| 684 | log("MS <--Call Release-- MSC: subscr=%s callref=0x%x", |
| 685 | vlr_subscr_name(trans->vsub), trans->callref); |
Neels Hofmeyr | cbcf89c | 2018-03-13 17:52:07 +0100 | [diff] [blame] | 686 | if (on_call_release_mncc_sends_to_cc_data) { |
| 687 | mncc_tx_to_cc(trans->net, on_call_release_mncc_sends_to_cc_data->msg_type, |
| 688 | on_call_release_mncc_sends_to_cc_data); |
| 689 | on_call_release_mncc_sends_to_cc_data = NULL; |
| 690 | } |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 691 | } |
| 692 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 693 | static int fake_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi) |
| 694 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 695 | struct ran_conn *conn = msc_conn_ref; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 696 | if (send_tmsi == GSM_RESERVED_TMSI) |
| 697 | btw("sending LU Accept for %s", vlr_subscr_name(conn->vsub)); |
| 698 | else |
| 699 | btw("sending LU Accept for %s, with TMSI 0x%08x", |
| 700 | vlr_subscr_name(conn->vsub), send_tmsi); |
| 701 | lu_result_sent |= RES_ACCEPT; |
| 702 | return 0; |
| 703 | } |
| 704 | |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 705 | 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] | 706 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 707 | struct ran_conn *conn = msc_conn_ref; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 708 | btw("sending LU Reject for %s, cause %u", vlr_subscr_name(conn->vsub), cause); |
| 709 | lu_result_sent |= RES_REJECT; |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int fake_vlr_tx_cm_serv_acc(void *msc_conn_ref) |
| 714 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 715 | struct ran_conn *conn = msc_conn_ref; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 716 | btw("sending CM Service Accept for %s", vlr_subscr_name(conn->vsub)); |
| 717 | cm_service_result_sent |= RES_ACCEPT; |
| 718 | return 0; |
| 719 | } |
| 720 | |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 721 | static int fake_vlr_tx_cm_serv_rej(void *msc_conn_ref, enum gsm48_reject_value cause) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 722 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 723 | struct ran_conn *conn = msc_conn_ref; |
Neels Hofmeyr | 1580959 | 2018-04-06 02:57:51 +0200 | [diff] [blame] | 724 | btw("sending CM Service Reject for %s, cause: %s", |
| 725 | vlr_subscr_name(conn->vsub), gsm48_reject_value_name(cause)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 726 | cm_service_result_sent |= RES_REJECT; |
| 727 | return 0; |
| 728 | } |
| 729 | |
Neels Hofmeyr | 8b6e536 | 2018-11-30 02:57:33 +0100 | [diff] [blame] | 730 | 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] | 731 | bool send_autn) |
| 732 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 733 | struct ran_conn *conn = msc_conn_ref; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 734 | char *hex; |
| 735 | bool ok = true; |
| 736 | btw("sending %s Auth Request for %s: tuple use_count=%d key_seq=%d auth_types=0x%x and...", |
| 737 | send_autn? "UMTS" : "GSM", vlr_subscr_name(conn->vsub), |
| 738 | at->use_count, at->key_seq, at->vec.auth_types); |
| 739 | |
| 740 | hex = osmo_hexdump_nospc((void*)&at->vec.rand, sizeof(at->vec.rand)); |
| 741 | btw("...rand=%s", hex); |
| 742 | if (!auth_request_expect_rand |
| 743 | || strcmp(hex, auth_request_expect_rand) != 0) { |
| 744 | ok = false; |
| 745 | log("FAILURE: expected rand=%s", |
| 746 | auth_request_expect_rand ? auth_request_expect_rand : "-"); |
| 747 | } |
| 748 | |
| 749 | if (send_autn) { |
| 750 | hex = osmo_hexdump_nospc((void*)&at->vec.autn, sizeof(at->vec.autn)); |
| 751 | btw("...autn=%s", hex); |
| 752 | if (!auth_request_expect_autn |
| 753 | || strcmp(hex, auth_request_expect_autn) != 0) { |
| 754 | ok = false; |
| 755 | log("FAILURE: expected autn=%s", |
| 756 | auth_request_expect_autn ? auth_request_expect_autn : "-"); |
| 757 | } |
| 758 | } else if (auth_request_expect_autn) { |
| 759 | ok = false; |
| 760 | log("FAILURE: no AUTN sent, expected AUTN = %s", |
| 761 | auth_request_expect_autn); |
| 762 | } |
| 763 | |
| 764 | if (send_autn) |
| 765 | btw("...expecting res=%s", |
| 766 | osmo_hexdump_nospc((void*)&at->vec.res, at->vec.res_len)); |
| 767 | else |
| 768 | btw("...expecting sres=%s", |
| 769 | osmo_hexdump_nospc((void*)&at->vec.sres, sizeof(at->vec.sres))); |
| 770 | |
| 771 | auth_request_sent = ok; |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static int fake_vlr_tx_auth_rej(void *msc_conn_ref) |
| 776 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 777 | struct ran_conn *conn = msc_conn_ref; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 778 | btw("sending Auth Reject for %s", vlr_subscr_name(conn->vsub)); |
| 779 | return 0; |
| 780 | } |
| 781 | |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 782 | /* override, requires '-Wl,--wrap=a_iface_tx_cipher_mode' */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 783 | int __real_a_iface_tx_cipher_mode(const struct ran_conn *conn, |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 784 | struct gsm0808_encrypt_info *ei, int include_imeisv); |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 785 | int __wrap_a_iface_tx_cipher_mode(const struct ran_conn *conn, |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 786 | struct gsm0808_encrypt_info *ei, int include_imeisv) |
| 787 | { |
| 788 | int i; |
| 789 | btw("sending Ciphering Mode Command for %s: include_imeisv=%d", |
| 790 | vlr_subscr_name(conn->vsub), include_imeisv); |
| 791 | for (i = 0; i < ei->perm_algo_len; i++) |
Neels Hofmeyr | d28ea6c | 2018-09-17 00:54:52 +0200 | [diff] [blame] | 792 | btw("...perm algo: A5/%u", ei->perm_algo[i] - 1); |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 793 | OSMO_ASSERT(ei->key_len <= sizeof(ei->key)); |
| 794 | btw("...key: %s", osmo_hexdump_nospc(ei->key, ei->key_len)); |
| 795 | cipher_mode_cmd_sent = true; |
| 796 | cipher_mode_cmd_sent_with_imeisv = include_imeisv; |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 797 | |
| 798 | if (!cipher_mode_expect_kc |
| 799 | || strcmp(cipher_mode_expect_kc, osmo_hexdump_nospc(ei->key, ei->key_len))) { |
| 800 | log("FAILURE: expected kc=%s", cipher_mode_expect_kc ? : "NULL"); |
| 801 | OSMO_ASSERT(false); |
| 802 | } |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | /* override, requires '-Wl,--wrap=ranap_iu_tx_sec_mode_cmd' */ |
| 807 | int __real_ranap_iu_tx_sec_mode_cmd(struct ranap_ue_conn_ctx *uectx, struct osmo_auth_vector *vec, |
| 808 | int send_ck, int new_key); |
| 809 | int __wrap_ranap_iu_tx_sec_mode_cmd(struct ranap_ue_conn_ctx *uectx, struct osmo_auth_vector *vec, |
| 810 | int send_ck, int new_key) |
| 811 | { |
| 812 | btw("sending SecurityModeControl for UE ctx %u send_ck=%d new_key=%d", |
| 813 | uectx->conn_id, send_ck, new_key); |
| 814 | btw("...ik=%s", osmo_hexdump_nospc(vec->ik, sizeof(vec->ik))); |
| 815 | if (send_ck) |
| 816 | btw("...ck=%s", osmo_hexdump_nospc(vec->ck, sizeof(vec->ck))); |
Neels Hofmeyr | dbabfd3 | 2018-03-10 02:06:47 +0100 | [diff] [blame] | 817 | security_mode_ctrl_sent = true; |
| 818 | if (!security_mode_expect_ik |
| 819 | || strcmp(security_mode_expect_ik, osmo_hexdump_nospc(vec->ik, sizeof(vec->ik)))) { |
| 820 | log("FAILURE: expected ik=%s", security_mode_expect_ik ? : "NULL"); |
| 821 | OSMO_ASSERT(false); |
| 822 | } |
| 823 | if (((!!send_ck) != (!!security_mode_expect_ck)) |
| 824 | || (security_mode_expect_ck |
| 825 | && strcmp(security_mode_expect_ck, osmo_hexdump_nospc(vec->ck, sizeof(vec->ck))))) { |
| 826 | log("FAILURE: expected ck=%s", security_mode_expect_ck ? : "NULL"); |
| 827 | OSMO_ASSERT(false); |
| 828 | } |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | extern int msc_vlr_set_ciph_mode(void *msc_conn_ref, bool umts_aka, bool retrieve_imeisv); |
| 833 | |
Harald Welte | 71c51df | 2017-12-23 18:51:48 +0100 | [diff] [blame] | 834 | static int fake_vlr_tx_ciph_mode_cmd(void *msc_conn_ref, bool umts_aka, bool retrieve_imeisv) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 835 | { |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 836 | int rc; |
| 837 | #ifndef BUILD_IU |
| 838 | /* If we built without support for IU, fake the IU part here. The root cause is that we don't |
| 839 | * have differing sets of expected outputs for --enable-iu and --disable-iu. */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 840 | struct ran_conn *conn = msc_conn_ref; |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 841 | if (conn->via_ran == OSMO_RAT_UTRAN_IU) { |
Neels Hofmeyr | da21a52 | 2018-03-02 01:50:09 +0100 | [diff] [blame] | 842 | DEBUGP(DMM, "-> SECURITY MODE CONTROL %s\n", vlr_subscr_name(conn->vsub)); |
| 843 | rc = __wrap_ranap_iu_tx_sec_mode_cmd(conn->iu.ue_ctx, &conn->vsub->last_tuple->vec, |
| 844 | 0, 1); |
| 845 | } else |
| 846 | #endif |
| 847 | rc = msc_vlr_set_ciph_mode(msc_conn_ref, umts_aka, retrieve_imeisv); |
| 848 | if (rc) |
| 849 | btw("ERROR sending ciphering mode command: rc=%d", rc); |
| 850 | return rc; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 851 | } |
| 852 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 853 | void ms_sends_security_mode_complete() |
| 854 | { |
| 855 | OSMO_ASSERT(g_conn); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 856 | OSMO_ASSERT(g_conn->via_ran == OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 857 | OSMO_ASSERT(g_conn->iu.ue_ctx); |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 858 | ran_conn_rx_sec_mode_compl(g_conn); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 859 | } |
| 860 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 861 | void bss_sends_clear_complete() |
| 862 | { |
| 863 | btw("BSS sends BSSMAP Clear Complete"); |
| 864 | OSMO_ASSERT(g_conn); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 865 | OSMO_ASSERT(g_conn->via_ran == OSMO_RAT_GERAN_A); |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 866 | ran_conn_rx_bssmap_clear_complete(g_conn); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | void rnc_sends_release_complete() |
| 870 | { |
| 871 | btw("RNC sends Iu Release Complete"); |
| 872 | OSMO_ASSERT(g_conn); |
Neels Hofmeyr | 7814a83 | 2018-12-26 00:40:18 +0100 | [diff] [blame] | 873 | OSMO_ASSERT(g_conn->via_ran == OSMO_RAT_UTRAN_IU); |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 874 | ran_conn_rx_iu_release_complete(g_conn); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 875 | } |
| 876 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 877 | const struct timeval fake_time_start_time = { 123, 456 }; |
| 878 | |
| 879 | void fake_time_start() |
| 880 | { |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 881 | struct timespec *clock_override; |
| 882 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 883 | osmo_gettimeofday_override_time = fake_time_start_time; |
| 884 | osmo_gettimeofday_override = true; |
Stefan Sperling | defc3c8 | 2018-05-15 14:48:04 +0200 | [diff] [blame] | 885 | clock_override = osmo_clock_override_gettimespec(CLOCK_MONOTONIC); |
| 886 | OSMO_ASSERT(clock_override); |
| 887 | clock_override->tv_sec = fake_time_start_time.tv_sec; |
| 888 | clock_override->tv_nsec = fake_time_start_time.tv_usec * 1000; |
| 889 | osmo_clock_override_enable(CLOCK_MONOTONIC, true); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 890 | fake_time_passes(0, 0); |
| 891 | } |
| 892 | |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 893 | static void check_talloc(void *msgb_ctx, void *msc_vlr_tests_ctx) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 894 | { |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 895 | /* Verifying that the msgb context is empty */ |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 896 | talloc_report_full(msgb_ctx, stderr); |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 897 | /* Expecting these to stick around in msc_vlr_tests_ctx: |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 898 | * talloc_total_blocks(tall_bsc_ctx) == 13 |
| 899 | * full talloc report on 'msc_vlr_tests_ctx' (total 4638 bytes in 13 blocks) |
| 900 | * struct osmo_gsup_client contains 256 bytes in 1 blocks (ref 0) 0x61300000dd20 |
| 901 | * struct gsm_network contains 2983 bytes in 5 blocks (ref 0) 0x61400000fea0 |
| 902 | * struct vlr_instance contains 320 bytes in 2 blocks (ref 0) 0x61300000dee0 |
| 903 | * struct ipaccess_unit contains 64 bytes in 1 blocks (ref 0) 0x60e0000244c0 |
| 904 | * no_gsup_server contains 15 bytes in 1 blocks (ref 0) 0x60b00000af40 |
| 905 | * rate_ctr.c:234 contains 2352 bytes in 1 blocks (ref 0) 0x61e00000f0e0 |
| 906 | * logging contains 1399 bytes in 5 blocks (ref 0) 0x60b00000aff0 |
| 907 | * struct log_target contains 238 bytes in 2 blocks (ref 0) 0x61200000bf20 |
| 908 | * struct log_category contains 70 bytes in 1 blocks (ref 0) 0x60f00000efb0 |
| 909 | * struct log_info contains 1160 bytes in 2 blocks (ref 0) 0x60d00000cfd0 |
| 910 | * struct log_info_cat contains 1120 bytes in 1 blocks (ref 0) 0x61a00001f2e0 |
| 911 | * msgb contains 0 bytes in 1 blocks (ref 0) 0x60800000bf80 |
| 912 | * (That's 13 counting the root ctx) |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 913 | */ |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 914 | fprintf(stderr, "talloc_total_blocks(tall_bsc_ctx) == %zu\n", |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 915 | talloc_total_blocks(msc_vlr_tests_ctx)); |
Stefan Sperling | afa030d | 2018-12-06 12:06:59 +0100 | [diff] [blame] | 916 | if (talloc_total_blocks(msc_vlr_tests_ctx) != 13) |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 917 | talloc_report_full(msc_vlr_tests_ctx, stderr); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 918 | fprintf(stderr, "\n"); |
| 919 | } |
| 920 | |
| 921 | static struct { |
| 922 | bool verbose; |
| 923 | int run_test_nr; |
| 924 | } cmdline_opts = { |
| 925 | .verbose = false, |
| 926 | .run_test_nr = -1, |
| 927 | }; |
| 928 | |
| 929 | static void print_help(const char *program) |
| 930 | { |
| 931 | printf("Usage:\n" |
| 932 | " %s [-v] [N [N...]]\n" |
| 933 | "Options:\n" |
| 934 | " -h --help show this text.\n" |
| 935 | " -v --verbose print source file and line numbers\n" |
| 936 | " N run only the Nth test (first test is N=1)\n", |
| 937 | program |
| 938 | ); |
| 939 | } |
| 940 | |
| 941 | static void handle_options(int argc, char **argv) |
| 942 | { |
| 943 | while (1) { |
| 944 | int option_index = 0, c; |
| 945 | static struct option long_options[] = { |
| 946 | {"help", 0, 0, 'h'}, |
| 947 | {"verbose", 1, 0, 'v'}, |
| 948 | {0, 0, 0, 0} |
| 949 | }; |
| 950 | |
| 951 | c = getopt_long(argc, argv, "hv", |
| 952 | long_options, &option_index); |
| 953 | if (c == -1) |
| 954 | break; |
| 955 | |
| 956 | switch (c) { |
| 957 | case 'h': |
| 958 | print_help(argv[0]); |
| 959 | exit(0); |
| 960 | case 'v': |
| 961 | cmdline_opts.verbose = true; |
| 962 | break; |
| 963 | default: |
| 964 | /* catch unknown options *as well as* missing arguments. */ |
| 965 | fprintf(stderr, "Error in command line options. Exiting.\n"); |
| 966 | exit(-1); |
| 967 | break; |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | void *msgb_ctx = NULL; |
| 973 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 974 | static void run_tests(int nr) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 975 | { |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 976 | int test_nr; |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 977 | |
| 978 | check_talloc(msgb_ctx, msc_vlr_tests_ctx); |
| 979 | |
Max | 5e2e9bd | 2018-02-06 19:31:08 +0100 | [diff] [blame] | 980 | nr--; /* arg's first test is 1, in here it's 0 */ |
| 981 | for (test_nr = 0; msc_vlr_tests[test_nr]; test_nr++) { |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 982 | if (nr >= 0 && test_nr != nr) |
| 983 | continue; |
| 984 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 985 | if (cmdline_opts.verbose) |
| 986 | fprintf(stderr, "(test nr %d)\n", test_nr + 1); |
| 987 | |
| 988 | msc_vlr_tests[test_nr](); |
| 989 | |
| 990 | if (cmdline_opts.verbose) |
| 991 | fprintf(stderr, "(test nr %d)\n", test_nr + 1); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 992 | |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 993 | check_talloc(msgb_ctx, msc_vlr_tests_ctx); |
Max | 29ce08a | 2018-02-06 18:46:57 +0100 | [diff] [blame] | 994 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 995 | } |
| 996 | |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 997 | struct gsm_network *test_net(void *ctx) |
| 998 | { |
Neels Hofmeyr | 7f48420 | 2018-02-27 12:59:45 +0100 | [diff] [blame] | 999 | struct gsm_network *net = gsm_network_init(ctx, mncc_recv); |
Max | 5e60de6 | 2018-02-07 12:56:09 +0100 | [diff] [blame] | 1000 | |
| 1001 | net->gsup_server_addr_str = talloc_strdup(net, "no_gsup_server"); |
| 1002 | net->gsup_server_port = 0; |
| 1003 | |
| 1004 | OSMO_ASSERT(msc_vlr_alloc(net) == 0); |
| 1005 | OSMO_ASSERT(msc_vlr_start(net) == 0); |
| 1006 | OSMO_ASSERT(net->vlr); |
| 1007 | OSMO_ASSERT(net->vlr->gsup_client); |
| 1008 | |
| 1009 | net->vlr->ops.tx_lu_acc = fake_vlr_tx_lu_acc; |
| 1010 | net->vlr->ops.tx_lu_rej = fake_vlr_tx_lu_rej; |
| 1011 | net->vlr->ops.tx_cm_serv_acc = fake_vlr_tx_cm_serv_acc; |
| 1012 | net->vlr->ops.tx_cm_serv_rej = fake_vlr_tx_cm_serv_rej; |
| 1013 | net->vlr->ops.tx_auth_req = fake_vlr_tx_auth_req; |
| 1014 | net->vlr->ops.tx_auth_rej = fake_vlr_tx_auth_rej; |
| 1015 | net->vlr->ops.set_ciph_mode = fake_vlr_tx_ciph_mode_cmd; |
| 1016 | |
| 1017 | return net; |
| 1018 | } |
| 1019 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1020 | int main(int argc, char **argv) |
| 1021 | { |
| 1022 | handle_options(argc, argv); |
| 1023 | |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 1024 | msc_vlr_tests_ctx = talloc_named_const(NULL, 0, "msc_vlr_tests_ctx"); |
| 1025 | msgb_ctx = msgb_talloc_ctx_init(msc_vlr_tests_ctx, 0); |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 1026 | osmo_init_logging2(msc_vlr_tests_ctx, &info); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1027 | |
| 1028 | _log_lines = cmdline_opts.verbose; |
| 1029 | |
| 1030 | OSMO_ASSERT(osmo_stderr_target); |
| 1031 | log_set_use_color(osmo_stderr_target, 0); |
| 1032 | log_set_print_timestamp(osmo_stderr_target, 0); |
Neels Hofmeyr | 39cb0dd | 2018-12-18 02:30:18 +0100 | [diff] [blame] | 1033 | log_set_print_filename(osmo_stderr_target, 0); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1034 | log_set_print_category(osmo_stderr_target, 1); |
Max | 4813152 | 2019-01-16 12:47:39 +0100 | [diff] [blame] | 1035 | log_set_category_filter(osmo_stderr_target, DLSMS, 1, LOGL_DEBUG); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1036 | |
Neels Hofmeyr | 39cb0dd | 2018-12-18 02:30:18 +0100 | [diff] [blame] | 1037 | if (cmdline_opts.verbose) { |
Neels Hofmeyr | 39cb0dd | 2018-12-18 02:30:18 +0100 | [diff] [blame] | 1038 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME); |
| 1039 | log_set_print_filename_pos(osmo_stderr_target, LOG_FILENAME_POS_LINE_END); |
| 1040 | log_set_use_color(osmo_stderr_target, 1); |
| 1041 | log_set_print_level(osmo_stderr_target, 1); |
| 1042 | } |
Neels Hofmeyr | 3f5b780 | 2017-12-15 03:49:55 +0100 | [diff] [blame] | 1043 | |
Neels Hofmeyr | c01e909 | 2018-03-22 15:56:49 +0100 | [diff] [blame] | 1044 | net = test_net(msc_vlr_tests_ctx); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1045 | |
| 1046 | osmo_fsm_log_addr(false); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1047 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 1048 | ran_conn_init(); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1049 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 1050 | clear_vlr(); |
| 1051 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1052 | if (optind >= argc) |
| 1053 | run_tests(-1); |
| 1054 | else { |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1055 | int arg; |
| 1056 | long int nr; |
| 1057 | for (arg = optind; arg < argc; arg++) { |
Neels Hofmeyr | 9c848b5 | 2017-11-22 01:59:36 +0100 | [diff] [blame] | 1058 | errno = 0; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1059 | nr = strtol(argv[arg], NULL, 10); |
| 1060 | if (errno) { |
| 1061 | fprintf(stderr, "Invalid argument: %s\n", |
| 1062 | argv[arg]); |
| 1063 | exit(1); |
| 1064 | } |
| 1065 | |
Neels Hofmeyr | dfdc61d | 2018-03-02 00:40:58 +0100 | [diff] [blame] | 1066 | run_tests(nr); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | printf("Done\n"); |
| 1071 | |
Neels Hofmeyr | 08b3828 | 2018-03-30 23:04:04 +0200 | [diff] [blame] | 1072 | check_talloc(msgb_ctx, msc_vlr_tests_ctx); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 1073 | return 0; |
| 1074 | } |