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 | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 33 | #include <osmocom/msc/gsup_client.h> |
| 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 | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 38 | |
| 39 | #if BUILD_IU |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 40 | #include <osmocom/msc/iucs_ranap.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 41 | #include <osmocom/ranap/iu_client.h> |
| 42 | #else |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 43 | #include <osmocom/msc/iu_dummy.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 44 | #endif |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 45 | |
| 46 | #include "msc_vlr_tests.h" |
| 47 | |
| 48 | bool _log_lines = false; |
| 49 | |
| 50 | struct gsm_network *net = NULL; |
| 51 | |
| 52 | struct gsm_bts *the_bts; |
| 53 | |
| 54 | const char *gsup_tx_expected = NULL; |
| 55 | bool gsup_tx_confirmed; |
| 56 | |
| 57 | struct msgb *dtap_tx_expected = NULL; |
| 58 | bool dtap_tx_confirmed; |
| 59 | |
| 60 | enum result_sent lu_result_sent; |
| 61 | enum result_sent cm_service_result_sent; |
| 62 | bool auth_request_sent; |
| 63 | const char *auth_request_expect_rand; |
| 64 | const char *auth_request_expect_autn; |
| 65 | bool cipher_mode_cmd_sent; |
| 66 | bool cipher_mode_cmd_sent_with_imeisv; |
| 67 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 68 | bool iu_release_expected = false; |
| 69 | bool iu_release_sent = false; |
| 70 | bool bssap_clear_expected = false; |
| 71 | bool bssap_clear_sent = false; |
| 72 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 73 | uint32_t cc_to_mncc_tx_expected_msg_type = 0; |
| 74 | const char *cc_to_mncc_tx_expected_imsi = NULL; |
| 75 | bool cc_to_mncc_tx_confirmed = false; |
| 76 | uint32_t cc_to_mncc_tx_got_callref = 0; |
| 77 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 78 | struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex) |
| 79 | { |
| 80 | struct msgb *msg = msgb_alloc(size, label); |
| 81 | unsigned char *rc; |
| 82 | msg->l2h = msg->head; |
| 83 | rc = msgb_put(msg, osmo_hexparse(hex, msg->head, msgb_tailroom(msg))); |
| 84 | OSMO_ASSERT(rc == msg->l2h); |
| 85 | return msg; |
| 86 | } |
| 87 | |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 88 | const char *gh_type_name(struct gsm48_hdr *gh) |
| 89 | { |
| 90 | return gsm48_pdisc_msgtype_name(gsm48_hdr_pdisc(gh), |
| 91 | gsm48_hdr_msg_type(gh)); |
| 92 | } |
| 93 | |
| 94 | const char *msg_type_name(struct msgb *msg) |
| 95 | { |
| 96 | return gh_type_name((void*)msg->data); |
| 97 | } |
| 98 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 99 | void dtap_expect_tx(const char *hex) |
| 100 | { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 101 | /* Has the previously expected dtap been received? */ |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 102 | OSMO_ASSERT(!dtap_tx_expected); |
| 103 | if (!hex) |
| 104 | return; |
| 105 | dtap_tx_expected = msgb_from_hex("dtap_tx_expected", 1024, hex); |
| 106 | dtap_tx_confirmed = false; |
| 107 | } |
| 108 | |
| 109 | void dtap_expect_tx_ussd(char *ussd_text) |
| 110 | { |
| 111 | uint8_t ussd_enc[128]; |
| 112 | int len; |
| 113 | /* header */ |
| 114 | char ussd_msg_hex[128] = "8b2a1c27a225020100302002013b301b04010f0416"; |
| 115 | |
| 116 | log("expecting USSD:\n %s", ussd_text); |
| 117 | /* append encoded USSD text */ |
| 118 | gsm_7bit_encode_n_ussd(ussd_enc, sizeof(ussd_enc), ussd_text, |
| 119 | &len); |
| 120 | strncat(ussd_msg_hex, osmo_hexdump_nospc(ussd_enc, len), |
| 121 | sizeof(ussd_msg_hex) - strlen(ussd_msg_hex)); |
| 122 | dtap_expect_tx(ussd_msg_hex); |
| 123 | } |
| 124 | |
| 125 | int vlr_gsupc_read_cb(struct gsup_client *gsupc, struct msgb *msg); |
| 126 | |
| 127 | void gsup_rx(const char *rx_hex, const char *expect_tx_hex) |
| 128 | { |
| 129 | int rc; |
| 130 | struct msgb *msg; |
| 131 | const char *label; |
| 132 | |
| 133 | gsup_expect_tx(expect_tx_hex); |
| 134 | |
| 135 | msg = msgb_from_hex("gsup", 1024, rx_hex); |
| 136 | label = osmo_gsup_message_type_name(msg->l2h[0]); |
| 137 | fprintf(stderr, "<-- GSUP rx %s: %s\n", label, |
| 138 | osmo_hexdump_nospc(msgb_l2(msg), msgb_l2len(msg))); |
Neels Hofmeyr | 834f94a | 2017-09-28 03:07:16 +0200 | [diff] [blame] | 139 | /* GSUP read cb takes ownership of msgb */ |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 140 | rc = vlr_gsupc_read_cb(net->vlr->gsup_client, msg); |
| 141 | fprintf(stderr, "<-- GSUP rx %s: vlr_gsupc_read_cb() returns %d\n", |
| 142 | label, rc); |
| 143 | if (expect_tx_hex) |
| 144 | OSMO_ASSERT(gsup_tx_confirmed); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | bool conn_exists(struct gsm_subscriber_connection *conn) |
| 148 | { |
| 149 | struct gsm_subscriber_connection *c; |
| 150 | llist_for_each_entry(c, &net->subscr_conns, entry) { |
| 151 | if (c == conn) |
| 152 | return true; |
| 153 | } |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | enum ran_type rx_from_ran = RAN_GERAN_A; |
| 158 | |
| 159 | struct gsm_subscriber_connection *conn_new(void) |
| 160 | { |
| 161 | struct gsm_subscriber_connection *conn; |
| 162 | conn = msc_subscr_con_allocate(net); |
| 163 | conn->bts = the_bts; |
| 164 | conn->via_ran = rx_from_ran; |
Neels Hofmeyr | 8a656eb | 2017-11-22 02:55:52 +0100 | [diff] [blame] | 165 | conn->lac = 23; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 166 | if (conn->via_ran == RAN_UTRAN_IU) { |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 167 | struct ranap_ue_conn_ctx *ue_ctx = talloc_zero(conn, struct ranap_ue_conn_ctx); |
| 168 | *ue_ctx = (struct ranap_ue_conn_ctx){ |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 169 | .conn_id = 42, |
| 170 | }; |
| 171 | conn->iu.ue_ctx = ue_ctx; |
| 172 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 173 | return conn; |
| 174 | } |
| 175 | |
| 176 | struct gsm_subscriber_connection *g_conn = NULL; |
| 177 | |
| 178 | void rx_from_ms(struct msgb *msg) |
| 179 | { |
| 180 | int rc; |
| 181 | |
| 182 | struct gsm48_hdr *gh = msgb_l3(msg); |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 183 | |
| 184 | log("MSC <--%s-- MS: %s", |
| 185 | ran_type_name(rx_from_ran), |
| 186 | gh_type_name(gh)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 187 | |
| 188 | if (g_conn && !conn_exists(g_conn)) |
| 189 | g_conn = NULL; |
| 190 | |
| 191 | if (!g_conn) { |
| 192 | log("new conn"); |
| 193 | g_conn = conn_new(); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 194 | rc = msc_compl_l3(g_conn, msg, 23); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 195 | if (rc == BSC_API_CONN_POL_REJECT) { |
| 196 | msc_subscr_con_free(g_conn); |
| 197 | g_conn = NULL; |
| 198 | } |
| 199 | } else { |
| 200 | if ((gsm48_hdr_pdisc(gh) == GSM48_PDISC_RR) |
| 201 | && (gsm48_hdr_msg_type(gh) == GSM48_MT_RR_CIPH_M_COMPL)) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 202 | msc_cipher_mode_compl(g_conn, msg, 0); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 203 | else |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 204 | msc_dtap(g_conn, 23, msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | if (g_conn && !conn_exists(g_conn)) |
| 208 | g_conn = NULL; |
| 209 | } |
| 210 | |
| 211 | void ms_sends_msg(const char *hex) |
| 212 | { |
| 213 | struct msgb *msg; |
| 214 | |
| 215 | msg = msgb_from_hex("ms_sends_msg", 1024, hex); |
| 216 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
| 217 | rx_from_ms(msg); |
| 218 | talloc_free(msg); |
| 219 | } |
| 220 | |
| 221 | int ms_sends_msg_fake(uint8_t pdisc, uint8_t msg_type) |
| 222 | { |
| 223 | int rc; |
| 224 | struct msgb *msg; |
| 225 | struct gsm48_hdr *gh; |
| 226 | |
| 227 | msg = msgb_alloc(1024, "ms_sends_msg_fake"); |
| 228 | msg->l1h = msg->l2h = msg->l3h = msg->data; |
| 229 | |
| 230 | gh = (struct gsm48_hdr*)msgb_put(msg, sizeof(*gh)); |
| 231 | gh->proto_discr = pdisc; |
| 232 | gh->msg_type = msg_type; |
| 233 | /* some amount of data, whatever */ |
| 234 | msgb_put(msg, 123); |
| 235 | |
| 236 | rc = gsm0408_dispatch(g_conn, msg); |
| 237 | |
| 238 | talloc_free(msg); |
| 239 | return rc; |
| 240 | } |
| 241 | |
| 242 | void thwart_rx_non_initial_requests() |
| 243 | { |
| 244 | log("requests shall be thwarted"); |
| 245 | OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_CC, GSM48_MT_CC_SETUP) == -EACCES); |
| 246 | OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_MM, 0x33 /* nonexistent */) == -EACCES); |
| 247 | OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_RR, GSM48_MT_RR_SYSINFO_1) == -EACCES); |
| 248 | OSMO_ASSERT(ms_sends_msg_fake(GSM48_PDISC_SMS, GSM411_MT_CP_DATA) == -EACCES); |
| 249 | } |
| 250 | |
| 251 | void send_sms(struct vlr_subscr *receiver, |
| 252 | struct vlr_subscr *sender, |
| 253 | char *str) |
| 254 | { |
| 255 | struct gsm_sms *sms = sms_from_text(receiver, sender, 0, str); |
| 256 | gsm411_send_sms_subscr(receiver, sms); |
| 257 | } |
| 258 | |
| 259 | unsigned char next_rand_byte = 0; |
| 260 | /* override, requires '-Wl,--wrap=RAND_bytes' */ |
| 261 | int __real_RAND_bytes(unsigned char *buf, int num); |
| 262 | int __wrap_RAND_bytes(unsigned char *buf, int num) |
| 263 | { |
| 264 | int i; |
| 265 | for (i = 0; i < num; i++) |
| 266 | buf[i] = next_rand_byte++; |
| 267 | return 1; |
| 268 | } |
| 269 | |
| 270 | /* override, requires '-Wl,--wrap=gsm340_gen_scts' */ |
| 271 | void __real_gsm340_gen_scts(uint8_t *scts, time_t time); |
| 272 | void __wrap_gsm340_gen_scts(uint8_t *scts, time_t time) |
| 273 | { |
Neels Hofmeyr | 05230ea | 2017-08-22 18:06:42 +0200 | [diff] [blame] | 274 | /* Write fixed time bytes for deterministic test results */ |
| 275 | osmo_hexparse("07101000000000", scts, 7); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | const char *paging_expecting_imsi = NULL; |
| 279 | uint32_t paging_expecting_tmsi; |
| 280 | bool paging_sent; |
| 281 | bool paging_stopped; |
| 282 | |
| 283 | void paging_expect_imsi(const char *imsi) |
| 284 | { |
| 285 | paging_expecting_imsi = imsi; |
| 286 | paging_expecting_tmsi = GSM_RESERVED_TMSI; |
| 287 | } |
| 288 | |
| 289 | void paging_expect_tmsi(uint32_t tmsi) |
| 290 | { |
| 291 | paging_expecting_tmsi = tmsi; |
| 292 | paging_expecting_imsi = NULL; |
| 293 | } |
| 294 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 295 | int _paging_sent(enum ran_type via_ran, const char *imsi, uint32_t tmsi, uint32_t lac) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 296 | { |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 297 | log("%s sends out paging request to IMSI %s, TMSI 0x%08x, LAC %u", |
| 298 | ran_type_name(via_ran), imsi, tmsi, lac); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 299 | OSMO_ASSERT(paging_expecting_imsi || (paging_expecting_tmsi != GSM_RESERVED_TMSI)); |
| 300 | if (paging_expecting_imsi) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 301 | VERBOSE_ASSERT(strcmp(paging_expecting_imsi, imsi), == 0, "%d"); |
| 302 | if (paging_expecting_tmsi != GSM_RESERVED_TMSI) { |
| 303 | VERBOSE_ASSERT(paging_expecting_tmsi, == tmsi, "0x%08x"); |
| 304 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 305 | paging_sent = true; |
| 306 | paging_stopped = false; |
| 307 | return 1; |
| 308 | } |
| 309 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 310 | /* override, requires '-Wl,--wrap=ranap_iu_page_cs' */ |
| 311 | int __real_ranap_iu_page_cs(const char *imsi, const uint32_t *tmsi, uint16_t lac); |
| 312 | 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] | 313 | { |
| 314 | return _paging_sent(RAN_UTRAN_IU, imsi, tmsi ? *tmsi : GSM_RESERVED_TMSI, lac); |
| 315 | } |
| 316 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 317 | /* override, requires '-Wl,--wrap=a_iface_tx_paging' */ |
| 318 | int __real_a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac); |
| 319 | 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] | 320 | { |
| 321 | return _paging_sent(RAN_GERAN_A, imsi, tmsi, lac); |
| 322 | } |
| 323 | |
| 324 | /* override, requires '-Wl,--wrap=msc_stop_paging' */ |
| 325 | void __real_msc_stop_paging(struct vlr_subscr *vsub); |
| 326 | void __wrap_msc_stop_paging(struct vlr_subscr *vsub) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 327 | { |
| 328 | paging_stopped = true; |
| 329 | } |
| 330 | |
| 331 | void clear_vlr() |
| 332 | { |
| 333 | struct vlr_subscr *vsub, *n; |
| 334 | llist_for_each_entry_safe(vsub, n, &net->vlr->subscribers, list) { |
| 335 | vlr_subscr_free(vsub); |
| 336 | } |
| 337 | |
| 338 | net->authentication_required = false; |
| 339 | net->a5_encryption = VLR_CIPH_NONE; |
| 340 | net->vlr->cfg.check_imei_rqd = false; |
| 341 | net->vlr->cfg.assign_tmsi = false; |
Neels Hofmeyr | 54a706c | 2017-07-18 15:39:27 +0200 | [diff] [blame] | 342 | net->vlr->cfg.retrieve_imeisv_early = false; |
| 343 | net->vlr->cfg.retrieve_imeisv_ciphered = false; |
Neels Hofmeyr | 7b1418e | 2017-10-29 02:12:16 +0100 | [diff] [blame] | 344 | net->vlr->cfg.auth_tuple_max_reuse_count = 0; |
| 345 | net->vlr->cfg.auth_reuse_old_sets_on_error = false; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 346 | |
| 347 | rx_from_ran = RAN_GERAN_A; |
| 348 | auth_request_sent = false; |
| 349 | auth_request_expect_rand = NULL; |
| 350 | auth_request_expect_autn = NULL; |
| 351 | |
| 352 | next_rand_byte = 0; |
| 353 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 354 | iu_release_expected = false; |
| 355 | iu_release_sent = false; |
| 356 | bssap_clear_expected = false; |
| 357 | bssap_clear_sent = false; |
| 358 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 359 | osmo_gettimeofday_override = false; |
| 360 | } |
| 361 | |
| 362 | static struct log_info_cat test_categories[] = { |
| 363 | [DMSC] = { |
| 364 | .name = "DMSC", |
| 365 | .description = "Mobile Switching Center", |
| 366 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 367 | }, |
| 368 | [DRLL] = { |
| 369 | .name = "DRLL", |
| 370 | .description = "A-bis Radio Link Layer (RLL)", |
| 371 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 372 | }, |
| 373 | [DMM] = { |
| 374 | .name = "DMM", |
| 375 | .description = "Layer3 Mobility Management (MM)", |
| 376 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 377 | }, |
| 378 | [DRR] = { |
| 379 | .name = "DRR", |
| 380 | .description = "Layer3 Radio Resource (RR)", |
| 381 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 382 | }, |
| 383 | [DCC] = { |
| 384 | .name = "DCC", |
| 385 | .description = "Layer3 Call Control (CC)", |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 386 | .enabled = 1, .loglevel = LOGL_INFO, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 387 | }, |
| 388 | [DMM] = { |
| 389 | .name = "DMM", |
| 390 | .description = "Layer3 Mobility Management (MM)", |
| 391 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 392 | }, |
| 393 | [DVLR] = { |
| 394 | .name = "DVLR", |
| 395 | .description = "Visitor Location Register", |
| 396 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 397 | }, |
| 398 | [DREF] = { |
| 399 | .name = "DREF", |
| 400 | .description = "Reference Counting", |
| 401 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 402 | }, |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 403 | [DPAG] = { |
| 404 | .name = "DPAG", |
| 405 | .description = "Paging Subsystem", |
| 406 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 407 | }, |
| 408 | [DIUCS] = { |
| 409 | .name = "DIUCS", |
| 410 | .description = "Iu-CS Protocol", |
| 411 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 412 | }, |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 413 | [DMNCC] = { |
| 414 | .name = "DMNCC", |
| 415 | .description = "MNCC API for Call Control application", |
| 416 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 417 | }, |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | static struct log_info info = { |
| 421 | .cat = test_categories, |
| 422 | .num_cat = ARRAY_SIZE(test_categories), |
| 423 | }; |
| 424 | |
| 425 | extern void *tall_bsc_ctx; |
| 426 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 427 | int mncc_recv(struct gsm_network *net, struct msgb *msg) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 428 | { |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 429 | struct gsm_mncc *mncc = (void*)msg->data; |
| 430 | log("MSC --> MNCC: callref 0x%x: %s", mncc->callref, |
| 431 | get_mncc_name(mncc->msg_type)); |
| 432 | |
| 433 | OSMO_ASSERT(cc_to_mncc_tx_expected_msg_type); |
| 434 | if (cc_to_mncc_tx_expected_msg_type != mncc->msg_type) { |
| 435 | log("Mismatch! Expected MNCC msg type: %s", |
| 436 | get_mncc_name(cc_to_mncc_tx_expected_msg_type)); |
| 437 | abort(); |
| 438 | } |
| 439 | |
| 440 | if (strcmp(cc_to_mncc_tx_expected_imsi, mncc->imsi)) { |
| 441 | log("Mismatch! Expected MNCC msg IMSI: '%s', got '%s'", |
| 442 | cc_to_mncc_tx_expected_imsi, |
| 443 | mncc->imsi); |
| 444 | abort(); |
| 445 | } |
| 446 | |
| 447 | cc_to_mncc_tx_confirmed = true; |
| 448 | cc_to_mncc_tx_got_callref = mncc->callref; |
| 449 | cc_to_mncc_tx_expected_imsi = NULL; |
| 450 | cc_to_mncc_tx_expected_msg_type = 0; |
| 451 | talloc_free(msg); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | /* override, requires '-Wl,--wrap=gsup_client_create' */ |
| 456 | struct gsup_client * |
| 457 | __real_gsup_client_create(const char *ip_addr, unsigned int tcp_port, |
| 458 | gsup_client_read_cb_t read_cb, |
| 459 | struct oap_client_config *oap_config); |
| 460 | struct gsup_client * |
| 461 | __wrap_gsup_client_create(const char *ip_addr, unsigned int tcp_port, |
| 462 | gsup_client_read_cb_t read_cb, |
| 463 | struct oap_client_config *oap_config) |
| 464 | { |
| 465 | struct gsup_client *gsupc; |
| 466 | gsupc = talloc_zero(tall_bsc_ctx, struct gsup_client); |
| 467 | OSMO_ASSERT(gsupc); |
| 468 | return gsupc; |
| 469 | } |
| 470 | |
| 471 | /* override, requires '-Wl,--wrap=gsup_client_send' */ |
| 472 | int __real_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg); |
| 473 | int __wrap_gsup_client_send(struct gsup_client *gsupc, struct msgb *msg) |
| 474 | { |
| 475 | const char *is = osmo_hexdump_nospc(msg->data, msg->len); |
| 476 | fprintf(stderr, "GSUP --> HLR: %s: %s\n", |
| 477 | osmo_gsup_message_type_name(msg->data[0]), is); |
| 478 | |
| 479 | OSMO_ASSERT(gsup_tx_expected); |
| 480 | if (strcmp(gsup_tx_expected, is)) { |
| 481 | fprintf(stderr, "Mismatch! Expected:\n%s\n", gsup_tx_expected); |
| 482 | abort(); |
| 483 | } |
| 484 | |
| 485 | talloc_free(msg); |
| 486 | gsup_tx_confirmed = true; |
| 487 | gsup_tx_expected = NULL; |
| 488 | return 0; |
| 489 | } |
| 490 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 491 | int _validate_dtap(struct msgb *msg, enum ran_type to_ran) |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 492 | { |
Neels Hofmeyr | 78ada64 | 2017-03-10 02:15:20 +0100 | [diff] [blame] | 493 | btw("DTAP --%s--> MS: %s: %s", |
| 494 | ran_type_name(to_ran), msg_type_name(msg), |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 495 | osmo_hexdump_nospc(msg->data, msg->len)); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 496 | |
| 497 | OSMO_ASSERT(dtap_tx_expected); |
| 498 | if (msg->len != dtap_tx_expected->len |
| 499 | || memcmp(msg->data, dtap_tx_expected->data, msg->len)) { |
| 500 | fprintf(stderr, "Mismatch! Expected:\n%s\n", |
| 501 | osmo_hexdump_nospc(dtap_tx_expected->data, |
| 502 | dtap_tx_expected->len)); |
| 503 | abort(); |
| 504 | } |
| 505 | |
| 506 | btw("DTAP matches expected message"); |
| 507 | |
| 508 | talloc_free(msg); |
| 509 | dtap_tx_confirmed = true; |
| 510 | talloc_free(dtap_tx_expected); |
| 511 | dtap_tx_expected = NULL; |
| 512 | return 0; |
| 513 | } |
| 514 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 515 | /* override, requires '-Wl,--wrap=ranap_iu_tx' */ |
| 516 | int __real_ranap_iu_tx(struct msgb *msg, uint8_t sapi); |
| 517 | int __wrap_ranap_iu_tx(struct msgb *msg, uint8_t sapi) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 518 | { |
| 519 | return _validate_dtap(msg, RAN_UTRAN_IU); |
| 520 | } |
| 521 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 522 | /* override, requires '-Wl,--wrap=ranap_iu_tx_release' */ |
| 523 | int __real_ranap_iu_tx_release(struct ranap_ue_conn_ctx *ctx, const struct RANAP_Cause *cause); |
| 524 | 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] | 525 | { |
| 526 | btw("Iu Release --%s--> MS", ran_type_name(RAN_UTRAN_IU)); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 527 | OSMO_ASSERT(iu_release_expected); |
| 528 | iu_release_expected = false; |
| 529 | iu_release_sent = true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | /* override, requires '-Wl,--wrap=iu_tx_common_id' */ |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 534 | int __real_ranap_iu_tx_common_id(struct ranap_ue_conn_ctx *ue_ctx, const char *imsi); |
| 535 | 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] | 536 | { |
| 537 | btw("Iu Common ID --%s--> MS (IMSI=%s)", ran_type_name(RAN_UTRAN_IU), imsi); |
| 538 | return 0; |
| 539 | } |
| 540 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 541 | /* override, requires '-Wl,--wrap=a_iface_tx_dtap' */ |
| 542 | int __real_a_iface_tx_dtap(struct msgb *msg); |
| 543 | int __wrap_a_iface_tx_dtap(struct msgb *msg) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 544 | { |
| 545 | return _validate_dtap(msg, RAN_GERAN_A); |
| 546 | } |
| 547 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 548 | /* override, requires '-Wl,--wrap=a_iface_tx_clear_cmd' */ |
| 549 | int __real_a_iface_tx_clear_cmd(struct gsm_subscriber_connection *conn); |
| 550 | int __wrap_a_iface_tx_clear_cmd(struct gsm_subscriber_connection *conn) |
| 551 | { |
| 552 | btw("BSSAP Clear --%s--> MS", ran_type_name(RAN_GERAN_A)); |
| 553 | OSMO_ASSERT(bssap_clear_expected); |
| 554 | bssap_clear_expected = false; |
| 555 | bssap_clear_sent = true; |
| 556 | return 0; |
| 557 | } |
| 558 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 559 | /* override, requires '-Wl,--wrap=msc_call_assignment' */ |
| 560 | int __real_msc_call_assignment(struct gsm_trans *trans); |
| 561 | int __wrap_msc_call_assignment(struct gsm_trans *trans) |
| 562 | { |
| 563 | log("MS <--Call Assignment-- MSC: subscr=%s callref=0x%x", |
| 564 | vlr_subscr_name(trans->vsub), trans->callref); |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | /* override, requires '-Wl,--wrap=msc_call_release' */ |
| 569 | void __real_msc_call_release(struct gsm_trans *trans); |
| 570 | void __wrap_msc_call_release(struct gsm_trans *trans) |
| 571 | { |
| 572 | log("MS <--Call Release-- MSC: subscr=%s callref=0x%x", |
| 573 | vlr_subscr_name(trans->vsub), trans->callref); |
| 574 | } |
| 575 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 576 | static int fake_vlr_tx_lu_acc(void *msc_conn_ref, uint32_t send_tmsi) |
| 577 | { |
| 578 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 579 | if (send_tmsi == GSM_RESERVED_TMSI) |
| 580 | btw("sending LU Accept for %s", vlr_subscr_name(conn->vsub)); |
| 581 | else |
| 582 | btw("sending LU Accept for %s, with TMSI 0x%08x", |
| 583 | vlr_subscr_name(conn->vsub), send_tmsi); |
| 584 | lu_result_sent |= RES_ACCEPT; |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static int fake_vlr_tx_lu_rej(void *msc_conn_ref, uint8_t cause) |
| 589 | { |
| 590 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 591 | btw("sending LU Reject for %s, cause %u", vlr_subscr_name(conn->vsub), cause); |
| 592 | lu_result_sent |= RES_REJECT; |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | static int fake_vlr_tx_cm_serv_acc(void *msc_conn_ref) |
| 597 | { |
| 598 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 599 | btw("sending CM Service Accept for %s", vlr_subscr_name(conn->vsub)); |
| 600 | cm_service_result_sent |= RES_ACCEPT; |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | static int fake_vlr_tx_cm_serv_rej(void *msc_conn_ref, |
| 605 | enum vlr_proc_arq_result result) |
| 606 | { |
| 607 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 608 | btw("sending CM Service Reject for %s, result %s", |
| 609 | vlr_subscr_name(conn->vsub), |
| 610 | vlr_proc_arq_result_name(result)); |
| 611 | cm_service_result_sent |= RES_REJECT; |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static int fake_vlr_tx_auth_req(void *msc_conn_ref, struct gsm_auth_tuple *at, |
| 616 | bool send_autn) |
| 617 | { |
| 618 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 619 | char *hex; |
| 620 | bool ok = true; |
| 621 | btw("sending %s Auth Request for %s: tuple use_count=%d key_seq=%d auth_types=0x%x and...", |
| 622 | send_autn? "UMTS" : "GSM", vlr_subscr_name(conn->vsub), |
| 623 | at->use_count, at->key_seq, at->vec.auth_types); |
| 624 | |
| 625 | hex = osmo_hexdump_nospc((void*)&at->vec.rand, sizeof(at->vec.rand)); |
| 626 | btw("...rand=%s", hex); |
| 627 | if (!auth_request_expect_rand |
| 628 | || strcmp(hex, auth_request_expect_rand) != 0) { |
| 629 | ok = false; |
| 630 | log("FAILURE: expected rand=%s", |
| 631 | auth_request_expect_rand ? auth_request_expect_rand : "-"); |
| 632 | } |
| 633 | |
| 634 | if (send_autn) { |
| 635 | hex = osmo_hexdump_nospc((void*)&at->vec.autn, sizeof(at->vec.autn)); |
| 636 | btw("...autn=%s", hex); |
| 637 | if (!auth_request_expect_autn |
| 638 | || strcmp(hex, auth_request_expect_autn) != 0) { |
| 639 | ok = false; |
| 640 | log("FAILURE: expected autn=%s", |
| 641 | auth_request_expect_autn ? auth_request_expect_autn : "-"); |
| 642 | } |
| 643 | } else if (auth_request_expect_autn) { |
| 644 | ok = false; |
| 645 | log("FAILURE: no AUTN sent, expected AUTN = %s", |
| 646 | auth_request_expect_autn); |
| 647 | } |
| 648 | |
| 649 | if (send_autn) |
| 650 | btw("...expecting res=%s", |
| 651 | osmo_hexdump_nospc((void*)&at->vec.res, at->vec.res_len)); |
| 652 | else |
| 653 | btw("...expecting sres=%s", |
| 654 | osmo_hexdump_nospc((void*)&at->vec.sres, sizeof(at->vec.sres))); |
| 655 | |
| 656 | auth_request_sent = ok; |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static int fake_vlr_tx_auth_rej(void *msc_conn_ref) |
| 661 | { |
| 662 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
| 663 | btw("sending Auth Reject for %s", vlr_subscr_name(conn->vsub)); |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int fake_vlr_tx_ciph_mode_cmd(void *msc_conn_ref, enum vlr_ciph ciph, |
| 668 | bool retrieve_imeisv) |
| 669 | { |
| 670 | /* FIXME: we actually would like to see the message bytes checked here, |
| 671 | * not possible while msc_vlr_set_ciph_mode() calls |
| 672 | * gsm0808_cipher_mode() directly. When the MSCSPLIT is ready, check |
| 673 | * the tx bytes in the sense of dtap_expect_tx() above. */ |
| 674 | struct gsm_subscriber_connection *conn = msc_conn_ref; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 675 | switch (conn->via_ran) { |
| 676 | case RAN_GERAN_A: |
| 677 | btw("sending Ciphering Mode Command for %s: cipher=%s kc=%s" |
| 678 | " retrieve_imeisv=%d", |
| 679 | vlr_subscr_name(conn->vsub), |
| 680 | vlr_ciph_name(conn->network->a5_encryption), |
| 681 | osmo_hexdump_nospc(conn->vsub->last_tuple->vec.kc, 8), |
| 682 | retrieve_imeisv); |
| 683 | break; |
| 684 | case RAN_UTRAN_IU: |
| 685 | btw("sending SecurityModeControl for %s", |
| 686 | vlr_subscr_name(conn->vsub)); |
| 687 | break; |
| 688 | default: |
| 689 | btw("UNKNOWN RAN TYPE %d", conn->via_ran); |
| 690 | OSMO_ASSERT(false); |
| 691 | return -1; |
| 692 | } |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 693 | cipher_mode_cmd_sent = true; |
| 694 | cipher_mode_cmd_sent_with_imeisv = retrieve_imeisv; |
| 695 | return 0; |
| 696 | } |
| 697 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 698 | void ms_sends_security_mode_complete() |
| 699 | { |
| 700 | OSMO_ASSERT(g_conn); |
| 701 | OSMO_ASSERT(g_conn->via_ran == RAN_UTRAN_IU); |
| 702 | OSMO_ASSERT(g_conn->iu.ue_ctx); |
| 703 | msc_rx_sec_mode_compl(g_conn); |
| 704 | } |
| 705 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 706 | const struct timeval fake_time_start_time = { 123, 456 }; |
| 707 | |
| 708 | void fake_time_start() |
| 709 | { |
| 710 | osmo_gettimeofday_override_time = fake_time_start_time; |
| 711 | osmo_gettimeofday_override = true; |
| 712 | fake_time_passes(0, 0); |
| 713 | } |
| 714 | |
| 715 | void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks) |
| 716 | { |
| 717 | talloc_report_full(msgb_ctx, stderr); |
Neels Hofmeyr | 2c46e04 | 2017-11-18 23:29:24 +0100 | [diff] [blame] | 718 | /* Expecting these to stick around in tall_bsc_ctx: |
| 719 | full talloc report on 'msgb' (total 0 bytes in 1 blocks) |
| 720 | talloc_total_blocks(tall_bsc_ctx) == 9 |
| 721 | full talloc report on 'subscr_conn_test_ctx' (total 2658 bytes in 9 blocks) |
| 722 | struct gsup_client contains 248 bytes in 1 blocks (ref 0) 0x61300000dee0 |
| 723 | struct gsm_network contains 2410 bytes in 6 blocks (ref 0) 0x61700000fce0 |
| 724 | struct vlr_instance contains 160 bytes in 1 blocks (ref 0) 0x611000009a60 |
| 725 | no_gsup_server contains 15 bytes in 1 blocks (ref 0) 0x60b00000ade0 |
| 726 | ../../../src/libosmocore/src/rate_ctr.c:199 contains 1552 bytes in 1 blocks (ref 0) 0x61b00001eae0 |
| 727 | struct llist_head contains 16 bytes in 1 blocks (ref 0) 0x60b00000ae90 |
| 728 | .* contains 3 bytes in 1 blocks (ref 0) 0x60b00000af40 |
| 729 | msgb contains 0 bytes in 1 blocks (ref 0) 0x60800000bf80 |
| 730 | */ |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 731 | fprintf(stderr, "talloc_total_blocks(tall_bsc_ctx) == %zu\n", |
| 732 | talloc_total_blocks(tall_bsc_ctx)); |
| 733 | if (talloc_total_blocks(tall_bsc_ctx) != expected_blocks) |
| 734 | talloc_report_full(tall_bsc_ctx, stderr); |
| 735 | fprintf(stderr, "\n"); |
| 736 | } |
| 737 | |
| 738 | static struct { |
| 739 | bool verbose; |
| 740 | int run_test_nr; |
| 741 | } cmdline_opts = { |
| 742 | .verbose = false, |
| 743 | .run_test_nr = -1, |
| 744 | }; |
| 745 | |
| 746 | static void print_help(const char *program) |
| 747 | { |
| 748 | printf("Usage:\n" |
| 749 | " %s [-v] [N [N...]]\n" |
| 750 | "Options:\n" |
| 751 | " -h --help show this text.\n" |
| 752 | " -v --verbose print source file and line numbers\n" |
| 753 | " N run only the Nth test (first test is N=1)\n", |
| 754 | program |
| 755 | ); |
| 756 | } |
| 757 | |
| 758 | static void handle_options(int argc, char **argv) |
| 759 | { |
| 760 | while (1) { |
| 761 | int option_index = 0, c; |
| 762 | static struct option long_options[] = { |
| 763 | {"help", 0, 0, 'h'}, |
| 764 | {"verbose", 1, 0, 'v'}, |
| 765 | {0, 0, 0, 0} |
| 766 | }; |
| 767 | |
| 768 | c = getopt_long(argc, argv, "hv", |
| 769 | long_options, &option_index); |
| 770 | if (c == -1) |
| 771 | break; |
| 772 | |
| 773 | switch (c) { |
| 774 | case 'h': |
| 775 | print_help(argv[0]); |
| 776 | exit(0); |
| 777 | case 'v': |
| 778 | cmdline_opts.verbose = true; |
| 779 | break; |
| 780 | default: |
| 781 | /* catch unknown options *as well as* missing arguments. */ |
| 782 | fprintf(stderr, "Error in command line options. Exiting.\n"); |
| 783 | exit(-1); |
| 784 | break; |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | void *msgb_ctx = NULL; |
| 790 | |
| 791 | void run_tests(int nr) |
| 792 | { |
| 793 | int test_nr; |
| 794 | nr --; /* arg's first test is 1, in here it's 0 */ |
| 795 | for (test_nr = 0; msc_vlr_tests[test_nr]; test_nr ++) { |
| 796 | if (nr >= 0 && test_nr != nr) |
| 797 | continue; |
| 798 | |
| 799 | if (cmdline_opts.verbose) |
| 800 | fprintf(stderr, "(test nr %d)\n", test_nr + 1); |
| 801 | |
| 802 | msc_vlr_tests[test_nr](); |
| 803 | |
| 804 | if (cmdline_opts.verbose) |
| 805 | fprintf(stderr, "(test nr %d)\n", test_nr + 1); |
| 806 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 807 | check_talloc(msgb_ctx, tall_bsc_ctx, 9); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 808 | } while(0); |
| 809 | } |
| 810 | |
| 811 | int main(int argc, char **argv) |
| 812 | { |
| 813 | handle_options(argc, argv); |
| 814 | |
| 815 | tall_bsc_ctx = talloc_named_const(NULL, 0, "subscr_conn_test_ctx"); |
| 816 | msgb_ctx = msgb_talloc_ctx_init(tall_bsc_ctx, 0); |
| 817 | osmo_init_logging(&info); |
| 818 | |
| 819 | _log_lines = cmdline_opts.verbose; |
| 820 | |
| 821 | OSMO_ASSERT(osmo_stderr_target); |
| 822 | log_set_use_color(osmo_stderr_target, 0); |
| 823 | log_set_print_timestamp(osmo_stderr_target, 0); |
| 824 | log_set_print_filename(osmo_stderr_target, _log_lines? 1 : 0); |
| 825 | log_set_print_category(osmo_stderr_target, 1); |
| 826 | |
Neels Hofmeyr | a99b427 | 2017-11-21 17:13:23 +0100 | [diff] [blame] | 827 | net = gsm_network_init(tall_bsc_ctx, 1, 1, mncc_recv); |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 828 | net->gsup_server_addr_str = talloc_strdup(net, "no_gsup_server"); |
| 829 | net->gsup_server_port = 0; |
| 830 | |
| 831 | osmo_fsm_log_addr(false); |
| 832 | OSMO_ASSERT(msc_vlr_alloc(net) == 0); |
| 833 | OSMO_ASSERT(msc_vlr_start(net) == 0); |
| 834 | OSMO_ASSERT(net->vlr); |
| 835 | OSMO_ASSERT(net->vlr->gsup_client); |
| 836 | msc_subscr_conn_init(); |
| 837 | |
| 838 | net->vlr->ops.tx_lu_acc = fake_vlr_tx_lu_acc; |
| 839 | net->vlr->ops.tx_lu_rej = fake_vlr_tx_lu_rej; |
| 840 | net->vlr->ops.tx_cm_serv_acc = fake_vlr_tx_cm_serv_acc; |
| 841 | net->vlr->ops.tx_cm_serv_rej = fake_vlr_tx_cm_serv_rej; |
| 842 | net->vlr->ops.tx_auth_req = fake_vlr_tx_auth_req; |
| 843 | net->vlr->ops.tx_auth_rej = fake_vlr_tx_auth_rej; |
| 844 | net->vlr->ops.set_ciph_mode = fake_vlr_tx_ciph_mode_cmd; |
| 845 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 846 | clear_vlr(); |
| 847 | |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 848 | if (optind >= argc) |
| 849 | run_tests(-1); |
| 850 | else { |
| 851 | int arg; |
| 852 | long int nr; |
| 853 | for (arg = optind; arg < argc; arg++) { |
Neels Hofmeyr | 9c848b5 | 2017-11-22 01:59:36 +0100 | [diff] [blame] | 854 | errno = 0; |
Neels Hofmeyr | 6a29d32 | 2017-01-25 15:04:16 +0100 | [diff] [blame] | 855 | nr = strtol(argv[arg], NULL, 10); |
| 856 | if (errno) { |
| 857 | fprintf(stderr, "Invalid argument: %s\n", |
| 858 | argv[arg]); |
| 859 | exit(1); |
| 860 | } |
| 861 | |
| 862 | run_tests(nr); |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | printf("Done\n"); |
| 867 | |
| 868 | talloc_free(the_bts); |
| 869 | |
| 870 | check_talloc(msgb_ctx, tall_bsc_ctx, 9); |
| 871 | return 0; |
| 872 | } |