blob: a29e87065df35f2f3e8f52aaef5aed26dbccd2a5 [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
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +010049#define comment_start() fprintf(stderr, "===== %s\n", __func__);
50#define comment_end() fprintf(stderr, "===== %s: SUCCESS\n\n", __func__);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +010051
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;
Neels Hofmeyrdbabfd32018-03-10 02:06:47 +010079extern const char *cipher_mode_expect_kc;
80
81extern bool security_mode_ctrl_sent;
82extern const char *security_mode_expect_ck;
83extern const char *security_mode_expect_ik;
84
85static inline void expect_cipher_mode_cmd(const char *kc)
86{
87 cipher_mode_cmd_sent = false;
88 cipher_mode_expect_kc = kc;
89 /* make sure we don't mix up the two */
90 security_mode_ctrl_sent = false;
91}
92
93static inline void expect_security_mode_ctrl(const char *ck, const char *ik)
94{
95 security_mode_ctrl_sent = false;
96 security_mode_expect_ck = ck;
97 security_mode_expect_ik = ik;
98 /* make sure we don't mix up the two */
99 cipher_mode_cmd_sent = false;
100}
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100101
102extern bool paging_sent;
103extern bool paging_stopped;
104
Philipp Maierfbf66102017-04-09 12:32:51 +0200105extern bool iu_release_expected;
106extern bool iu_release_sent;
107extern bool bssap_clear_expected;
108extern bool bssap_clear_sent;
109
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100110extern uint32_t cc_to_mncc_tx_expected_msg_type;
111extern const char *cc_to_mncc_tx_expected_imsi;
112extern bool cc_to_mncc_tx_confirmed;
113extern uint32_t cc_to_mncc_tx_got_callref;
114
Neels Hofmeyrcbcf89c2018-03-13 17:52:07 +0100115extern struct gsm_mncc *on_call_release_mncc_sends_to_cc_data;
116
Philipp Maierfbf66102017-04-09 12:32:51 +0200117static inline void expect_iu_release()
118{
119 iu_release_expected = true;
120 iu_release_sent = false;
121}
122
123static inline void expect_bssap_clear()
124{
125 bssap_clear_expected = true;
126 bssap_clear_sent = false;
127}
128
129static inline void expect_release_clear(enum ran_type via_ran)
130{
131 switch (via_ran) {
132 case RAN_GERAN_A:
133 expect_bssap_clear();
134 return;
135 case RAN_UTRAN_IU:
136 expect_iu_release();
137 return;
138 default:
139 OSMO_ASSERT(false);
140 break;
141 }
142}
143
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100144struct msc_vlr_test_cmdline_opts {
145 bool verbose;
146 int run_test_nr;
147};
148
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100149typedef void (* msc_vlr_test_func_t )(void);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100150extern msc_vlr_test_func_t msc_vlr_tests[];
151
152struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex);
153
154void clear_vlr();
155bool conn_exists(struct gsm_subscriber_connection *conn);
156
157void dtap_expect_tx(const char *hex);
158void dtap_expect_tx_ussd(char *ussd_text);
159void paging_expect_imsi(const char *imsi);
160void paging_expect_tmsi(uint32_t tmsi);
161
162void ms_sends_msg(const char *hex);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200163void ms_sends_security_mode_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100164void gsup_rx(const char *rx_hex, const char *expect_tx_hex);
165void send_sms(struct vlr_subscr *receiver,
166 struct vlr_subscr *sender,
167 char *str);
168
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200169void bss_sends_clear_complete();
170void rnc_sends_release_complete();
171
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100172void thwart_rx_non_initial_requests();
173
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100174#define EXPECT_ACCEPTED(expect_accepted) do { \
175 if (g_conn) \
176 OSMO_ASSERT(conn_exists(g_conn)); \
177 bool accepted = msc_subscr_conn_is_accepted(g_conn); \
178 fprintf(stderr, "msc_subscr_conn_is_accepted() == %s\n", \
179 accepted ? "true" : "false"); \
180 OSMO_ASSERT(accepted == expect_accepted); \
181 } while (false)
182
183#define VERBOSE_ASSERT(val, expect_op, fmt) \
184 do { \
185 log(#val " == " fmt, (val)); \
186 OSMO_ASSERT((val) expect_op); \
187 } while (0);
188
189#define EXPECT_CONN_COUNT(N) VERBOSE_ASSERT(llist_count(&net->subscr_conns), == N, "%d")
190
191#define gsup_expect_tx(hex) do \
192{ \
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200193 if (gsup_tx_expected) { \
194 log("Previous expected GSUP tx was not confirmed!"); \
195 OSMO_ASSERT(!gsup_tx_expected); \
196 } \
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100197 if (!hex) \
198 break; \
199 gsup_tx_expected = hex; \
200 gsup_tx_confirmed = false; \
201} while (0)
202
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100203#define cc_to_mncc_expect_tx(imsi, msg_type) do \
204{ \
205 if (cc_to_mncc_tx_expected_msg_type) { \
206 log("Previous expected MNCC tx was not confirmed!"); \
207 OSMO_ASSERT(!cc_to_mncc_tx_expected_msg_type); \
208 } \
209 cc_to_mncc_tx_expected_imsi = imsi; \
210 cc_to_mncc_tx_expected_msg_type = msg_type; \
211 cc_to_mncc_tx_confirmed = false; \
212} while (0)
213
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100214void fake_time_start();
215
216/* as macro to get the test file's source line number */
217#define fake_time_passes(secs, usecs) do \
218{ \
219 struct timeval diff; \
220 osmo_gettimeofday_override_add(secs, usecs); \
221 timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \
222 btw("Total time passed: %d.%06d s", \
223 (int)diff.tv_sec, (int)diff.tv_usec); \
224 osmo_timers_prepare(); \
225 osmo_timers_update(); \
226} while (0)
227
228extern const struct timeval fake_time_start_time;
Neels Hofmeyr4068ab22018-04-01 20:55:54 +0200229
230#define ASSERT_RELEASE_CLEAR(via_ran) \
231 switch (via_ran) { \
232 case RAN_GERAN_A: \
233 VERBOSE_ASSERT(bssap_clear_sent, == true, "%d"); \
234 break; \
235 case RAN_UTRAN_IU: \
236 VERBOSE_ASSERT(iu_release_sent, == true, "%d"); \
237 break; \
238 default: \
239 OSMO_ASSERT(false); \
240 break; \
241 }
242
243static inline void bss_rnc_sends_release_clear_complete(enum ran_type via_ran)
244{
245 switch (via_ran) {
246 case RAN_GERAN_A:
247 bss_sends_clear_complete();
248 return;
249 case RAN_UTRAN_IU:
250 rnc_sends_release_complete();
251 return;
252 default:
253 OSMO_ASSERT(false);
254 break;
255 }
256}