blob: ee26ac40d80540791abb7a733373b79c0cd2934e [file] [log] [blame]
Neels Hofmeyr6a29d322017-01-25 15:04:16 +01001/* 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#pragma once
25
26#include <stdbool.h>
27#include <stdio.h>
28
Neels Hofmeyr90843962017-09-04 15:04:35 +020029#include <osmocom/msc/gsm_data.h>
30#include <osmocom/msc/osmo_msc.h>
31#include <osmocom/msc/vlr.h>
Neels Hofmeyra99b4272017-11-21 17:13:23 +010032#include <osmocom/msc/mncc.h>
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010033
34extern bool _log_lines;
35#define _log(fmt, args...) do { \
36 if (_log_lines) \
37 fprintf(stderr, " %4d:%s: " fmt "\n", \
38 __LINE__, __FILE__, ## args ); \
39 else \
40 fprintf(stderr, fmt "\n", ## args ); \
41 } while (false)
42
43/* btw means "by the way", the test tells the log what's happening.
44 * BTW() marks a larger section, btw() is the usual logging. */
45#define BTW(fmt, args...) _log("---\n- " fmt, ## args )
46#define btw(fmt, args...) _log("- " fmt, ## args )
47#define log(fmt, args...) _log(" " fmt, ## args )
48
49#define comment_start() fprintf(stderr, "===== %s\n", __func__);
50#define comment_end() fprintf(stderr, "===== %s: SUCCESS\n\n", __func__);
51
52extern struct gsm_subscriber_connection *g_conn;
53extern struct gsm_network *net;
54extern struct gsm_bts *the_bts;
55extern void *msgb_ctx;
56
57extern enum ran_type rx_from_ran;
58
59extern const char *gsup_tx_expected;
60extern bool gsup_tx_confirmed;
61
62extern struct msgb *dtap_tx_expected;
63extern bool dtap_tx_confirmed;
64
65enum result_sent {
66 RES_NONE = 0,
67 RES_ACCEPT = 1,
68 RES_REJECT = 2,
69};
70extern enum result_sent lu_result_sent;
71extern enum result_sent cm_service_result_sent;
72
73extern bool auth_request_sent;
74extern const char *auth_request_expect_rand;
75extern const char *auth_request_expect_autn;
76
77extern bool cipher_mode_cmd_sent;
78extern bool cipher_mode_cmd_sent_with_imeisv;
79
80extern bool paging_sent;
81extern bool paging_stopped;
82
Philipp Maierfbf66102017-04-09 12:32:51 +020083extern bool iu_release_expected;
84extern bool iu_release_sent;
85extern bool bssap_clear_expected;
86extern bool bssap_clear_sent;
87
Neels Hofmeyra99b4272017-11-21 17:13:23 +010088extern uint32_t cc_to_mncc_tx_expected_msg_type;
89extern const char *cc_to_mncc_tx_expected_imsi;
90extern bool cc_to_mncc_tx_confirmed;
91extern uint32_t cc_to_mncc_tx_got_callref;
92
Philipp Maierfbf66102017-04-09 12:32:51 +020093static inline void expect_iu_release()
94{
95 iu_release_expected = true;
96 iu_release_sent = false;
97}
98
99static inline void expect_bssap_clear()
100{
101 bssap_clear_expected = true;
102 bssap_clear_sent = false;
103}
104
105static inline void expect_release_clear(enum ran_type via_ran)
106{
107 switch (via_ran) {
108 case RAN_GERAN_A:
109 expect_bssap_clear();
110 return;
111 case RAN_UTRAN_IU:
112 expect_iu_release();
113 return;
114 default:
115 OSMO_ASSERT(false);
116 break;
117 }
118}
119
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100120struct msc_vlr_test_cmdline_opts {
121 bool verbose;
122 int run_test_nr;
123};
124
125typedef void (* msc_vlr_test_func_t )(void);
126extern msc_vlr_test_func_t msc_vlr_tests[];
127
128struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex);
129
130void clear_vlr();
131bool conn_exists(struct gsm_subscriber_connection *conn);
132
133void dtap_expect_tx(const char *hex);
134void dtap_expect_tx_ussd(char *ussd_text);
135void paging_expect_imsi(const char *imsi);
136void paging_expect_tmsi(uint32_t tmsi);
137
138void ms_sends_msg(const char *hex);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200139void ms_sends_security_mode_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100140void gsup_rx(const char *rx_hex, const char *expect_tx_hex);
141void send_sms(struct vlr_subscr *receiver,
142 struct vlr_subscr *sender,
143 char *str);
144
145void thwart_rx_non_initial_requests();
146
147void check_talloc(void *msgb_ctx, void *tall_bsc_ctx, int expected_blocks);
148
149#define EXPECT_ACCEPTED(expect_accepted) do { \
150 if (g_conn) \
151 OSMO_ASSERT(conn_exists(g_conn)); \
152 bool accepted = msc_subscr_conn_is_accepted(g_conn); \
153 fprintf(stderr, "msc_subscr_conn_is_accepted() == %s\n", \
154 accepted ? "true" : "false"); \
155 OSMO_ASSERT(accepted == expect_accepted); \
156 } while (false)
157
158#define VERBOSE_ASSERT(val, expect_op, fmt) \
159 do { \
160 log(#val " == " fmt, (val)); \
161 OSMO_ASSERT((val) expect_op); \
162 } while (0);
163
164#define EXPECT_CONN_COUNT(N) VERBOSE_ASSERT(llist_count(&net->subscr_conns), == N, "%d")
165
166#define gsup_expect_tx(hex) do \
167{ \
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200168 if (gsup_tx_expected) { \
169 log("Previous expected GSUP tx was not confirmed!"); \
170 OSMO_ASSERT(!gsup_tx_expected); \
171 } \
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100172 if (!hex) \
173 break; \
174 gsup_tx_expected = hex; \
175 gsup_tx_confirmed = false; \
176} while (0)
177
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100178#define cc_to_mncc_expect_tx(imsi, msg_type) do \
179{ \
180 if (cc_to_mncc_tx_expected_msg_type) { \
181 log("Previous expected MNCC tx was not confirmed!"); \
182 OSMO_ASSERT(!cc_to_mncc_tx_expected_msg_type); \
183 } \
184 cc_to_mncc_tx_expected_imsi = imsi; \
185 cc_to_mncc_tx_expected_msg_type = msg_type; \
186 cc_to_mncc_tx_confirmed = false; \
187} while (0)
188
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100189void fake_time_start();
190
191/* as macro to get the test file's source line number */
192#define fake_time_passes(secs, usecs) do \
193{ \
194 struct timeval diff; \
195 osmo_gettimeofday_override_add(secs, usecs); \
196 timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \
197 btw("Total time passed: %d.%06d s", \
198 (int)diff.tv_sec, (int)diff.tv_usec); \
199 osmo_timers_prepare(); \
200 osmo_timers_update(); \
201} while (0)
202
203extern const struct timeval fake_time_start_time;