diff options
Diffstat (limited to 'tests/bsc-nat')
-rw-r--r-- | tests/bsc-nat/Makefile.am | 4 | ||||
-rw-r--r-- | tests/bsc-nat/Makefile.in | 11 | ||||
-rw-r--r-- | tests/bsc-nat/bsc_data.c | 22 | ||||
-rw-r--r-- | tests/bsc-nat/bsc_nat_test.c | 126 |
4 files changed, 112 insertions, 51 deletions
diff --git a/tests/bsc-nat/Makefile.am b/tests/bsc-nat/Makefile.am index 04bdb9789..478509842 100644 --- a/tests/bsc-nat/Makefile.am +++ b/tests/bsc-nat/Makefile.am @@ -1,5 +1,5 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include -AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS) $(LIBOSMOSCCP_CFLAGS) $(COVERAGE_CFLAGS) +AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOSCCP_CFLAGS) $(COVERAGE_CFLAGS) AM_LDFLAGS = $(COVERAGE_LDFLAGS) EXTRA_DIST = bsc_data.c @@ -16,4 +16,4 @@ bsc_nat_test_LDADD = $(top_builddir)/src/libbsc/libbsc.a \ $(top_srcdir)/src/libabis/libabis.a \ $(top_srcdir)/src/libtrau/libtrau.a \ $(top_srcdir)/src/libcommon/libcommon.a \ - $(LIBOSMOCORE_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) + $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) diff --git a/tests/bsc-nat/Makefile.in b/tests/bsc-nat/Makefile.in index 280d22d7a..6e1d0941a 100644 --- a/tests/bsc-nat/Makefile.in +++ b/tests/bsc-nat/Makefile.in @@ -36,7 +36,7 @@ noinst_PROGRAMS = bsc_nat_test$(EXEEXT) subdir = tests/bsc-nat DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -54,7 +54,8 @@ bsc_nat_test_DEPENDENCIES = $(top_builddir)/src/libbsc/libbsc.a \ $(top_srcdir)/src/libabis/libabis.a \ $(top_srcdir)/src/libtrau/libtrau.a \ $(top_srcdir)/src/libcommon/libcommon.a $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -116,6 +117,8 @@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBOSMOCORE_CFLAGS = @LIBOSMOCORE_CFLAGS@ LIBOSMOCORE_LIBS = @LIBOSMOCORE_LIBS@ +LIBOSMOGSM_CFLAGS = @LIBOSMOGSM_CFLAGS@ +LIBOSMOGSM_LIBS = @LIBOSMOGSM_LIBS@ LIBOSMOSCCP_CFLAGS = @LIBOSMOSCCP_CFLAGS@ LIBOSMOSCCP_LIBS = @LIBOSMOSCCP_LIBS@ LIBOSMOVTY_CFLAGS = @LIBOSMOVTY_CFLAGS@ @@ -185,7 +188,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ INCLUDES = $(all_includes) -I$(top_srcdir)/include -AM_CFLAGS = -Wall -ggdb3 $(LIBOSMOCORE_CFLAGS) $(LIBOSMOSCCP_CFLAGS) $(COVERAGE_CFLAGS) +AM_CFLAGS = -Wall -ggdb3 $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOSCCP_CFLAGS) $(COVERAGE_CFLAGS) AM_LDFLAGS = $(COVERAGE_LDFLAGS) EXTRA_DIST = bsc_data.c bsc_nat_test_SOURCES = bsc_nat_test.c \ @@ -199,7 +202,7 @@ bsc_nat_test_LDADD = $(top_builddir)/src/libbsc/libbsc.a \ $(top_srcdir)/src/libabis/libabis.a \ $(top_srcdir)/src/libtrau/libtrau.a \ $(top_srcdir)/src/libcommon/libcommon.a \ - $(LIBOSMOCORE_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) + $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOVTY_LIBS) all: all-am diff --git a/tests/bsc-nat/bsc_data.c b/tests/bsc-nat/bsc_data.c index 04755233c..8a06348fd 100644 --- a/tests/bsc-nat/bsc_data.c +++ b/tests/bsc-nat/bsc_data.c @@ -96,6 +96,28 @@ static const uint8_t id_resp[] = { 0x31 }; +/* sms code msg */ +static const uint8_t smsc_rewrite[] = { +0x00, 0x30, 0xfd, 0x06, 0x01, 0x13, 0x1e, 0x00, +0x01, 0x29, 0x01, 0x03, 0x26, 0x09, 0x01, 0x23, +0x00, 0x0c, 0x00, 0x07, 0x91, 0x36, 0x19, 0x08, +0x00, 0x10, 0x50, 0x17, 0x01, 0x0c, 0x0f, 0x81, +0x00, 0x94, 0x51, 0x87, 0x86, 0x78, 0x46, 0xf5, +0x00, 0x00, 0x09, 0xcc, 0xb7, 0xbd, 0x0c, 0xca, +0xbf, 0xeb, 0x20 +}; + +static const uint8_t smsc_rewrite_patched[] = { +0x00, 0x31, 0xfd, 0x06, 0x01, 0x13, 0x1e, 0x00, +0x01, 0x2a, 0x01, 0x00, 0x27, 0x09, 0x01, 0x24, +0x00, 0x0c, 0x00, 0x08, 0x91, 0x66, 0x66, 0x66, +0x66, 0x66, 0x66, 0xf7, 0x17, 0x01, 0x0c, 0x0f, +0x81, 0x00, 0x94, 0x51, 0x87, 0x86, 0x78, 0x46, +0xf5, 0x00, 0x00, 0x09, 0xcc, 0xb7, 0xbd, 0x0c, +0xca, 0xbf, 0xeb, 0x20 +}; + + /* * MGCP messages */ diff --git a/tests/bsc-nat/bsc_nat_test.c b/tests/bsc-nat/bsc_nat_test.c index 504b69196..d198424a4 100644 --- a/tests/bsc-nat/bsc_nat_test.c +++ b/tests/bsc-nat/bsc_nat_test.c @@ -27,10 +27,11 @@ #include <openbsc/bsc_nat.h> #include <openbsc/bsc_nat_sccp.h> -#include <osmocore/talloc.h> +#include <osmocom/core/application.h> +#include <osmocom/core/talloc.h> #include <osmocom/sccp/sccp.h> -#include <osmocore/protocol/gsm_08_08.h> +#include <osmocom/gsm/protocol/gsm_08_08.h> #include <stdio.h> @@ -384,12 +385,9 @@ static void test_contrack() static void test_paging(void) { - int lac; struct bsc_nat *nat; struct bsc_connection *con; - struct bsc_nat_parsed *parsed; struct bsc_config *cfg; - struct msgb *msg; fprintf(stderr, "Testing paging by lac.\n"); @@ -400,34 +398,20 @@ static void test_paging(void) bsc_config_add_lac(cfg, 23); con->authenticated = 1; llist_add(&con->list_entry, &nat->bsc_connections); - msg = msgb_alloc(4096, "test"); - - /* Test completely bad input */ - copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd)); - if (bsc_nat_find_bsc(nat, msg, &lac) != 0) { - fprintf(stderr, "Should have not found anything.\n"); - abort(); - } /* Test it by not finding it */ - copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd)); - parsed = bsc_nat_parse(msg); - if (bsc_nat_find_bsc(nat, msg, &lac) != 0) { - fprintf(stderr, "Should have not found aynthing.\n"); + if (bsc_config_handles_lac(cfg, 8213) != 0) { + fprintf(stderr, "Should not be handled.\n"); abort(); } - talloc_free(parsed); /* Test by finding it */ bsc_config_del_lac(cfg, 23); bsc_config_add_lac(cfg, 8213); - copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd)); - parsed = bsc_nat_parse(msg); - if (bsc_nat_find_bsc(nat, msg, &lac) != con) { + if (bsc_config_handles_lac(cfg, 8213) == 0) { fprintf(stderr, "Should have found it.\n"); abort(); } - talloc_free(parsed); } static void test_mgcp_allocations(void) @@ -506,7 +490,7 @@ static void test_mgcp_ass_tracking(void) if (msg->l2h[16] != 0 || msg->l2h[17] != 0x1) { fprintf(stderr, "Input is not as expected.. %s 0x%x\n", - hexdump(msg->l2h, msgb_l2len(msg)), + osmo_hexdump(msg->l2h, msgb_l2len(msg)), msg->l2h[17]); abort(); } @@ -536,7 +520,7 @@ static void test_mgcp_ass_tracking(void) uint16_t cic = htons(timeslot & 0x1f); if (memcmp(&cic, &msg->l2h[16], sizeof(cic)) != 0) { fprintf(stderr, "Message was not patched properly\n"); - fprintf(stderr, "data cic: 0x%x %s\n", cic, hexdump(msg->l2h, msgb_l2len(msg))); + fprintf(stderr, "data cic: 0x%x %s\n", cic, osmo_hexdump(msg->l2h, msgb_l2len(msg))); abort(); } @@ -761,15 +745,18 @@ static void test_cr_filter() nat_lst = bsc_nat_acc_lst_get(nat, "nat"); bsc_lst = bsc_nat_acc_lst_get(nat, "bsc"); - bsc_parse_reg(nat_entry, &nat_entry->imsi_deny_re, &nat_entry->imsi_deny, + if (bsc_parse_reg(nat_entry, &nat_entry->imsi_deny_re, &nat_entry->imsi_deny, cr_filter[i].nat_imsi_deny ? 1 : 0, - &cr_filter[i].nat_imsi_deny); - bsc_parse_reg(bsc_entry, &bsc_entry->imsi_allow_re, &bsc_entry->imsi_allow, + &cr_filter[i].nat_imsi_deny) != 0) + abort(); + if (bsc_parse_reg(bsc_entry, &bsc_entry->imsi_allow_re, &bsc_entry->imsi_allow, cr_filter[i].bsc_imsi_allow ? 1 : 0, - &cr_filter[i].bsc_imsi_allow); - bsc_parse_reg(bsc_entry, &bsc_entry->imsi_deny_re, &bsc_entry->imsi_deny, + &cr_filter[i].bsc_imsi_allow) != 0) + abort(); + if (bsc_parse_reg(bsc_entry, &bsc_entry->imsi_deny_re, &bsc_entry->imsi_deny, cr_filter[i].bsc_imsi_deny ? 1 : 0, - &cr_filter[i].bsc_imsi_deny); + &cr_filter[i].bsc_imsi_deny) != 0) + abort(); parsed = bsc_nat_parse(msg); if (!parsed) { @@ -858,8 +845,8 @@ static void test_setup_rewrite() struct bsc_nat *nat = bsc_nat_alloc(); /* a fake list */ - struct msg_entries entries; - struct msg_entry entry; + struct osmo_config_list entries; + struct osmo_config_entry entry; INIT_LLIST_HEAD(&entries.entry); entry.mcc = "274"; @@ -867,7 +854,7 @@ static void test_setup_rewrite() entry.option = "^0([1-9])"; entry.text = "0049"; llist_add_tail(&entry.list, &entries.entry); - nat->num_rewr = &entries; + bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries); /* verify that nothing changed */ msgb_reset(msg); @@ -878,7 +865,7 @@ static void test_setup_rewrite() abort(); } - out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); + out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi); if (msg != out) { fprintf(stderr, "FAIL: The message should not have been changed\n"); abort(); @@ -904,7 +891,7 @@ static void test_setup_rewrite() abort(); } - out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); + out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi); if (!out) { fprintf(stderr, "FAIL: A new message should be created.\n"); abort(); @@ -922,7 +909,7 @@ static void test_setup_rewrite() if (memcmp(cc_setup_national_patched, out->data, out->len) != 0) { fprintf(stderr, "FAIL: Data is wrong.\n"); - fprintf(stderr, "Data was: %s\n", hexdump(out->data, out->len)); + fprintf(stderr, "Data was: %s\n", osmo_hexdump(out->data, out->len)); abort(); } @@ -930,6 +917,7 @@ static void test_setup_rewrite() /* Make sure that a wildcard is matching */ entry.mnc = "*"; + bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries); msg = msgb_alloc(4096, "test_dt_filter"); copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national)); parsed = bsc_nat_parse(msg); @@ -938,7 +926,7 @@ static void test_setup_rewrite() abort(); } - out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); + out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi); if (!out) { fprintf(stderr, "FAIL: A new message should be created.\n"); abort(); @@ -956,7 +944,7 @@ static void test_setup_rewrite() if (memcmp(cc_setup_national_patched, out->data, out->len) != 0) { fprintf(stderr, "FAIL: Data is wrong.\n"); - fprintf(stderr, "Data was: %s\n", hexdump(out->data, out->len)); + fprintf(stderr, "Data was: %s\n", osmo_hexdump(out->data, out->len)); abort(); } @@ -964,6 +952,7 @@ static void test_setup_rewrite() /* Make sure that a wildcard is matching */ entry.mnc = "09"; + bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries); msg = msgb_alloc(4096, "test_dt_filter"); copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national)); parsed = bsc_nat_parse(msg); @@ -972,7 +961,7 @@ static void test_setup_rewrite() abort(); } - out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi); + out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi); if (out != msg) { fprintf(stderr, "FAIL: The message should be unchanged.\n"); abort(); @@ -991,15 +980,61 @@ static void test_setup_rewrite() msgb_free(out); } -int main(int argc, char **argv) +static void test_smsc_rewrite() { - struct log_target *stderr_target; + struct msgb *msg = msgb_alloc(4096, "SMSC rewrite"), *out; + struct bsc_nat_parsed *parsed; + const char *imsi = "515039900406700"; + + struct bsc_nat *nat = bsc_nat_alloc(); + /* a fake list */ + struct osmo_config_list smsc_entries, dest_entries; + struct osmo_config_entry smsc_entry, dest_entry; + + INIT_LLIST_HEAD(&smsc_entries.entry); + INIT_LLIST_HEAD(&dest_entries.entry); + smsc_entry.mcc = "^515039"; + smsc_entry.option = "639180000105()"; + smsc_entry.text = "6666666666667"; + llist_add_tail(&smsc_entry.list, &smsc_entries.entry); + dest_entry.mcc = "515"; + dest_entry.mnc = "03"; + dest_entry.option = "^0049"; + dest_entry.text = ""; + llist_add_tail(&dest_entry.list, &dest_entries.entry); + + bsc_nat_num_rewr_entry_adapt(nat, &nat->smsc_rewr, &smsc_entries); + bsc_nat_num_rewr_entry_adapt(nat, &nat->tpdest_match, &dest_entries); + + copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite)); + parsed = bsc_nat_parse(msg); + if (!parsed) { + fprintf(stderr, "FAIL: Could not parse SMS\n"); + abort(); + } + + out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi); + if (out == msg) { + fprintf(stderr, "FAIL: This should have changed.\n"); + abort(); + } + + if (out->len != ARRAY_SIZE(smsc_rewrite_patched)) { + fprintf(stderr, "FAIL: The size should match.\n"); + abort(); + } + + if (memcmp(out->data, smsc_rewrite_patched, out->len) != 0) { + fprintf(stderr, "FAIL: the data should be changed.\n"); + abort(); + } +} + +int main(int argc, char **argv) +{ sccp_set_log_area(DSCCP); - log_init(&log_info); - stderr_target = log_target_create_stderr(); - log_add_target(stderr_target); - log_set_all_filter(stderr_target, 1); + osmo_init_logging(&log_info); test_filter(); test_contrack(); @@ -1011,6 +1046,7 @@ int main(int argc, char **argv) test_cr_filter(); test_dt_filter(); test_setup_rewrite(); + test_smsc_rewrite(); test_mgcp_allocations(); return 0; } |