summaryrefslogtreecommitdiffstats
path: root/openbsc/tests/bsc-nat
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2012-01-18 20:00:28 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-01-18 20:14:58 +0100
commit8e60f629e27f6a4cbb47479a1a69966c01890201 (patch)
tree7de85ad2d7cbe0d8f83eff89970f74229eede7c3 /openbsc/tests/bsc-nat
parentbe53012f9c14b1bf27b16f4fa2d0f58f8f0393ca (diff)
nat: Prepare to rewrite the TP-DA number of a SMS submit.
Introduce number rewriting of SMS-SUBMIT. Introduce a new list, move code around to help with finding a new number, somehow the number encoding for TP-DA is borked, 03.40 references 04.11 but the length appears to be strlen(number) without taken the type field into account.
Diffstat (limited to 'openbsc/tests/bsc-nat')
-rw-r--r--openbsc/tests/bsc-nat/bsc_data.c9
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c48
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.ok1
3 files changed, 56 insertions, 2 deletions
diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c
index 08b900b83..d8a0c8706 100644
--- a/openbsc/tests/bsc-nat/bsc_data.c
+++ b/openbsc/tests/bsc-nat/bsc_data.c
@@ -127,6 +127,15 @@ static const uint8_t smsc_rewrite_patched_hdr[] = {
0xbf, 0xeb, 0x20
};
+static const uint8_t smsc_rewrite_num_patched[] = {
+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, 0x21, 0x0c, 0x0f, 0x81,
+0x00, 0x23, 0x51, 0x87, 0x86, 0x78, 0x46, 0xf5,
+0x00, 0x00, 0x09, 0xcc, 0xb7, 0xbd, 0x0c, 0xca,
+0xbf, 0xeb, 0x20
+};
/*
* MGCP messages
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index ab97db1ee..c6187f9c5 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -981,7 +981,7 @@ static void test_setup_rewrite()
msgb_free(out);
}
-static void test_smsc_rewrite()
+static void test_sms_smsc_rewrite()
{
struct msgb *msg = msgb_alloc(4096, "SMSC rewrite"), *out;
struct bsc_nat_parsed *parsed;
@@ -1076,6 +1076,49 @@ static void test_smsc_rewrite()
msgb_free(out);
}
+static void test_sms_number_rewrite(void)
+{
+ 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 num_entries;
+ struct osmo_config_entry num_entry;
+
+ INIT_LLIST_HEAD(&num_entries.entry);
+ num_entry.mcc = "^515039";
+ num_entry.option = "^0049()";
+ num_entry.text = "0032";
+ llist_add_tail(&num_entry.list, &num_entries.entry);
+
+ bsc_nat_num_rewr_entry_adapt(nat, &nat->sms_num_rewr, &num_entries);
+
+ printf("Testing SMS TP-DA rewriting.\n");
+
+ /*
+ * Check if the SMSC address is changed
+ */
+ copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
+ parsed = bsc_nat_parse(msg);
+ if (!parsed) {
+ printf("FAIL: Could not parse SMS\n");
+ abort();
+ }
+
+ out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
+ if (out == msg) {
+ printf("FAIL: This should have changed.\n");
+ abort();
+ }
+
+ verify_msg(out, smsc_rewrite_num_patched,
+ ARRAY_SIZE(smsc_rewrite_num_patched));
+ msgb_free(out);
+}
+
int main(int argc, char **argv)
{
sccp_set_log_area(DSCCP);
@@ -1091,7 +1134,8 @@ int main(int argc, char **argv)
test_cr_filter();
test_dt_filter();
test_setup_rewrite();
- test_smsc_rewrite();
+ test_sms_smsc_rewrite();
+ test_sms_number_rewrite();
test_mgcp_allocations();
printf("Testing execution completed.\n");
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.ok b/openbsc/tests/bsc-nat/bsc_nat_test.ok
index f8eee238d..db37ffae6 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.ok
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.ok
@@ -21,4 +21,5 @@ Testing MGCP response parsing.
Testing SMSC rewriting.
Attempting to only rewrite the HDR
Attempting to change nothing.
+Testing SMS TP-DA rewriting.
Testing execution completed.