blob: c6187f9c551af38d056db6a81e668d7f8b00b9e8 [file] [log] [blame]
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +08001/*
2 * BSC NAT Message filtering
3 *
4 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freytherdf6143a2010-06-15 18:46:56 +08005 * (C) 2010 by On-Waves
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +08006 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * 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
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080012 * (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 General Public License for more details.
18 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * 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/>.
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080021 *
22 */
23
24
25#include <openbsc/debug.h>
26#include <openbsc/gsm_data.h>
27#include <openbsc/bsc_nat.h>
Holger Hans Peter Freytherc2b31ed2010-07-31 05:17:17 +080028#include <openbsc/bsc_nat_sccp.h>
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080029
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +020030#include <osmocom/core/application.h>
Pablo Neira Ayuso928cb332011-03-26 22:08:53 +010031#include <osmocom/core/talloc.h>
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +080032
Harald Welted5db12c2010-08-03 15:11:51 +020033#include <osmocom/sccp/sccp.h>
Pablo Neira Ayuso928cb332011-03-26 22:08:53 +010034#include <osmocom/gsm/protocol/gsm_08_08.h>
Holger Hans Peter Freyther30e1ae92010-07-30 02:53:14 +080035
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080036#include <stdio.h>
37
38/* test messages for ipa */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080039static uint8_t ipa_id[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080040 0x00, 0x01, 0xfe, 0x06,
41};
42
43/* SCCP messages are below */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080044static uint8_t gsm_reset[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080045 0x00, 0x12, 0xfd,
46 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
47 0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
48 0x01, 0x20,
49};
50
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080051static const uint8_t gsm_reset_ack[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080052 0x00, 0x13, 0xfd,
53 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
54 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
55 0x00, 0x01, 0x31,
56};
57
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080058static const uint8_t gsm_paging[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080059 0x00, 0x20, 0xfd,
60 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
61 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x10,
62 0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10,
63 0x02, 0x01, 0x31, 0x97, 0x61, 0x1a, 0x01, 0x06,
64};
65
66/* BSC -> MSC connection open */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080067static const uint8_t bssmap_cr[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080068 0x00, 0x2c, 0xfd,
69 0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x04, 0x02,
70 0x42, 0xfe, 0x0f, 0x1f, 0x00, 0x1d, 0x57, 0x05,
71 0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x12, 0xc3,
72 0x50, 0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33,
73 0x19, 0xa2, 0x08, 0x29, 0x47, 0x10, 0x02, 0x01,
74 0x31, 0x97, 0x61, 0x00
75};
76
77/* MSC -> BSC connection confirm */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080078static const uint8_t bssmap_cc[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080079 0x00, 0x0a, 0xfd,
80 0x02, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
81};
82
83/* MSC -> BSC released */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080084static const uint8_t bssmap_released[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080085 0x00, 0x0e, 0xfd,
86 0x04, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x00, 0x01, 0x0f,
87 0x02, 0x23, 0x42, 0x00,
88};
89
90/* BSC -> MSC released */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080091static const uint8_t bssmap_release_complete[] = {
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080092 0x00, 0x07, 0xfd,
93 0x05, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03
94};
95
Holger Hans Peter Freyther0a6f62f2010-04-06 10:22:01 +020096/* both directions IT timer */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +080097static const uint8_t connnection_it[] = {
Holger Hans Peter Freyther0a6f62f2010-04-06 10:22:01 +020098 0x00, 0x0b, 0xfd,
99 0x10, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03,
100 0x00, 0x00, 0x00, 0x00,
101};
102
Holger Hans Peter Freyther5e63f922010-04-21 15:45:26 +0800103/* error in both directions */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800104static const uint8_t proto_error[] = {
Holger Hans Peter Freyther5e63f922010-04-21 15:45:26 +0800105 0x00, 0x05, 0xfd,
106 0x0f, 0x22, 0x33, 0x44, 0x00,
107};
108
Holger Hans Peter Freythera128d912010-04-01 08:47:12 +0200109/* MGCP wrap... */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800110static const uint8_t mgcp_msg[] = {
Holger Hans Peter Freythera128d912010-04-01 08:47:12 +0200111 0x00, 0x03, 0xfc,
112 0x20, 0x20, 0x20,
113};
114
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800115/* location updating request */
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800116static const uint8_t bss_lu[] = {
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800117 0x00, 0x2e, 0xfd,
118 0x01, 0x91, 0x45, 0x14, 0x02, 0x02, 0x04, 0x02,
119 0x42, 0xfe, 0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05,
120 0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x14, 0xc3,
121 0x50, 0x17, 0x12, 0x05, 0x08, 0x70, 0x72, 0xf4,
122 0x80, 0xff, 0xfe, 0x30, 0x08, 0x29, 0x44, 0x50,
123 0x12, 0x03, 0x24, 0x01, 0x95, 0x00
124};
125
Holger Hans Peter Freytherf1924982010-05-15 23:54:04 +0800126/* paging response */
127static const uint8_t pag_resp[] = {
128 0x00, 0x2c, 0xfd, 0x01, 0xe5, 0x68,
129 0x14, 0x02, 0x02, 0x04, 0x02, 0x42, 0xfe, 0x0f,
130 0x1f, 0x00, 0x1d, 0x57, 0x05, 0x08, 0x00, 0x72,
131 0xf4, 0x80, 0x20, 0x16, 0xc3, 0x50, 0x17, 0x10,
132 0x06, 0x27, 0x01, 0x03, 0x30, 0x18, 0x96, 0x08,
133 0x29, 0x26, 0x30, 0x32, 0x11, 0x42, 0x01, 0x19,
134 0x00
135};
136
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800137struct filter_result {
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800138 const uint8_t *data;
Holger Hans Peter Freythere2c15202010-07-23 19:09:21 +0800139 const uint16_t length;
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100140 const int dir;
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800141 const int result;
142};
143
144static const struct filter_result results[] = {
145 {
146 .data = ipa_id,
147 .length = ARRAY_SIZE(ipa_id),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100148 .dir = DIR_MSC,
149 .result = 1,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800150 },
151 {
152 .data = gsm_reset,
153 .length = ARRAY_SIZE(gsm_reset),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100154 .dir = DIR_MSC,
155 .result = 1,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800156 },
157 {
158 .data = gsm_reset_ack,
159 .length = ARRAY_SIZE(gsm_reset_ack),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100160 .dir = DIR_BSC,
161 .result = 1,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800162 },
163 {
164 .data = gsm_paging,
165 .length = ARRAY_SIZE(gsm_paging),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100166 .dir = DIR_BSC,
167 .result = 0,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800168 },
169 {
170 .data = bssmap_cr,
171 .length = ARRAY_SIZE(bssmap_cr),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100172 .dir = DIR_MSC,
173 .result = 0,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800174 },
175 {
176 .data = bssmap_cc,
177 .length = ARRAY_SIZE(bssmap_cc),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100178 .dir = DIR_BSC,
179 .result = 0,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800180 },
181 {
182 .data = bssmap_released,
183 .length = ARRAY_SIZE(bssmap_released),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100184 .dir = DIR_MSC,
185 .result = 0,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800186 },
187 {
188 .data = bssmap_release_complete,
189 .length = ARRAY_SIZE(bssmap_release_complete),
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100190 .dir = DIR_BSC,
191 .result = 0,
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800192 },
Holger Hans Peter Freythera128d912010-04-01 08:47:12 +0200193 {
194 .data = mgcp_msg,
195 .length = ARRAY_SIZE(mgcp_msg),
196 .dir = DIR_MSC,
197 .result = 0,
198 },
Holger Hans Peter Freyther0a6f62f2010-04-06 10:22:01 +0200199 {
200 .data = connnection_it,
201 .length = ARRAY_SIZE(connnection_it),
202 .dir = DIR_BSC,
203 .result = 0,
204 },
205 {
206 .data = connnection_it,
207 .length = ARRAY_SIZE(connnection_it),
208 .dir = DIR_MSC,
209 .result = 0,
210 },
Holger Hans Peter Freyther5e63f922010-04-21 15:45:26 +0800211 {
212 .data = proto_error,
213 .length = ARRAY_SIZE(proto_error),
214 .dir = DIR_BSC,
215 .result = 0,
216 },
217 {
218 .data = proto_error,
219 .length = ARRAY_SIZE(proto_error),
220 .dir = DIR_MSC,
221 .result = 0,
222 },
223
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800224};
225
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800226static void test_filter(void)
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800227{
228 int i;
229
230
231 /* start testinh with proper messages */
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100232 printf("Testing BSS Filtering.\n");
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800233 for (i = 0; i < ARRAY_SIZE(results); ++i) {
234 int result;
235 struct bsc_nat_parsed *parsed;
236 struct msgb *msg = msgb_alloc(4096, "test-message");
237
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100238 printf("Going to test item: %d\n", i);
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800239 memcpy(msg->data, results[i].data, results[i].length);
240 msg->l2h = msgb_put(msg, results[i].length);
241
242 parsed = bsc_nat_parse(msg);
243 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100244 printf("FAIL: Failed to parse the message\n");
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800245 continue;
246 }
247
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100248 result = bsc_nat_filter_ipa(results[i].dir, msg, parsed);
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800249 if (result != results[i].result) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100250 printf("FAIL: Not the expected result got: %d wanted: %d\n",
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800251 result, results[i].result);
252 }
253
254 msgb_free(msg);
255 }
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800256}
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800257
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800258#include "bsc_data.c"
259
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800260static void copy_to_msg(struct msgb *msg, const uint8_t *data, unsigned int length)
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800261{
262 msgb_reset(msg);
263 msg->l2h = msgb_put(msg, length);
264 memcpy(msg->l2h, data, msgb_l2len(msg));
265}
266
Holger Hans Peter Freyther50be1a92012-01-10 22:31:39 +0100267static void verify_msg(struct msgb *out, const uint8_t *ref, int ref_len)
268{
269 if (out->len != ref_len) {
Holger Hans Peter Freytherbe530122012-01-18 17:20:23 +0100270 printf("FAIL: The size should match: %d vs. %d\n",
271 out->len, ref_len);
272 printf("%s\n", osmo_hexdump(out->data, out->len));
273 printf("Wanted\n");
274 printf("%s\n", osmo_hexdump(ref, ref_len));
Holger Hans Peter Freyther50be1a92012-01-10 22:31:39 +0100275 abort();
276 }
277
278 if (memcmp(out->data, ref, out->len) != 0) {
279 printf("FAIL: the data should be changed.\n");
280 printf("%s\n", osmo_hexdump(out->data, out->len));
281 printf("Wanted\n");
282 printf("%s\n", osmo_hexdump(ref, ref_len));
283 abort();
284 }
285}
286
287
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800288#define VERIFY(con_found, con, msg, ver, str) \
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100289 if (!con_found) { \
290 printf("Failed to find connection.\n"); \
291 abort(); \
292 } \
293 if (con_found->bsc != con) { \
294 printf("Got connection of the wrong BSC: %d\n", \
295 con_found->bsc->cfg->nr); \
296 abort(); \
297 } \
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800298 if (memcmp(msg->data, ver, sizeof(ver)) != 0) { \
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100299 printf("Failed to patch the %s msg.\n", str); \
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800300 abort(); \
301 }
302
303/* test conn tracking once */
304static void test_contrack()
305{
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800306 struct bsc_nat *nat;
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800307 struct bsc_connection *con;
308 struct sccp_connections *con_found;
Holger Hans Peter Freytherfa20c942010-05-16 16:51:31 +0800309 struct sccp_connections *rc_con;
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800310 struct bsc_nat_parsed *parsed;
311 struct msgb *msg;
312
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100313 printf("Testing connection tracking.\n");
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800314 nat = bsc_nat_alloc();
315 con = bsc_connection_alloc(nat);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800316 con->cfg = bsc_config_alloc(nat, "foo");
317 bsc_config_add_lac(con->cfg, 23);
318 bsc_config_add_lac(con->cfg, 49);
319 bsc_config_add_lac(con->cfg, 42);
320 bsc_config_del_lac(con->cfg, 49);
321 bsc_config_add_lac(con->cfg, 1111);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800322 msg = msgb_alloc(4096, "test");
323
324 /* 1.) create a connection */
325 copy_to_msg(msg, bsc_cr, sizeof(bsc_cr));
326 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freytherb5513ca2010-04-21 18:56:12 +0800327 con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800328 if (con_found != NULL) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100329 printf("Con should not exist realref(%u)\n",
330 sccp_src_ref_to_int(&con_found->real_ref));
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800331 abort();
332 }
Holger Hans Peter Freytherfa20c942010-05-16 16:51:31 +0800333 rc_con = create_sccp_src_ref(con, parsed);
334 if (!rc_con) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100335 printf("Failed to create a ref\n");
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800336 abort();
337 }
Holger Hans Peter Freytherb5513ca2010-04-21 18:56:12 +0800338 con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100339 if (!con_found) {
340 printf("Failed to find connection.\n");
341 abort();
342 }
343 if (con_found->bsc != con) {
344 printf("Got connection of the wrong BSC: %d\n",
345 con_found->bsc->cfg->nr);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800346 abort();
347 }
Holger Hans Peter Freytherfa20c942010-05-16 16:51:31 +0800348 if (con_found != rc_con) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100349 printf("Failed to find the right connection.\n");
Holger Hans Peter Freytherfa20c942010-05-16 16:51:31 +0800350 abort();
351 }
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800352 if (memcmp(msg->data, bsc_cr_patched, sizeof(bsc_cr_patched)) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100353 printf("Failed to patch the BSC CR msg.\n");
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800354 abort();
355 }
356 talloc_free(parsed);
357
358 /* 2.) get the cc */
359 copy_to_msg(msg, msc_cc, sizeof(msc_cc));
360 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800361 con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
362 VERIFY(con_found, con, msg, msc_cc_patched, "MSC CC");
363 if (update_sccp_src_ref(con_found, parsed) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100364 printf("Failed to update the SCCP con.\n");
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800365 abort();
366 }
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800367
368 /* 3.) send some data */
369 copy_to_msg(msg, bsc_dtap, sizeof(bsc_dtap));
370 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freytherb5513ca2010-04-21 18:56:12 +0800371 con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800372 VERIFY(con_found, con, msg, bsc_dtap_patched, "BSC DTAP");
373
374 /* 4.) receive some data */
375 copy_to_msg(msg, msc_dtap, sizeof(msc_dtap));
376 parsed = bsc_nat_parse(msg);
377 con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
378 VERIFY(con_found, con, msg, msc_dtap_patched, "MSC DTAP");
379
380 /* 5.) close the connection */
381 copy_to_msg(msg, msc_rlsd, sizeof(msc_rlsd));
382 parsed = bsc_nat_parse(msg);
383 con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
384 VERIFY(con_found, con, msg, msc_rlsd_patched, "MSC RLSD");
385
386 /* 6.) confirm the connection close */
387 copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
388 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freytherb5513ca2010-04-21 18:56:12 +0800389 con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100390 if (!con_found) {
391 printf("Failed to find connection.\n");
392 abort();
393 }
394 if (con_found->bsc != con) {
395 printf("Got connection of the wrong BSC: %d\n",
396 con_found->bsc->cfg->nr);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800397 abort();
398 }
399 if (memcmp(msg->data, bsc_rlc_patched, sizeof(bsc_rlc_patched)) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100400 printf("Failed to patch the BSC CR msg.\n");
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800401 abort();
402 }
403 remove_sccp_src_ref(con, msg, parsed);
Holger Hans Peter Freyther9d518552010-04-05 21:44:51 +0200404 talloc_free(parsed);
405
406 copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
407 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freytherb5513ca2010-04-21 18:56:12 +0800408 con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800409
410 /* verify that it is gone */
411 if (con_found != NULL) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100412 printf("Con should not exist real_ref(%u)\n",
413 sccp_src_ref_to_int(&con_found->real_ref));
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800414 abort();
415 }
416 talloc_free(parsed);
417
418
Holger Hans Peter Freyther9212d9d2011-02-27 11:18:41 +0100419 bsc_config_free(con->cfg);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +0800420 talloc_free(nat);
421 msgb_free(msg);
422}
423
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200424static void test_paging(void)
425{
426 struct bsc_nat *nat;
427 struct bsc_connection *con;
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800428 struct bsc_config *cfg;
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200429
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100430 printf("Testing paging by lac.\n");
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200431
432 nat = bsc_nat_alloc();
433 con = bsc_connection_alloc(nat);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800434 cfg = bsc_config_alloc(nat, "unknown");
435 con->cfg = cfg;
436 bsc_config_add_lac(cfg, 23);
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200437 con->authenticated = 1;
438 llist_add(&con->list_entry, &nat->bsc_connections);
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200439
440 /* Test it by not finding it */
Holger Hans Peter Freyther1ffe98c2011-05-02 16:20:32 +0200441 if (bsc_config_handles_lac(cfg, 8213) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100442 printf("Should not be handled.\n");
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200443 abort();
444 }
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200445
446 /* Test by finding it */
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800447 bsc_config_del_lac(cfg, 23);
448 bsc_config_add_lac(cfg, 8213);
Holger Hans Peter Freyther1ffe98c2011-05-02 16:20:32 +0200449 if (bsc_config_handles_lac(cfg, 8213) == 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100450 printf("Should have found it.\n");
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200451 abort();
452 }
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +0200453}
454
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100455static void test_mgcp_allocations(void)
456{
457#if 0
458 struct bsc_connection *bsc;
459 struct bsc_nat *nat;
460 struct sccp_connections con;
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100461 int i, j, multiplex;
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100462
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100463 printf("Testing MGCP.\n");
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100464 memset(&con, 0, sizeof(con));
465
466 nat = bsc_nat_alloc();
467 nat->bsc_endpoints = talloc_zero_array(nat,
468 struct bsc_endpoint,
469 65);
470 nat->mgcp_cfg = mgcp_config_alloc();
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100471 nat->mgcp_cfg->trunk.number_endpoints = 64;
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100472
473 bsc = bsc_connection_alloc(nat);
474 bsc->cfg = bsc_config_alloc(nat, "foo");
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100475 bsc->cfg->max_endpoints = 60;
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100476 bsc_config_add_lac(bsc->cfg, 2323);
477 bsc->last_endpoint = 0x22;
478 con.bsc = bsc;
479
480 bsc_init_endps_if_needed(bsc);
481
482 i = 1;
483 do {
484 if (bsc_assign_endpoint(bsc, &con) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100485 printf("failed to allocate... on iteration %d\n", i);
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100486 break;
487 }
488 ++i;
489 } while(1);
490
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100491 multiplex = bsc_mgcp_nr_multiplexes(bsc->cfg->max_endpoints);
492 for (i = 0; i < multiplex; ++i) {
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100493 for (j = 0; j < 32; ++j)
494 printf("%d", bsc->_endpoint_status[i*32 + j]);
495 printf(": %d of %d\n", i*32 + 32, 32 * 8);
496 }
497#endif
498}
499
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200500static void test_mgcp_ass_tracking(void)
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800501{
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800502 struct bsc_connection *bsc;
503 struct bsc_nat *nat;
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800504 struct sccp_connections con;
505 struct bsc_nat_parsed *parsed;
506 struct msgb *msg;
507
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100508 printf("Testing MGCP.\n");
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800509 memset(&con, 0, sizeof(con));
510
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800511 nat = bsc_nat_alloc();
512 nat->bsc_endpoints = talloc_zero_array(nat,
513 struct bsc_endpoint,
514 33);
Holger Hans Peter Freyther7e0cc502011-02-25 12:43:58 +0100515 nat->mgcp_cfg = mgcp_config_alloc();
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100516 nat->mgcp_cfg->trunk.number_endpoints = 64;
Holger Hans Peter Freyther7e0cc502011-02-25 12:43:58 +0100517
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800518 bsc = bsc_connection_alloc(nat);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800519 bsc->cfg = bsc_config_alloc(nat, "foo");
520 bsc_config_add_lac(bsc->cfg, 2323);
Holger Hans Peter Freyther86c1db62011-02-25 17:10:25 +0100521 bsc->last_endpoint = 0x1e;
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800522 con.bsc = bsc;
523
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800524 msg = msgb_alloc(4096, "foo");
525 copy_to_msg(msg, ass_cmd, sizeof(ass_cmd));
526 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freythercd702372010-09-20 01:21:51 +0800527
528 if (msg->l2h[16] != 0 ||
529 msg->l2h[17] != 0x1) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100530 printf("Input is not as expected.. %s 0x%x\n",
Pablo Neira Ayusoc0d17f22011-05-07 12:12:48 +0200531 osmo_hexdump(msg->l2h, msgb_l2len(msg)),
Holger Hans Peter Freythercd702372010-09-20 01:21:51 +0800532 msg->l2h[17]);
533 abort();
534 }
535
Holger Hans Peter Freyther45fd07d2010-08-28 18:22:14 +0800536 if (bsc_mgcp_assign_patch(&con, msg) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100537 printf("Failed to handle assignment.\n");
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800538 abort();
539 }
540
Holger Hans Peter Freythercd702372010-09-20 01:21:51 +0800541 if (con.msc_endp != 1) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100542 printf("Timeslot should be 1.\n");
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800543 abort();
544 }
545
Holger Hans Peter Freyther86c1db62011-02-25 17:10:25 +0100546 if (con.bsc_endp != 0x1) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100547 printf("Assigned timeslot should have been 1.\n");
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800548 abort();
549 }
Holger Hans Peter Freyther86c1db62011-02-25 17:10:25 +0100550 if (con.bsc->_endpoint_status[0x1] != 1) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100551 printf("The status on the BSC is wrong.\n");
Holger Hans Peter Freyther45fd07d2010-08-28 18:22:14 +0800552 abort();
553 }
554
Holger Hans Peter Freythercd702372010-09-20 01:21:51 +0800555 int multiplex, timeslot;
Holger Hans Peter Freyther86c1db62011-02-25 17:10:25 +0100556 mgcp_endpoint_to_timeslot(0x1, &multiplex, &timeslot);
Holger Hans Peter Freythercd702372010-09-20 01:21:51 +0800557
558 uint16_t cic = htons(timeslot & 0x1f);
559 if (memcmp(&cic, &msg->l2h[16], sizeof(cic)) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100560 printf("Message was not patched properly\n");
561 printf("data cic: 0x%x %s\n", cic, osmo_hexdump(msg->l2h, msgb_l2len(msg)));
Holger Hans Peter Freythercd702372010-09-20 01:21:51 +0800562 abort();
563 }
564
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800565 talloc_free(parsed);
566
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800567 bsc_mgcp_dlcx(&con);
Holger Hans Peter Freytherd2df4ca2010-09-19 20:54:21 +0800568 if (con.bsc_endp != -1 || con.msc_endp != -1 ||
Holger Hans Peter Freyther86c1db62011-02-25 17:10:25 +0100569 con.bsc->_endpoint_status[1] != 0 || con.bsc->last_endpoint != 0x1) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100570 printf("Clearing should remove the mapping.\n");
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800571 abort();
572 }
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800573
Holger Hans Peter Freyther9212d9d2011-02-27 11:18:41 +0100574 bsc_config_free(bsc->cfg);
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800575 talloc_free(nat);
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800576}
577
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200578/* test the code to find a given connection */
579static void test_mgcp_find(void)
580{
581 struct bsc_nat *nat;
582 struct bsc_connection *con;
583 struct sccp_connections *sccp_con;
584
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100585 printf("Testing finding of a BSC Connection\n");
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200586
587 nat = bsc_nat_alloc();
588 con = bsc_connection_alloc(nat);
589 llist_add(&con->list_entry, &nat->bsc_connections);
590
591 sccp_con = talloc_zero(con, struct sccp_connections);
Holger Hans Peter Freytherf4b34392010-08-28 16:08:39 +0800592 sccp_con->msc_endp = 12;
593 sccp_con->bsc_endp = 12;
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200594 sccp_con->bsc = con;
595 llist_add(&sccp_con->list_entry, &nat->sccp_connections);
596
597 if (bsc_mgcp_find_con(nat, 11) != NULL) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100598 printf("Found the wrong connection.\n");
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200599 abort();
600 }
601
Holger Hans Peter Freyther08a1b162010-04-18 02:26:16 +0800602 if (bsc_mgcp_find_con(nat, 12) != sccp_con) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100603 printf("Didn't find the connection\n");
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200604 abort();
605 }
606
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200607 /* free everything */
608 talloc_free(nat);
609}
610
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200611static void test_mgcp_rewrite(void)
612{
613 int i;
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200614 struct msgb *output;
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100615 printf("Testing rewriting MGCP messages.\n");
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200616
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200617 for (i = 0; i < ARRAY_SIZE(mgcp_messages); ++i) {
618 const char *orig = mgcp_messages[i].orig;
619 const char *patc = mgcp_messages[i].patch;
620 const char *ip = mgcp_messages[i].ip;
621 const int port = mgcp_messages[i].port;
622
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200623 char *input = strdup(orig);
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200624
Holger Hans Peter Freytherf7c86c52010-08-30 13:44:32 +0800625 output = bsc_mgcp_rewrite(input, strlen(input), 0x1e, ip, port);
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200626 if (msgb_l2len(output) != strlen(patc)) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100627 printf("Wrong sizes for test: %d %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig));
628 printf("String '%s' vs '%s'\n", (const char *) output->l2h, patc);
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200629 abort();
630 }
631
632 if (memcmp(output->l2h, patc, msgb_l2len(output)) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100633 printf("Broken on %d msg: '%s'\n", i, (const char *) output->l2h);
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200634 abort();
635 }
636
637 msgb_free(output);
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200638 free(input);
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200639 }
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200640}
641
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200642static void test_mgcp_parse(void)
643{
644 int code, ci;
645 char transaction[60];
646
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100647 printf("Testing MGCP response parsing.\n");
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200648
649 if (bsc_mgcp_parse_response(crcx_resp, &code, transaction) != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100650 printf("Failed to parse CRCX resp.\n");
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200651 abort();
652 }
653
654 if (code != 200) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100655 printf("Failed to parse the CODE properly. Got: %d\n", code);
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200656 abort();
657 }
658
659 if (strcmp(transaction, "23265295") != 0) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100660 printf("Failed to parse transaction id: '%s'\n", transaction);
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200661 abort();
662 }
663
664 ci = bsc_mgcp_extract_ci(crcx_resp);
665 if (ci != 1) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100666 printf("Failed to parse the CI. Got: %d\n", ci);
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200667 abort();
668 }
669}
670
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800671struct cr_filter {
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800672 const uint8_t *data;
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800673 int length;
674 int result;
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800675 int contype;
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800676
677 const char *bsc_imsi_allow;
678 const char *bsc_imsi_deny;
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800679 const char *nat_imsi_deny;
680};
681
682static struct cr_filter cr_filter[] = {
683 {
684 .data = bssmap_cr,
685 .length = sizeof(bssmap_cr),
Holger Hans Peter Freytherd880f542010-09-15 01:42:07 +0800686 .result = 1,
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800687 .contype = NAT_CON_TYPE_CM_SERV_REQ,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800688 },
689 {
690 .data = bss_lu,
691 .length = sizeof(bss_lu),
Holger Hans Peter Freytherd880f542010-09-15 01:42:07 +0800692 .result = 1,
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800693 .contype = NAT_CON_TYPE_LU,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800694 },
695 {
Holger Hans Peter Freytherf1924982010-05-15 23:54:04 +0800696 .data = pag_resp,
697 .length = sizeof(pag_resp),
Holger Hans Peter Freytherd880f542010-09-15 01:42:07 +0800698 .result = 1,
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800699 .contype = NAT_CON_TYPE_PAG_RESP,
Holger Hans Peter Freytherf1924982010-05-15 23:54:04 +0800700 },
701 {
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800702 /* nat deny is before blank/null BSC */
703 .data = bss_lu,
704 .length = sizeof(bss_lu),
705 .result = -3,
706 .nat_imsi_deny = "[0-9]*",
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800707 .contype = NAT_CON_TYPE_LU,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800708 },
709 {
Holger Hans Peter Freythera0aeaa72010-05-14 23:07:58 +0800710 /* BSC allow is before NAT deny */
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800711 .data = bss_lu,
712 .length = sizeof(bss_lu),
Holger Hans Peter Freytherd880f542010-09-15 01:42:07 +0800713 .result = 1,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800714 .nat_imsi_deny = "[0-9]*",
Holger Hans Peter Freythera0aeaa72010-05-14 23:07:58 +0800715 .bsc_imsi_allow = "2440[0-9]*",
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800716 .contype = NAT_CON_TYPE_LU,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800717 },
718 {
719 /* BSC allow is before NAT deny */
720 .data = bss_lu,
721 .length = sizeof(bss_lu),
Holger Hans Peter Freytherd880f542010-09-15 01:42:07 +0800722 .result = 1,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800723 .bsc_imsi_allow = "[0-9]*",
724 .nat_imsi_deny = "[0-9]*",
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800725 .contype = NAT_CON_TYPE_LU,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800726 },
727 {
728 /* filter as deny is first */
729 .data = bss_lu,
730 .length = sizeof(bss_lu),
Holger Hans Peter Freyther1fd60632010-10-19 20:55:33 +0200731 .result = 1,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800732 .bsc_imsi_deny = "[0-9]*",
733 .bsc_imsi_allow = "[0-9]*",
734 .nat_imsi_deny = "[0-9]*",
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800735 .contype = NAT_CON_TYPE_LU,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800736 },
Holger Hans Peter Freyther1fd60632010-10-19 20:55:33 +0200737 {
738 /* deny by nat rule */
739 .data = bss_lu,
740 .length = sizeof(bss_lu),
741 .result = -3,
742 .bsc_imsi_deny = "000[0-9]*",
743 .nat_imsi_deny = "[0-9]*",
744 .contype = NAT_CON_TYPE_LU,
745 },
746 {
747 /* deny by bsc rule */
748 .data = bss_lu,
749 .length = sizeof(bss_lu),
750 .result = -2,
751 .bsc_imsi_deny = "[0-9]*",
752 .contype = NAT_CON_TYPE_LU,
753 },
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800754
755};
756
Holger Hans Peter Freyther0c08db12010-05-14 08:12:57 +0800757static void test_cr_filter()
758{
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800759 int i, res, contype;
Holger Hans Peter Freyther0c08db12010-05-14 08:12:57 +0800760 struct msgb *msg = msgb_alloc(4096, "test_cr_filter");
Holger Hans Peter Freyther0c08db12010-05-14 08:12:57 +0800761 struct bsc_nat_parsed *parsed;
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800762 struct bsc_nat_acc_lst *nat_lst, *bsc_lst;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800763 struct bsc_nat_acc_lst_entry *nat_entry, *bsc_entry;
Holger Hans Peter Freyther0c08db12010-05-14 08:12:57 +0800764
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800765 struct bsc_nat *nat = bsc_nat_alloc();
766 struct bsc_connection *bsc = bsc_connection_alloc(nat);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800767 bsc->cfg = bsc_config_alloc(nat, "foo");
768 bsc_config_add_lac(bsc->cfg, 1234);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800769 bsc->cfg->acc_lst_name = "bsc";
770 nat->acc_lst_name = "nat";
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800771
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800772 nat_lst = bsc_nat_acc_lst_get(nat, "nat");
773 bsc_lst = bsc_nat_acc_lst_get(nat, "bsc");
774
775 bsc_entry = bsc_nat_acc_lst_entry_create(bsc_lst);
776 nat_entry = bsc_nat_acc_lst_entry_create(nat_lst);
777
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800778 for (i = 0; i < ARRAY_SIZE(cr_filter); ++i) {
Holger Hans Peter Freyther749497e2010-09-29 01:19:42 +0800779 char *imsi;
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800780 msgb_reset(msg);
781 copy_to_msg(msg, cr_filter[i].data, cr_filter[i].length);
782
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800783 nat_lst = bsc_nat_acc_lst_get(nat, "nat");
784 bsc_lst = bsc_nat_acc_lst_get(nat, "bsc");
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800785
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200786 if (gsm_parse_reg(nat_entry, &nat_entry->imsi_deny_re, &nat_entry->imsi_deny,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800787 cr_filter[i].nat_imsi_deny ? 1 : 0,
Holger Hans Peter Freyther4c9557e2011-04-04 19:19:26 +0200788 &cr_filter[i].nat_imsi_deny) != 0)
789 abort();
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200790 if (gsm_parse_reg(bsc_entry, &bsc_entry->imsi_allow_re, &bsc_entry->imsi_allow,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800791 cr_filter[i].bsc_imsi_allow ? 1 : 0,
Holger Hans Peter Freyther4c9557e2011-04-04 19:19:26 +0200792 &cr_filter[i].bsc_imsi_allow) != 0)
793 abort();
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +0200794 if (gsm_parse_reg(bsc_entry, &bsc_entry->imsi_deny_re, &bsc_entry->imsi_deny,
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800795 cr_filter[i].bsc_imsi_deny ? 1 : 0,
Holger Hans Peter Freyther4c9557e2011-04-04 19:19:26 +0200796 &cr_filter[i].bsc_imsi_deny) != 0)
797 abort();
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800798
799 parsed = bsc_nat_parse(msg);
800 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100801 printf("FAIL: Failed to parse the message\n");
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800802 abort();
803 }
804
Holger Hans Peter Freyther749497e2010-09-29 01:19:42 +0800805 res = bsc_nat_filter_sccp_cr(bsc, msg, parsed, &contype, &imsi);
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800806 if (res != cr_filter[i].result) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100807 printf("FAIL: Wrong result %d for test %d.\n", res, i);
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800808 abort();
809 }
810
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800811 if (contype != cr_filter[i].contype) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100812 printf("FAIL: Wrong contype %d for test %d.\n", res, contype);
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800813 abort();
814 }
815
Holger Hans Peter Freyther749497e2010-09-29 01:19:42 +0800816 talloc_steal(parsed, imsi);
Holger Hans Peter Freyther34a96ae2010-05-14 19:49:35 +0800817 talloc_free(parsed);
Holger Hans Peter Freyther0c08db12010-05-14 08:12:57 +0800818 }
819
Holger Hans Peter Freyther0c08db12010-05-14 08:12:57 +0800820 msgb_free(msg);
821}
822
Holger Hans Peter Freyther32685402010-09-15 05:20:40 +0800823static void test_dt_filter()
824{
825 int i;
826 struct msgb *msg = msgb_alloc(4096, "test_dt_filter");
827 struct bsc_nat_parsed *parsed;
828
829 struct bsc_nat *nat = bsc_nat_alloc();
830 struct bsc_connection *bsc = bsc_connection_alloc(nat);
831 struct sccp_connections *con = talloc_zero(0, struct sccp_connections);
832
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800833 bsc->cfg = bsc_config_alloc(nat, "foo");
834 bsc_config_add_lac(bsc->cfg, 23);
Holger Hans Peter Freyther32685402010-09-15 05:20:40 +0800835 con->bsc = bsc;
836
837 msgb_reset(msg);
838 copy_to_msg(msg, id_resp, ARRAY_SIZE(id_resp));
839
840 parsed = bsc_nat_parse(msg);
841 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100842 printf("FAIL: Could not parse ID resp\n");
Holger Hans Peter Freyther32685402010-09-15 05:20:40 +0800843 abort();
844 }
845
846 if (parsed->bssap != BSSAP_MSG_DTAP) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100847 printf("FAIL: It should be dtap\n");
Holger Hans Peter Freyther32685402010-09-15 05:20:40 +0800848 abort();
849 }
850
851 /* gsm_type is actually the size of the dtap */
852 if (parsed->gsm_type < msgb_l3len(msg) - 3) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100853 printf("FAIL: Not enough space for the content\n");
Holger Hans Peter Freyther32685402010-09-15 05:20:40 +0800854 abort();
855 }
856
857 if (bsc_nat_filter_dt(bsc, msg, con, parsed) != 1) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100858 printf("FAIL: Should have passed..\n");
Holger Hans Peter Freyther32685402010-09-15 05:20:40 +0800859 abort();
860 }
861
862 /* just some basic length checking... */
863 for (i = ARRAY_SIZE(id_resp); i >= 0; --i) {
864 msgb_reset(msg);
865 copy_to_msg(msg, id_resp, ARRAY_SIZE(id_resp));
866
867 parsed = bsc_nat_parse(msg);
868 if (!parsed)
869 continue;
870
871 con->imsi_checked = 0;
872 bsc_nat_filter_dt(bsc, msg, con, parsed);
873 }
874}
875
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200876static void test_setup_rewrite()
877{
878 struct msgb *msg = msgb_alloc(4096, "test_dt_filter");
879 struct msgb *out;
880 struct bsc_nat_parsed *parsed;
881 const char *imsi = "27408000001234";
882
883 struct bsc_nat *nat = bsc_nat_alloc();
884
885 /* a fake list */
Pablo Neira Ayusoab46cf32011-05-07 13:11:20 +0200886 struct osmo_config_list entries;
887 struct osmo_config_entry entry;
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200888
889 INIT_LLIST_HEAD(&entries.entry);
890 entry.mcc = "274";
891 entry.mnc = "08";
892 entry.option = "^0([1-9])";
893 entry.text = "0049";
894 llist_add_tail(&entry.list, &entries.entry);
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200895 bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries);
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200896
897 /* verify that nothing changed */
898 msgb_reset(msg);
899 copy_to_msg(msg, cc_setup_international, ARRAY_SIZE(cc_setup_international));
900 parsed = bsc_nat_parse(msg);
901 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100902 printf("FAIL: Could not parse ID resp\n");
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200903 abort();
904 }
905
Holger Hans Peter Freytherdf8e6e92011-05-27 14:09:55 +0200906 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200907 if (msg != out) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100908 printf("FAIL: The message should not have been changed\n");
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200909 abort();
910 }
911
Holger Hans Peter Freyther50be1a92012-01-10 22:31:39 +0100912 verify_msg(out, cc_setup_international, ARRAY_SIZE(cc_setup_international));
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200913 talloc_free(parsed);
914
915 /* verify that something in the message changes */
916 msgb_reset(msg);
917 copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national));
918 parsed = bsc_nat_parse(msg);
919 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100920 printf("FAIL: Could not parse ID resp\n");
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200921 abort();
922 }
923
Holger Hans Peter Freytherdf8e6e92011-05-27 14:09:55 +0200924 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200925 if (!out) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100926 printf("FAIL: A new message should be created.\n");
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200927 abort();
928 }
929
930 if (msg == out) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100931 printf("FAIL: The message should have changed\n");
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200932 abort();
933 }
934
Holger Hans Peter Freyther50be1a92012-01-10 22:31:39 +0100935 verify_msg(out, cc_setup_national_patched, ARRAY_SIZE(cc_setup_national_patched));
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200936 msgb_free(out);
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200937
938 /* Make sure that a wildcard is matching */
939 entry.mnc = "*";
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200940 bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries);
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200941 msg = msgb_alloc(4096, "test_dt_filter");
942 copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national));
943 parsed = bsc_nat_parse(msg);
944 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100945 printf("FAIL: Could not parse ID resp\n");
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200946 abort();
947 }
948
Holger Hans Peter Freytherdf8e6e92011-05-27 14:09:55 +0200949 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200950 if (!out) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100951 printf("FAIL: A new message should be created.\n");
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200952 abort();
953 }
954
955 if (msg == out) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100956 printf("FAIL: The message should have changed\n");
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200957 abort();
958 }
959
Holger Hans Peter Freyther50be1a92012-01-10 22:31:39 +0100960 verify_msg(out, cc_setup_national_patched, ARRAY_SIZE(cc_setup_national_patched));
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200961 msgb_free(out);
962
963 /* Make sure that a wildcard is matching */
964 entry.mnc = "09";
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200965 bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries);
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200966 msg = msgb_alloc(4096, "test_dt_filter");
967 copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national));
968 parsed = bsc_nat_parse(msg);
969 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100970 printf("FAIL: Could not parse ID resp\n");
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200971 abort();
972 }
973
Holger Hans Peter Freytherdf8e6e92011-05-27 14:09:55 +0200974 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200975 if (out != msg) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +0100976 printf("FAIL: The message should be unchanged.\n");
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200977 abort();
978 }
979
Holger Hans Peter Freyther50be1a92012-01-10 22:31:39 +0100980 verify_msg(out, cc_setup_national, ARRAY_SIZE(cc_setup_national));
Holger Hans Peter Freyther74779c62010-10-28 15:27:00 +0200981 msgb_free(out);
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +0200982}
983
Holger Hans Peter Freyther8e60f622012-01-18 20:00:28 +0100984static void test_sms_smsc_rewrite()
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200985{
986 struct msgb *msg = msgb_alloc(4096, "SMSC rewrite"), *out;
987 struct bsc_nat_parsed *parsed;
988 const char *imsi = "515039900406700";
989
990 struct bsc_nat *nat = bsc_nat_alloc();
991
992 /* a fake list */
Holger Hans Peter Freyther68368dd2012-01-10 22:39:07 +0100993 struct osmo_config_list smsc_entries, dest_entries, clear_entries;
994 struct osmo_config_entry smsc_entry, dest_entry, clear_entry;
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200995
Holger Hans Peter Freytheracc40312011-05-27 19:21:24 +0200996 INIT_LLIST_HEAD(&smsc_entries.entry);
997 INIT_LLIST_HEAD(&dest_entries.entry);
Holger Hans Peter Freyther68368dd2012-01-10 22:39:07 +0100998 INIT_LLIST_HEAD(&clear_entries.entry);
Holger Hans Peter Freytheracc40312011-05-27 19:21:24 +0200999 smsc_entry.mcc = "^515039";
1000 smsc_entry.option = "639180000105()";
1001 smsc_entry.text = "6666666666667";
1002 llist_add_tail(&smsc_entry.list, &smsc_entries.entry);
1003 dest_entry.mcc = "515";
1004 dest_entry.mnc = "03";
1005 dest_entry.option = "^0049";
1006 dest_entry.text = "";
1007 llist_add_tail(&dest_entry.list, &dest_entries.entry);
Holger Hans Peter Freyther68368dd2012-01-10 22:39:07 +01001008 clear_entry.mcc = "^515039";
1009 clear_entry.option = "^0049";
1010 clear_entry.text = "";
1011 llist_add_tail(&clear_entry.list, &clear_entries.entry);
Holger Hans Peter Freytheracc40312011-05-27 19:21:24 +02001012
1013 bsc_nat_num_rewr_entry_adapt(nat, &nat->smsc_rewr, &smsc_entries);
1014 bsc_nat_num_rewr_entry_adapt(nat, &nat->tpdest_match, &dest_entries);
Holger Hans Peter Freyther68368dd2012-01-10 22:39:07 +01001015 bsc_nat_num_rewr_entry_adapt(nat, &nat->sms_clear_tp_srr, &clear_entries);
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +02001016
Holger Hans Peter Freyther68368dd2012-01-10 22:39:07 +01001017 printf("Testing SMSC rewriting.\n");
1018
1019 /*
1020 * Check if the SMSC address is changed
1021 */
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +02001022 copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
1023 parsed = bsc_nat_parse(msg);
1024 if (!parsed) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +01001025 printf("FAIL: Could not parse SMS\n");
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +02001026 abort();
1027 }
1028
1029 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
1030 if (out == msg) {
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +01001031 printf("FAIL: This should have changed.\n");
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +02001032 abort();
1033 }
1034
Holger Hans Peter Freyther50be1a92012-01-10 22:31:39 +01001035 verify_msg(out, smsc_rewrite_patched, ARRAY_SIZE(smsc_rewrite_patched));
1036 msgb_free(out);
Holger Hans Peter Freyther68368dd2012-01-10 22:39:07 +01001037
1038 /* clear out the filter for SMSC */
1039 printf("Attempting to only rewrite the HDR\n");
1040 bsc_nat_num_rewr_entry_adapt(nat, &nat->smsc_rewr, NULL);
1041 msg = msgb_alloc(4096, "SMSC rewrite");
1042 copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
1043 parsed = bsc_nat_parse(msg);
1044 if (!parsed) {
1045 printf("FAIL: Could not parse SMS\n");
1046 abort();
1047 }
1048
1049 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
1050 if (out == msg) {
1051 printf("FAIL: This should have changed.\n");
1052 abort();
1053 }
1054
1055 verify_msg(out, smsc_rewrite_patched_hdr, ARRAY_SIZE(smsc_rewrite_patched_hdr));
1056 msgb_free(out);
1057
1058 /* clear out the next filter */
1059 printf("Attempting to change nothing.\n");
1060 bsc_nat_num_rewr_entry_adapt(nat, &nat->sms_clear_tp_srr, NULL);
1061 msg = msgb_alloc(4096, "SMSC rewrite");
1062 copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
1063 parsed = bsc_nat_parse(msg);
1064 if (!parsed) {
1065 printf("FAIL: Could not parse SMS\n");
1066 abort();
1067 }
1068
1069 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
1070 if (out != msg) {
1071 printf("FAIL: This should not have changed.\n");
1072 abort();
1073 }
1074
1075 verify_msg(out, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
1076 msgb_free(out);
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +02001077}
1078
Holger Hans Peter Freyther8e60f622012-01-18 20:00:28 +01001079static void test_sms_number_rewrite(void)
1080{
1081 struct msgb *msg = msgb_alloc(4096, "SMSC rewrite"), *out;
1082 struct bsc_nat_parsed *parsed;
1083 const char *imsi = "515039900406700";
1084
1085 struct bsc_nat *nat = bsc_nat_alloc();
1086
1087 /* a fake list */
1088 struct osmo_config_list num_entries;
1089 struct osmo_config_entry num_entry;
1090
1091 INIT_LLIST_HEAD(&num_entries.entry);
1092 num_entry.mcc = "^515039";
1093 num_entry.option = "^0049()";
1094 num_entry.text = "0032";
1095 llist_add_tail(&num_entry.list, &num_entries.entry);
1096
1097 bsc_nat_num_rewr_entry_adapt(nat, &nat->sms_num_rewr, &num_entries);
1098
1099 printf("Testing SMS TP-DA rewriting.\n");
1100
1101 /*
1102 * Check if the SMSC address is changed
1103 */
1104 copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
1105 parsed = bsc_nat_parse(msg);
1106 if (!parsed) {
1107 printf("FAIL: Could not parse SMS\n");
1108 abort();
1109 }
1110
1111 out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
1112 if (out == msg) {
1113 printf("FAIL: This should have changed.\n");
1114 abort();
1115 }
1116
1117 verify_msg(out, smsc_rewrite_num_patched,
1118 ARRAY_SIZE(smsc_rewrite_num_patched));
1119 msgb_free(out);
1120}
1121
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +08001122int main(int argc, char **argv)
1123{
Holger Hans Peter Freyther30e1ae92010-07-30 02:53:14 +08001124 sccp_set_log_area(DSCCP);
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +02001125 osmo_init_logging(&log_info);
Holger Hans Peter Freyther38f7c752010-06-15 18:48:36 +08001126
1127 test_filter();
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +02001128 test_contrack();
Holger Hans Peter Freyther04fd9922010-03-30 06:51:53 +02001129 test_paging();
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +02001130 test_mgcp_ass_tracking();
1131 test_mgcp_find();
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +02001132 test_mgcp_rewrite();
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +02001133 test_mgcp_parse();
Holger Hans Peter Freyther0c08db12010-05-14 08:12:57 +08001134 test_cr_filter();
Holger Hans Peter Freyther32685402010-09-15 05:20:40 +08001135 test_dt_filter();
Holger Hans Peter Freyther73bbf892010-10-21 14:46:57 +02001136 test_setup_rewrite();
Holger Hans Peter Freyther8e60f622012-01-18 20:00:28 +01001137 test_sms_smsc_rewrite();
1138 test_sms_number_rewrite();
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +01001139 test_mgcp_allocations();
Holger Hans Peter Freytherf5ede522012-01-06 13:56:12 +01001140
1141 printf("Testing execution completed.\n");
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +08001142 return 0;
1143}