blob: 858936c1c8f1136936252ed7a4d8c3897b237fce [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
Philipp Maierfbf66102017-04-09 12:32:51 +0200115static inline void expect_iu_release()
116{
117 iu_release_expected = true;
118 iu_release_sent = false;
119}
120
121static inline void expect_bssap_clear()
122{
123 bssap_clear_expected = true;
124 bssap_clear_sent = false;
125}
126
127static inline void expect_release_clear(enum ran_type via_ran)
128{
129 switch (via_ran) {
130 case RAN_GERAN_A:
131 expect_bssap_clear();
132 return;
133 case RAN_UTRAN_IU:
134 expect_iu_release();
135 return;
136 default:
137 OSMO_ASSERT(false);
138 break;
139 }
140}
141
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100142struct msc_vlr_test_cmdline_opts {
143 bool verbose;
144 int run_test_nr;
145};
146
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100147typedef void (* msc_vlr_test_func_t )(void);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100148extern msc_vlr_test_func_t msc_vlr_tests[];
149
150struct msgb *msgb_from_hex(const char *label, uint16_t size, const char *hex);
151
152void clear_vlr();
153bool conn_exists(struct gsm_subscriber_connection *conn);
154
155void dtap_expect_tx(const char *hex);
156void dtap_expect_tx_ussd(char *ussd_text);
157void paging_expect_imsi(const char *imsi);
158void paging_expect_tmsi(uint32_t tmsi);
159
160void ms_sends_msg(const char *hex);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200161void ms_sends_security_mode_complete();
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100162void gsup_rx(const char *rx_hex, const char *expect_tx_hex);
163void send_sms(struct vlr_subscr *receiver,
164 struct vlr_subscr *sender,
165 char *str);
166
167void thwart_rx_non_initial_requests();
168
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100169#define EXPECT_ACCEPTED(expect_accepted) do { \
170 if (g_conn) \
171 OSMO_ASSERT(conn_exists(g_conn)); \
172 bool accepted = msc_subscr_conn_is_accepted(g_conn); \
173 fprintf(stderr, "msc_subscr_conn_is_accepted() == %s\n", \
174 accepted ? "true" : "false"); \
175 OSMO_ASSERT(accepted == expect_accepted); \
176 } while (false)
177
178#define VERBOSE_ASSERT(val, expect_op, fmt) \
179 do { \
180 log(#val " == " fmt, (val)); \
181 OSMO_ASSERT((val) expect_op); \
182 } while (0);
183
184#define EXPECT_CONN_COUNT(N) VERBOSE_ASSERT(llist_count(&net->subscr_conns), == N, "%d")
185
186#define gsup_expect_tx(hex) do \
187{ \
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200188 if (gsup_tx_expected) { \
189 log("Previous expected GSUP tx was not confirmed!"); \
190 OSMO_ASSERT(!gsup_tx_expected); \
191 } \
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100192 if (!hex) \
193 break; \
194 gsup_tx_expected = hex; \
195 gsup_tx_confirmed = false; \
196} while (0)
197
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100198#define cc_to_mncc_expect_tx(imsi, msg_type) do \
199{ \
200 if (cc_to_mncc_tx_expected_msg_type) { \
201 log("Previous expected MNCC tx was not confirmed!"); \
202 OSMO_ASSERT(!cc_to_mncc_tx_expected_msg_type); \
203 } \
204 cc_to_mncc_tx_expected_imsi = imsi; \
205 cc_to_mncc_tx_expected_msg_type = msg_type; \
206 cc_to_mncc_tx_confirmed = false; \
207} while (0)
208
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100209void fake_time_start();
210
211/* as macro to get the test file's source line number */
212#define fake_time_passes(secs, usecs) do \
213{ \
214 struct timeval diff; \
215 osmo_gettimeofday_override_add(secs, usecs); \
216 timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \
217 btw("Total time passed: %d.%06d s", \
218 (int)diff.tv_sec, (int)diff.tv_usec); \
219 osmo_timers_prepare(); \
220 osmo_timers_update(); \
221} while (0)
222
223extern const struct timeval fake_time_start_time;