blob: 03aa3aeef79acdafc1585f4935c020ff0c2f0724 [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;
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
Neels Hofmeyrdfdc61d2018-03-02 00:40:58 +0100125typedef void (* msc_vlr_test_func_t )(void);
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100126extern 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
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100147#define EXPECT_ACCEPTED(expect_accepted) do { \
148 if (g_conn) \
149 OSMO_ASSERT(conn_exists(g_conn)); \
150 bool accepted = msc_subscr_conn_is_accepted(g_conn); \
151 fprintf(stderr, "msc_subscr_conn_is_accepted() == %s\n", \
152 accepted ? "true" : "false"); \
153 OSMO_ASSERT(accepted == expect_accepted); \
154 } while (false)
155
156#define VERBOSE_ASSERT(val, expect_op, fmt) \
157 do { \
158 log(#val " == " fmt, (val)); \
159 OSMO_ASSERT((val) expect_op); \
160 } while (0);
161
162#define EXPECT_CONN_COUNT(N) VERBOSE_ASSERT(llist_count(&net->subscr_conns), == N, "%d")
163
164#define gsup_expect_tx(hex) do \
165{ \
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200166 if (gsup_tx_expected) { \
167 log("Previous expected GSUP tx was not confirmed!"); \
168 OSMO_ASSERT(!gsup_tx_expected); \
169 } \
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100170 if (!hex) \
171 break; \
172 gsup_tx_expected = hex; \
173 gsup_tx_confirmed = false; \
174} while (0)
175
Neels Hofmeyra99b4272017-11-21 17:13:23 +0100176#define cc_to_mncc_expect_tx(imsi, msg_type) do \
177{ \
178 if (cc_to_mncc_tx_expected_msg_type) { \
179 log("Previous expected MNCC tx was not confirmed!"); \
180 OSMO_ASSERT(!cc_to_mncc_tx_expected_msg_type); \
181 } \
182 cc_to_mncc_tx_expected_imsi = imsi; \
183 cc_to_mncc_tx_expected_msg_type = msg_type; \
184 cc_to_mncc_tx_confirmed = false; \
185} while (0)
186
Neels Hofmeyr6a29d322017-01-25 15:04:16 +0100187void fake_time_start();
188
189/* as macro to get the test file's source line number */
190#define fake_time_passes(secs, usecs) do \
191{ \
192 struct timeval diff; \
193 osmo_gettimeofday_override_add(secs, usecs); \
194 timersub(&osmo_gettimeofday_override_time, &fake_time_start_time, &diff); \
195 btw("Total time passed: %d.%06d s", \
196 (int)diff.tv_sec, (int)diff.tv_usec); \
197 osmo_timers_prepare(); \
198 osmo_timers_update(); \
199} while (0)
200
201extern const struct timeval fake_time_start_time;