From 63bb41152266fb61ed10f5972b37a7dcebe8d479 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 25 Mar 2013 10:00:18 +0100 Subject: bss patching: Add test cases for assignment and assignment complete patching * Chosen Channel and Speech Version are both optional. Patch them separately if they are present. * Add testcase for the assignment request patching. --- src/bss_patch.c | 22 +++++++++---------- tests/patching/Makefile.am | 3 ++- tests/patching/patching_test.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/bss_patch.c b/src/bss_patch.c index be5aaf2..c05def5 100644 --- a/src/bss_patch.c +++ b/src/bss_patch.c @@ -80,22 +80,22 @@ static void patch_ass_cmpl(struct msgb *msg, int length) } tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 1, length - 1, 0, 0); - if (!TLVP_PRESENT(&tp, GSM0808_IE_CHOSEN_CHANNEL)) { + + /* Now patch chosen channel and speech version */ + + if (TLVP_PRESENT(&tp, GSM0808_IE_CHOSEN_CHANNEL)) { + data = (uint8_t *) TLVP_VAL(&tp, GSM0808_IE_CHOSEN_CHANNEL); + data[0] = 0x09; + } else { LOGP(DMSC, LOGL_ERROR, "Chosen Channel not in the MSG.\n"); - return; } - if (!TLVP_PRESENT(&tp, GSM0808_IE_SPEECH_VERSION)) { + if (TLVP_PRESENT(&tp, GSM0808_IE_SPEECH_VERSION)) { + data = (uint8_t *) TLVP_VAL(&tp, GSM0808_IE_SPEECH_VERSION); + data[0] = GSM0808_PERM_HR3; + } else { LOGP(DMSC, LOGL_ERROR, "Speech version not in the MSG.\n"); - return; } - - /* claim to have a TCH/H with no mode indication */ - data = (uint8_t *) TLVP_VAL(&tp, GSM0808_IE_CHOSEN_CHANNEL); - data[0] = 0x09; - - data = (uint8_t *) TLVP_VAL(&tp, GSM0808_IE_SPEECH_VERSION); - data[0] = GSM0808_PERM_HR3; } int bss_patch_filter_msg(struct msgb *msg, struct sccp_parse_result *sccp, int dir) diff --git a/tests/patching/Makefile.am b/tests/patching/Makefile.am index 0829e67..1057f86 100644 --- a/tests/patching/Makefile.am +++ b/tests/patching/Makefile.am @@ -3,6 +3,7 @@ noinst_PROGRAMS = patching_test EXTRA_DIST = patching_test.ok -patching_test_SOURCES = patching_test.c $(top_srcdir)/src/bss_patch.c +patching_test_SOURCES = patching_test.c $(top_srcdir)/src/bss_patch.c \ + $(top_srcdir)/src/debug.c patching_test_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOSCCP_LIBS) $(LIBOSMOGSM_LIBS) diff --git a/tests/patching/patching_test.c b/tests/patching/patching_test.c index c379382..f9fd5a4 100644 --- a/tests/patching/patching_test.c +++ b/tests/patching/patching_test.c @@ -2,6 +2,7 @@ #include +#include #include #include @@ -35,6 +36,18 @@ static const uint8_t cc[] = { 0x02, 0x01, 0x04, 0x00, 0x01, 0x01, 0xb4, 0x02, 0x01, 0x00 }; +static const uint8_t ass_rewrite[] = { + 0x06, 0xe5, 0xe2, 0x0e, 0x00, 0x01, 0x0c, 0x00, + 0x0a, 0x01, 0x0b, 0x04, 0x01, 0x0b, 0xa1, 0x25, + 0x01, 0x00, 0x08 +}; + +static const uint8_t ass_rewrite_patched[] = { + 0x06, 0xe5, 0xe2, 0x0e, 0x00, 0x01, 0x0c, 0x00, + 0x0a, 0x01, 0x0b, 0x04, 0x01, 0x0a, 0x91, 0x25, + 0x01, 0x00, 0x08 +}; + struct result { const uint8_t *input; @@ -75,6 +88,12 @@ static struct result results[] = { .exp_len = sizeof(cc), .result = 0, }, + { + .input = ass_rewrite, + .inp_len = sizeof(ass_rewrite), + .expected = ass_rewrite_patched, + .exp_len = sizeof(ass_rewrite_patched), + }, }; static const uint8_t udt_with_poi[] = { @@ -135,6 +154,21 @@ static const uint8_t dt1_cc_setup[] = { 0x99, 0x13, 0x28, 0x77, 0x77 }; +static const uint8_t dt1_ass_compl_norewrite[] = { + 0x06, 0x01, 0x09, 0xaf, 0x00, 0x01, 0x09, 0x00, + 0x07, 0x02, 0x21, 0x09, 0x2c, 0x02, 0x40, 0x25, +}; + +static const uint8_t dt1_ass_compl[] = { + 0x06, 0x01, 0x02, 0x47, 0x00, 0x01, 0x05, 0x00, + 0x03, 0x02, 0x40, 0x01, +}; + +static const uint8_t dt1_ass_compl_patched[] = { + 0x06, 0x01, 0x02, 0x47, 0x00, 0x01, 0x05, 0x00, + 0x03, 0x02, 0x40, 0x25, +}; + static struct result rewrite_results_to_msc[] = { { .input = udt_with_poi, @@ -170,6 +204,18 @@ static struct result rewrite_results_to_msc[] = { .expected = dt1_cc_setup, .exp_len = sizeof(dt1_cc_setup), }, + { + .input = dt1_ass_compl_norewrite, + .inp_len = sizeof(dt1_ass_compl_norewrite), + .expected = dt1_ass_compl_norewrite, + .exp_len = sizeof(dt1_ass_compl_norewrite), + }, + { + .input = dt1_ass_compl, + .inp_len = sizeof(dt1_ass_compl), + .expected = dt1_ass_compl_patched, + .exp_len = sizeof(dt1_ass_compl_patched), + }, }; @@ -304,6 +350,8 @@ static void test_rewrite_bsc(void) int main(int argc, char **argv) { + osmo_init_logging(&log_info); + test_patch_filter(); test_rewrite_msc(); test_rewrite_bsc(); -- cgit v1.2.3