aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests/bsc-nat
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-05-27 17:14:15 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-06-01 20:45:03 +0200
commit9c20571280fb7cf61bb7211cce0dbbfed9fad7b9 (patch)
tree8fa179b3cc133b597f45687df502bef54c699207 /openbsc/tests/bsc-nat
parent2e2ff340216b015c71537daf3a4103bacc95cc14 (diff)
nat: Patch the destination SMS address of a message
Use the same filtering infrasturcture to patch the SMSC address in a CP-DATA/RP-DATA message. Add a very simple testcase for this code.
Diffstat (limited to 'openbsc/tests/bsc-nat')
-rw-r--r--openbsc/tests/bsc-nat/bsc_data.c22
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c50
2 files changed, 69 insertions, 3 deletions
diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c
index 04755233c..8a06348fd 100644
--- a/openbsc/tests/bsc-nat/bsc_data.c
+++ b/openbsc/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/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index c9432fefd..a31efcaef 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -854,7 +854,7 @@ static void test_setup_rewrite()
entry.option = "^0([1-9])";
entry.text = "0049";
llist_add_tail(&entry.list, &entries.entry);
- bsc_nat_num_rewr_entry_adapt(nat, &entries);
+ bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries);
/* verify that nothing changed */
msgb_reset(msg);
@@ -917,7 +917,7 @@ static void test_setup_rewrite()
/* Make sure that a wildcard is matching */
entry.mnc = "*";
- bsc_nat_num_rewr_entry_adapt(nat, &entries);
+ 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);
@@ -952,7 +952,7 @@ static void test_setup_rewrite()
/* Make sure that a wildcard is matching */
entry.mnc = "09";
- bsc_nat_num_rewr_entry_adapt(nat, &entries);
+ 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);
@@ -980,6 +980,49 @@ static void test_setup_rewrite()
msgb_free(out);
}
+static void test_smsc_rewrite()
+{
+ 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 entries;
+ struct osmo_config_entry entry;
+
+ INIT_LLIST_HEAD(&entries.entry);
+ entry.mcc = "^515039";
+ entry.option = "639180000105()";
+ entry.text = "6666666666667";
+ llist_add_tail(&entry.list, &entries.entry);
+ bsc_nat_num_rewr_entry_adapt(nat, &nat->smsc_rewr, &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);
@@ -995,6 +1038,7 @@ int main(int argc, char **argv)
test_cr_filter();
test_dt_filter();
test_setup_rewrite();
+ test_smsc_rewrite();
test_mgcp_allocations();
return 0;
}