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