blob: aabc1304a63476f1b15b7f8ba3224b5d491929ab [file] [log] [blame]
Holger Hans Peter Freytherf75a6802010-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 Freyther98e49d42010-06-15 18:46:56 +08005 * (C) 2010 by On-Waves
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +08006 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25
26#include <openbsc/debug.h>
27#include <openbsc/gsm_data.h>
28#include <openbsc/bsc_nat.h>
29
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +080030#include <osmocore/talloc.h>
31
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +080032#include <stdio.h>
33
34/* test messages for ipa */
35static u_int8_t ipa_id[] = {
36 0x00, 0x01, 0xfe, 0x06,
37};
38
39/* SCCP messages are below */
40static u_int8_t gsm_reset[] = {
41 0x00, 0x12, 0xfd,
42 0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
43 0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
44 0x01, 0x20,
45};
46
47static const u_int8_t gsm_reset_ack[] = {
48 0x00, 0x13, 0xfd,
49 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
50 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
51 0x00, 0x01, 0x31,
52};
53
54static const u_int8_t gsm_paging[] = {
55 0x00, 0x20, 0xfd,
56 0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
57 0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x10,
58 0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10,
59 0x02, 0x01, 0x31, 0x97, 0x61, 0x1a, 0x01, 0x06,
60};
61
62/* BSC -> MSC connection open */
63static const u_int8_t bssmap_cr[] = {
64 0x00, 0x2c, 0xfd,
65 0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x04, 0x02,
66 0x42, 0xfe, 0x0f, 0x1f, 0x00, 0x1d, 0x57, 0x05,
67 0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x12, 0xc3,
68 0x50, 0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33,
69 0x19, 0xa2, 0x08, 0x29, 0x47, 0x10, 0x02, 0x01,
70 0x31, 0x97, 0x61, 0x00
71};
72
73/* MSC -> BSC connection confirm */
74static const u_int8_t bssmap_cc[] = {
75 0x00, 0x0a, 0xfd,
76 0x02, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
77};
78
79/* MSC -> BSC released */
80static const u_int8_t bssmap_released[] = {
81 0x00, 0x0e, 0xfd,
82 0x04, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x00, 0x01, 0x0f,
83 0x02, 0x23, 0x42, 0x00,
84};
85
86/* BSC -> MSC released */
87static const u_int8_t bssmap_release_complete[] = {
88 0x00, 0x07, 0xfd,
89 0x05, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03
90};
91
Holger Hans Peter Freyther55e8f552010-04-06 10:22:01 +020092/* both directions IT timer */
93static const u_int8_t connnection_it[] = {
94 0x00, 0x0b, 0xfd,
95 0x10, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03,
96 0x00, 0x00, 0x00, 0x00,
97};
98
Holger Hans Peter Freyther6b998282010-04-01 08:47:12 +020099/* MGCP wrap... */
100static const u_int8_t mgcp_msg[] = {
101 0x00, 0x03, 0xfc,
102 0x20, 0x20, 0x20,
103};
104
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800105struct filter_result {
106 const u_int8_t *data;
107 const u_int16_t length;
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100108 const int dir;
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800109 const int result;
110};
111
112static const struct filter_result results[] = {
113 {
114 .data = ipa_id,
115 .length = ARRAY_SIZE(ipa_id),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100116 .dir = DIR_MSC,
117 .result = 1,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800118 },
119 {
120 .data = gsm_reset,
121 .length = ARRAY_SIZE(gsm_reset),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100122 .dir = DIR_MSC,
123 .result = 1,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800124 },
125 {
126 .data = gsm_reset_ack,
127 .length = ARRAY_SIZE(gsm_reset_ack),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100128 .dir = DIR_BSC,
129 .result = 1,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800130 },
131 {
132 .data = gsm_paging,
133 .length = ARRAY_SIZE(gsm_paging),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100134 .dir = DIR_BSC,
135 .result = 0,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800136 },
137 {
138 .data = bssmap_cr,
139 .length = ARRAY_SIZE(bssmap_cr),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100140 .dir = DIR_MSC,
141 .result = 0,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800142 },
143 {
144 .data = bssmap_cc,
145 .length = ARRAY_SIZE(bssmap_cc),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100146 .dir = DIR_BSC,
147 .result = 0,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800148 },
149 {
150 .data = bssmap_released,
151 .length = ARRAY_SIZE(bssmap_released),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100152 .dir = DIR_MSC,
153 .result = 0,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800154 },
155 {
156 .data = bssmap_release_complete,
157 .length = ARRAY_SIZE(bssmap_release_complete),
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100158 .dir = DIR_BSC,
159 .result = 0,
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800160 },
Holger Hans Peter Freyther6b998282010-04-01 08:47:12 +0200161 {
162 .data = mgcp_msg,
163 .length = ARRAY_SIZE(mgcp_msg),
164 .dir = DIR_MSC,
165 .result = 0,
166 },
Holger Hans Peter Freyther55e8f552010-04-06 10:22:01 +0200167 {
168 .data = connnection_it,
169 .length = ARRAY_SIZE(connnection_it),
170 .dir = DIR_BSC,
171 .result = 0,
172 },
173 {
174 .data = connnection_it,
175 .length = ARRAY_SIZE(connnection_it),
176 .dir = DIR_MSC,
177 .result = 0,
178 },
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800179};
180
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800181static void test_filter(void)
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800182{
183 int i;
184
185
186 /* start testinh with proper messages */
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800187 fprintf(stderr, "Testing BSS Filtering.\n");
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800188 for (i = 0; i < ARRAY_SIZE(results); ++i) {
189 int result;
190 struct bsc_nat_parsed *parsed;
191 struct msgb *msg = msgb_alloc(4096, "test-message");
192
193 fprintf(stderr, "Going to test item: %d\n", i);
194 memcpy(msg->data, results[i].data, results[i].length);
195 msg->l2h = msgb_put(msg, results[i].length);
196
197 parsed = bsc_nat_parse(msg);
198 if (!parsed) {
199 fprintf(stderr, "FAIL: Failed to parse the message\n");
200 continue;
201 }
202
Holger Hans Peter Freytherbbf6b652010-01-30 11:53:30 +0100203 result = bsc_nat_filter_ipa(results[i].dir, msg, parsed);
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800204 if (result != results[i].result) {
205 fprintf(stderr, "FAIL: Not the expected result got: %d wanted: %d\n",
206 result, results[i].result);
207 }
208
209 msgb_free(msg);
210 }
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800211}
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800212
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800213#include "bsc_data.c"
214
215static void copy_to_msg(struct msgb *msg, const u_int8_t *data, unsigned int length)
216{
217 msgb_reset(msg);
218 msg->l2h = msgb_put(msg, length);
219 memcpy(msg->l2h, data, msgb_l2len(msg));
220}
221
222#define VERIFY(con_found, con, msg, ver, str) \
Holger Hans Peter Freyther75ee8412010-06-15 18:48:55 +0800223 if (!con_found || con_found->bsc != con) { \
Holger Hans Peter Freytherd062c522010-06-15 18:48:44 +0800224 fprintf(stderr, "Failed to find the con: %p\n", con_found); \
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800225 abort(); \
226 } \
227 if (memcmp(msg->data, ver, sizeof(ver)) != 0) { \
228 fprintf(stderr, "Failed to patch the %s msg.\n", str); \
229 abort(); \
230 }
231
232/* test conn tracking once */
233static void test_contrack()
234{
235 int rc;
236 struct bsc_nat *nat;
Holger Hans Peter Freyther75ee8412010-06-15 18:48:55 +0800237 struct bsc_connection *con;
238 struct sccp_connections *con_found;
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800239 struct bsc_nat_parsed *parsed;
240 struct msgb *msg;
241
242 fprintf(stderr, "Testing connection tracking.\n");
243 nat = bsc_nat_alloc();
244 con = bsc_connection_alloc(nat);
Holger Hans Peter Freyther7d841e62010-04-18 02:30:57 +0800245 con->cfg = bsc_config_alloc(nat, "foo", 23);
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800246 msg = msgb_alloc(4096, "test");
247
248 /* 1.) create a connection */
249 copy_to_msg(msg, bsc_cr, sizeof(bsc_cr));
250 parsed = bsc_nat_parse(msg);
251 con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
252 if (con_found != NULL) {
Holger Hans Peter Freytherd062c522010-06-15 18:48:44 +0800253 fprintf(stderr, "Con should not exist %p\n", con_found);
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800254 abort();
255 }
256 rc = create_sccp_src_ref(con, msg, parsed);
257 if (rc != 0) {
258 fprintf(stderr, "Failed to create a ref\n");
259 abort();
260 }
261 con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
Holger Hans Peter Freyther75ee8412010-06-15 18:48:55 +0800262 if (!con_found || con_found->bsc != con) {
Holger Hans Peter Freytherd062c522010-06-15 18:48:44 +0800263 fprintf(stderr, "Failed to find the con: %p\n", con_found);
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800264 abort();
265 }
266 if (memcmp(msg->data, bsc_cr_patched, sizeof(bsc_cr_patched)) != 0) {
267 fprintf(stderr, "Failed to patch the BSC CR msg.\n");
268 abort();
269 }
270 talloc_free(parsed);
271
272 /* 2.) get the cc */
273 copy_to_msg(msg, msc_cc, sizeof(msc_cc));
274 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freyther75ee8412010-06-15 18:48:55 +0800275 con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
276 VERIFY(con_found, con, msg, msc_cc_patched, "MSC CC");
277 if (update_sccp_src_ref(con_found, parsed) != 0) {
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800278 fprintf(stderr, "Failed to update the SCCP con.\n");
279 abort();
280 }
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800281
282 /* 3.) send some data */
283 copy_to_msg(msg, bsc_dtap, sizeof(bsc_dtap));
284 parsed = bsc_nat_parse(msg);
285 con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
286 VERIFY(con_found, con, msg, bsc_dtap_patched, "BSC DTAP");
287
288 /* 4.) receive some data */
289 copy_to_msg(msg, msc_dtap, sizeof(msc_dtap));
290 parsed = bsc_nat_parse(msg);
291 con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
292 VERIFY(con_found, con, msg, msc_dtap_patched, "MSC DTAP");
293
294 /* 5.) close the connection */
295 copy_to_msg(msg, msc_rlsd, sizeof(msc_rlsd));
296 parsed = bsc_nat_parse(msg);
297 con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
298 VERIFY(con_found, con, msg, msc_rlsd_patched, "MSC RLSD");
299
300 /* 6.) confirm the connection close */
301 copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
302 parsed = bsc_nat_parse(msg);
303 con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
Holger Hans Peter Freyther75ee8412010-06-15 18:48:55 +0800304 if (!con_found || con_found->bsc != con) {
Holger Hans Peter Freytherd062c522010-06-15 18:48:44 +0800305 fprintf(stderr, "Failed to find the con: %p\n", con_found);
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800306 abort();
307 }
308 if (memcmp(msg->data, bsc_rlc_patched, sizeof(bsc_rlc_patched)) != 0) {
309 fprintf(stderr, "Failed to patch the BSC CR msg.\n");
310 abort();
311 }
312 remove_sccp_src_ref(con, msg, parsed);
Holger Hans Peter Freytherbedecf32010-04-05 21:44:51 +0200313 talloc_free(parsed);
314
315 copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
316 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800317 con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
318
319 /* verify that it is gone */
320 if (con_found != NULL) {
Holger Hans Peter Freytherd062c522010-06-15 18:48:44 +0800321 fprintf(stderr, "Con should be gone. %p\n", con_found);
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800322 abort();
323 }
324 talloc_free(parsed);
325
326
327 talloc_free(nat);
328 msgb_free(msg);
329}
330
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200331static void test_paging(void)
332{
Holger Hans Peter Freyther935b2df2010-04-17 08:07:19 +0200333 int lac;
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200334 struct bsc_nat *nat;
335 struct bsc_connection *con;
336 struct bsc_nat_parsed *parsed;
Holger Hans Peter Freytherbfcf5192010-04-06 15:11:34 +0200337 struct bsc_config cfg;
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200338 struct msgb *msg;
339
340 fprintf(stderr, "Testing paging by lac.\n");
341
342 nat = bsc_nat_alloc();
343 con = bsc_connection_alloc(nat);
Holger Hans Peter Freytherbfcf5192010-04-06 15:11:34 +0200344 con->cfg = &cfg;
345 cfg.lac = 23;
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200346 con->authenticated = 1;
347 llist_add(&con->list_entry, &nat->bsc_connections);
348 msg = msgb_alloc(4096, "test");
349
350 /* Test completely bad input */
351 copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
Holger Hans Peter Freyther935b2df2010-04-17 08:07:19 +0200352 if (bsc_nat_find_bsc(nat, msg, &lac) != 0) {
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200353 fprintf(stderr, "Should have not found anything.\n");
354 abort();
355 }
356
357 /* Test it by not finding it */
358 copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
359 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freyther935b2df2010-04-17 08:07:19 +0200360 if (bsc_nat_find_bsc(nat, msg, &lac) != 0) {
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200361 fprintf(stderr, "Should have not found aynthing.\n");
362 abort();
363 }
364 talloc_free(parsed);
365
366 /* Test by finding it */
Holger Hans Peter Freytherbfcf5192010-04-06 15:11:34 +0200367 cfg.lac = 8213;
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200368 copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
369 parsed = bsc_nat_parse(msg);
Holger Hans Peter Freyther935b2df2010-04-17 08:07:19 +0200370 if (bsc_nat_find_bsc(nat, msg, &lac) != con) {
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200371 fprintf(stderr, "Should have found it.\n");
372 abort();
373 }
374 talloc_free(parsed);
375}
376
Holger Hans Peter Freyther89179982010-04-01 03:55:27 +0200377static void test_mgcp_ass_tracking(void)
Holger Hans Peter Freytherdccb9152010-06-15 18:49:53 +0800378{
379 struct sccp_connections con;
380 struct bsc_nat_parsed *parsed;
381 struct msgb *msg;
382
383 fprintf(stderr, "Testing MGCP.\n");
384 memset(&con, 0, sizeof(con));
385
386 msg = msgb_alloc(4096, "foo");
387 copy_to_msg(msg, ass_cmd, sizeof(ass_cmd));
388 parsed = bsc_nat_parse(msg);
389 if (bsc_mgcp_assign(&con, msg) != 0) {
390 fprintf(stderr, "Failed to handle assignment.\n");
391 abort();
392 }
393
394 if (con.msc_timeslot != 21) {
395 fprintf(stderr, "Timeslot should be 21.\n");
396 abort();
397 }
398
399 if (con.bsc_timeslot != 21) {
400 fprintf(stderr, "Assigned timeslot should have been 21.\n");
401 abort();
402 }
403 talloc_free(parsed);
404
405 bsc_mgcp_clear(&con);
406 if (con.bsc_timeslot != -1 || con.msc_timeslot != -1) {
407 fprintf(stderr, "Clearing should remove the mapping.\n");
408 abort();
409 }
410}
411
Holger Hans Peter Freyther89179982010-04-01 03:55:27 +0200412/* test the code to find a given connection */
413static void test_mgcp_find(void)
414{
415 struct bsc_nat *nat;
416 struct bsc_connection *con;
417 struct sccp_connections *sccp_con;
418
419 fprintf(stderr, "Testing finding of a BSC Connection\n");
420
421 nat = bsc_nat_alloc();
422 con = bsc_connection_alloc(nat);
423 llist_add(&con->list_entry, &nat->bsc_connections);
424
425 sccp_con = talloc_zero(con, struct sccp_connections);
426 sccp_con->msc_timeslot = 12;
427 sccp_con->bsc_timeslot = 12;
428 sccp_con->bsc = con;
429 llist_add(&sccp_con->list_entry, &nat->sccp_connections);
430
431 if (bsc_mgcp_find_con(nat, 11) != NULL) {
432 fprintf(stderr, "Found the wrong connection.\n");
433 abort();
434 }
435
Holger Hans Peter Freyther98d15ef2010-04-18 02:26:16 +0800436 if (bsc_mgcp_find_con(nat, 12) != sccp_con) {
Holger Hans Peter Freyther89179982010-04-01 03:55:27 +0200437 fprintf(stderr, "Didn't find the connection\n");
438 abort();
439 }
440
441 sccp_con->msc_timeslot = 0;
442 sccp_con->bsc_timeslot = 0;
Holger Hans Peter Freyther98d15ef2010-04-18 02:26:16 +0800443 if (bsc_mgcp_find_con(nat, 1) != sccp_con) {
Holger Hans Peter Freyther89179982010-04-01 03:55:27 +0200444 fprintf(stderr, "Didn't find the connection\n");
445 abort();
446 }
447
448 /* free everything */
449 talloc_free(nat);
450}
451
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200452static void test_mgcp_rewrite(void)
453{
454 int i;
Holger Hans Peter Freyther0d0aaa62010-04-04 18:09:10 +0200455 struct msgb *output;
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200456 fprintf(stderr, "Test rewriting MGCP messages.\n");
457
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200458 for (i = 0; i < ARRAY_SIZE(mgcp_messages); ++i) {
459 const char *orig = mgcp_messages[i].orig;
460 const char *patc = mgcp_messages[i].patch;
461 const char *ip = mgcp_messages[i].ip;
462 const int port = mgcp_messages[i].port;
463
Holger Hans Peter Freyther0d0aaa62010-04-04 18:09:10 +0200464 char *input = strdup(orig);
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200465
Holger Hans Peter Freyther0d0aaa62010-04-04 18:09:10 +0200466 output = bsc_mgcp_rewrite(input, strlen(input), ip, port);
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200467 if (msgb_l2len(output) != strlen(patc)) {
468 fprintf(stderr, "Wrong sizes for test: %d %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig));
469 fprintf(stderr, "String '%s' vs '%s'\n", (const char *) output->l2h, patc);
470 abort();
471 }
472
473 if (memcmp(output->l2h, patc, msgb_l2len(output)) != 0) {
474 fprintf(stderr, "Broken on %d msg: '%s'\n", i, (const char *) output->l2h);
475 abort();
476 }
477
478 msgb_free(output);
Holger Hans Peter Freyther0d0aaa62010-04-04 18:09:10 +0200479 free(input);
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200480 }
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200481}
482
Holger Hans Peter Freyther9fec0102010-04-01 10:16:28 +0200483static void test_mgcp_parse(void)
484{
485 int code, ci;
486 char transaction[60];
487
488 fprintf(stderr, "Test MGCP response parsing.\n");
489
490 if (bsc_mgcp_parse_response(crcx_resp, &code, transaction) != 0) {
491 fprintf(stderr, "Failed to parse CRCX resp.\n");
492 abort();
493 }
494
495 if (code != 200) {
496 fprintf(stderr, "Failed to parse the CODE properly. Got: %d\n", code);
497 abort();
498 }
499
500 if (strcmp(transaction, "23265295") != 0) {
501 fprintf(stderr, "Failed to parse transaction id: '%s'\n", transaction);
502 abort();
503 }
504
505 ci = bsc_mgcp_extract_ci(crcx_resp);
506 if (ci != 1) {
507 fprintf(stderr, "Failed to parse the CI. Got: %d\n", ci);
508 abort();
509 }
510}
511
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800512int main(int argc, char **argv)
513{
514 struct debug_target *stderr_target;
515
516 stderr_target = debug_target_create_stderr();
517 debug_add_target(stderr_target);
518 debug_set_all_filter(stderr_target, 1);
519
520 test_filter();
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200521 test_contrack();
Holger Hans Peter Freytherd5deb332010-03-30 06:51:53 +0200522 test_paging();
Holger Hans Peter Freyther89179982010-04-01 03:55:27 +0200523 test_mgcp_ass_tracking();
524 test_mgcp_find();
Holger Hans Peter Freytheracd64202010-04-01 06:48:52 +0200525 test_mgcp_rewrite();
Holger Hans Peter Freyther9fec0102010-04-01 10:16:28 +0200526 test_mgcp_parse();
Holger Hans Peter Freytherf75a6802010-06-15 18:45:38 +0800527 return 0;
528}
Holger Hans Peter Freytherb63a9f82010-06-15 18:48:36 +0800529
530void input_event()
531{}
532int nm_state_event()
533{
534 return -1;
535}
536
537int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
538{
539 return -1;
540}