aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests/gprs
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-05-08 23:25:31 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-05-09 00:26:01 +0200
commit6950d14c5bf301fbb3061f5a4fe67f5f57b76040 (patch)
tree1ae01412e3f15a6a7358ea5ad2a63cd6862a45f8 /openbsc/tests/gprs
parentcf2ca648e9f8b9ed753b4ffb588305b0a3430208 (diff)
parentcd5e52605cdb77bdc6f36fce81a6a1bac7fbda48 (diff)
Merge branch 'master' into sysmocom/iu, with tweakssysmocom/iu_orig_history
Numerous manual adjustments are included to make sense on the sysmocom/iu branch: * gsm_04_08_gprs.h has moved to libosmocore on the master branch, but sysmocom/iu has added some entries. Until it is clear whether to move the additions to libosmocore as well, keep gsm_04_08_gprs.h on sysmocom/iu with merely the additions. * Thus, keep using the old gsm_04_08_gprs.[hc] from openbsc in the Makefiles, but only where the sysmocom/iu additions are needed. * In openbsc's gsm_04_08_gprs.h, * include the libosmocore gsm_04_08_gprs.h, * use '#pragma once' instead of #ifndef and * add a TODO comment about moving the rest to libosmocore. * Apply the addition of an osmo_auth_vector to gsm_auth_tuple: in the Iu auth vector hacks, use the gsm_auth_tuple.vec instead of a local struct. See iu_hack__get_hardcoded_auth_tuple() and gsm48_rx_gmm_att_req(). * In the si2q tests, pass NULL as ctx to gsm_network_init(). * In cscn_main.c, add a debug log that was originally added to osmo-nitb. * openbsc/.gitignore: keep only one addition of 'writtenconfig' Conflicts: openbsc/include/openbsc/gprs_sgsn.h openbsc/include/openbsc/gsm_04_08_gprs.h openbsc/src/gprs/gsm_04_08_gprs.c openbsc/src/libmsc/gsm_04_08.c openbsc/src/osmo-cscn/cscn_main.c openbsc/tests/gsm0408/Makefile.am
Diffstat (limited to 'openbsc/tests/gprs')
-rw-r--r--openbsc/tests/gprs/Makefile.am4
-rw-r--r--openbsc/tests/gprs/gprs_test.c480
-rw-r--r--openbsc/tests/gprs/gprs_test.ok14
3 files changed, 2 insertions, 496 deletions
diff --git a/openbsc/tests/gprs/Makefile.am b/openbsc/tests/gprs/Makefile.am
index b57977b94..902313f2a 100644
--- a/openbsc/tests/gprs/Makefile.am
+++ b/openbsc/tests/gprs/Makefile.am
@@ -5,8 +5,6 @@ EXTRA_DIST = gprs_test.ok
noinst_PROGRAMS = gprs_test
-gprs_test_SOURCES = gprs_test.c $(top_srcdir)/src/gprs/gprs_utils.c \
- $(top_srcdir)/src/gprs/gprs_gsup_messages.c \
- $(top_srcdir)/src/libcommon/utils.c
+gprs_test_SOURCES = gprs_test.c $(top_srcdir)/src/gprs/gprs_utils.c
gprs_test_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS)
diff --git a/openbsc/tests/gprs/gprs_test.c b/openbsc/tests/gprs/gprs_test.c
index c78b98ab5..ff7740494 100644
--- a/openbsc/tests/gprs/gprs_test.c
+++ b/openbsc/tests/gprs/gprs_test.c
@@ -5,17 +5,14 @@
#include <openbsc/gprs_llc.h>
#include <openbsc/gprs_utils.h>
-#include <openbsc/gprs_gsup_messages.h>
-
#include <openbsc/debug.h>
#include <osmocom/core/application.h>
+#include <osmocom/gsm/gsup.h>
#define ASSERT_FALSE(x) if (x) { printf("Should have returned false.\n"); abort(); }
#define ASSERT_TRUE(x) if (!x) { printf("Should have returned true.\n"); abort(); }
-#define VERBOSE_FPRINTF(...)
-
/**
* GSM 04.64 8.4.2 Receipt of unacknowledged information
*/
@@ -146,479 +143,6 @@ static void test_gsm_03_03_apn(void)
}
}
-/* TODO: Move tlv testing to libosmocore */
-static void check_tlv_parse(uint8_t **data, size_t *data_len,
- uint8_t exp_tag, size_t exp_len, const uint8_t *exp_val)
-{
- uint8_t *value;
- size_t value_len;
- uint8_t tag;
- int rc;
- uint8_t *saved_data = *data;
- size_t saved_data_len = *data_len;
-
- rc = gprs_match_tlv(data, data_len, exp_tag ^ 1, NULL, NULL);
- OSMO_ASSERT(rc == 0);
-
- rc = gprs_match_tlv(data, data_len, exp_tag, &value, &value_len);
- OSMO_ASSERT(rc == (int)value_len + 2);
- OSMO_ASSERT(value_len == exp_len);
- OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0);
-
- /* restore data/data_len */
- *data = saved_data;
- *data_len = saved_data_len;
-
- rc = gprs_shift_tlv(data, data_len, &tag, &value, &value_len);
- OSMO_ASSERT(rc == (int)value_len + 2);
- OSMO_ASSERT(tag == exp_tag);
- OSMO_ASSERT(value_len == exp_len);
- OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0);
-}
-
-static void check_tv_fixed_match(uint8_t **data, size_t *data_len,
- uint8_t tag, size_t len, const uint8_t *exp_val)
-{
- uint8_t *value;
- int rc;
-
- rc = gprs_match_tv_fixed(data, data_len, tag ^ 1, len, NULL);
- OSMO_ASSERT(rc == 0);
-
- rc = gprs_match_tv_fixed(data, data_len, tag, len, &value);
- OSMO_ASSERT(rc == (int)len + 1);
- OSMO_ASSERT(memcmp(value, exp_val, len) == 0);
-}
-
-static void check_v_fixed_shift(uint8_t **data, size_t *data_len,
- size_t len, const uint8_t *exp_val)
-{
- uint8_t *value;
- int rc;
-
- rc = gprs_shift_v_fixed(data, data_len, len, &value);
- OSMO_ASSERT(rc == (int)len);
- OSMO_ASSERT(memcmp(value, exp_val, len) == 0);
-}
-
-static void check_lv_shift(uint8_t **data, size_t *data_len,
- size_t exp_len, const uint8_t *exp_val)
-{
- uint8_t *value;
- size_t value_len;
- int rc;
-
- rc = gprs_shift_lv(data, data_len, &value, &value_len);
- OSMO_ASSERT(rc == (int)value_len + 1);
- OSMO_ASSERT(value_len == exp_len);
- OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0);
-}
-
-static void check_tlv_match_data_len(size_t data_len, uint8_t tag, size_t len,
- const uint8_t *test_data)
-{
- uint8_t buf[300] = {0};
-
- uint8_t *unchanged_ptr = buf - 1;
- size_t unchanged_len = 0xdead;
- size_t tmp_data_len = data_len;
- uint8_t *value = unchanged_ptr;
- size_t value_len = unchanged_len;
- uint8_t *data = buf;
-
- OSMO_ASSERT(data_len <= sizeof(buf));
-
- tlv_put(data, tag, len, test_data);
- if (data_len < len + 2) {
- OSMO_ASSERT(-1 == gprs_match_tlv(&data, &tmp_data_len,
- tag, &value, &value_len));
- OSMO_ASSERT(tmp_data_len == 0);
- OSMO_ASSERT(data == buf + data_len);
- OSMO_ASSERT(value == unchanged_ptr);
- OSMO_ASSERT(value_len == unchanged_len);
- } else {
- OSMO_ASSERT(0 <= gprs_match_tlv(&data, &tmp_data_len,
- tag, &value, &value_len));
- OSMO_ASSERT(value != unchanged_ptr);
- OSMO_ASSERT(value_len != unchanged_len);
- }
-}
-
-static void check_tv_fixed_match_data_len(size_t data_len,
- uint8_t tag, size_t len,
- const uint8_t *test_data)
-{
- uint8_t buf[300] = {0};
-
- uint8_t *unchanged_ptr = buf - 1;
- size_t tmp_data_len = data_len;
- uint8_t *value = unchanged_ptr;
- uint8_t *data = buf;
-
- OSMO_ASSERT(data_len <= sizeof(buf));
-
- tv_fixed_put(data, tag, len, test_data);
-
- if (data_len < len + 1) {
- OSMO_ASSERT(-1 == gprs_match_tv_fixed(&data, &tmp_data_len,
- tag, len, &value));
- OSMO_ASSERT(tmp_data_len == 0);
- OSMO_ASSERT(data == buf + data_len);
- OSMO_ASSERT(value == unchanged_ptr);
- } else {
- OSMO_ASSERT(0 <= gprs_match_tv_fixed(&data, &tmp_data_len,
- tag, len, &value));
- OSMO_ASSERT(value != unchanged_ptr);
- }
-}
-
-static void check_v_fixed_shift_data_len(size_t data_len,
- size_t len, const uint8_t *test_data)
-{
- uint8_t buf[300] = {0};
-
- uint8_t *unchanged_ptr = buf - 1;
- size_t tmp_data_len = data_len;
- uint8_t *value = unchanged_ptr;
- uint8_t *data = buf;
-
- OSMO_ASSERT(data_len <= sizeof(buf));
-
- memcpy(data, test_data, len);
-
- if (data_len < len) {
- OSMO_ASSERT(-1 == gprs_shift_v_fixed(&data, &tmp_data_len,
- len, &value));
- OSMO_ASSERT(tmp_data_len == 0);
- OSMO_ASSERT(data == buf + data_len);
- OSMO_ASSERT(value == unchanged_ptr);
- } else {
- OSMO_ASSERT(0 <= gprs_shift_v_fixed(&data, &tmp_data_len,
- len, &value));
- OSMO_ASSERT(value != unchanged_ptr);
- }
-}
-
-static void check_lv_shift_data_len(size_t data_len,
- size_t len, const uint8_t *test_data)
-{
- uint8_t buf[300] = {0};
-
- uint8_t *unchanged_ptr = buf - 1;
- size_t unchanged_len = 0xdead;
- size_t tmp_data_len = data_len;
- uint8_t *value = unchanged_ptr;
- size_t value_len = unchanged_len;
- uint8_t *data = buf;
-
- lv_put(data, len, test_data);
- if (data_len < len + 1) {
- OSMO_ASSERT(-1 == gprs_shift_lv(&data, &tmp_data_len,
- &value, &value_len));
- OSMO_ASSERT(tmp_data_len == 0);
- OSMO_ASSERT(data == buf + data_len);
- OSMO_ASSERT(value == unchanged_ptr);
- OSMO_ASSERT(value_len == unchanged_len);
- } else {
- OSMO_ASSERT(0 <= gprs_shift_lv(&data, &tmp_data_len,
- &value, &value_len));
- OSMO_ASSERT(value != unchanged_ptr);
- OSMO_ASSERT(value_len != unchanged_len);
- }
-}
-
-static void test_tlv_shift_functions()
-{
- uint8_t test_data[1024];
- uint8_t buf[1024];
- uint8_t *data_end;
- unsigned i, len;
- uint8_t *data;
- size_t data_len;
- const uint8_t tag = 0x1a;
-
- printf("Test shift functions\n");
-
- for (i = 0; i < ARRAY_SIZE(test_data); i++)
- test_data[i] = (uint8_t)i;
-
- for (len = 0; len < 256; len++) {
- const unsigned iterations = sizeof(buf) / (len + 2) / 4;
-
- memset(buf, 0xee, sizeof(buf));
- data_end = data = buf;
-
- for (i = 0; i < iterations; i++) {
- data_end = tlv_put(data_end, tag, len, test_data);
- data_end = tv_fixed_put(data_end, tag, len, test_data);
- /* v_fixed_put */
- memcpy(data_end, test_data, len);
- data_end += len;
- data_end = lv_put(data_end, len, test_data);
- }
-
- data_len = data_end - data;
- OSMO_ASSERT(data_len <= sizeof(buf));
-
- for (i = 0; i < iterations; i++) {
- check_tlv_parse(&data, &data_len, tag, len, test_data);
- check_tv_fixed_match(&data, &data_len, tag, len, test_data);
- check_v_fixed_shift(&data, &data_len, len, test_data);
- check_lv_shift(&data, &data_len, len, test_data);
- }
-
- OSMO_ASSERT(data == data_end);
-
- /* Test at end of data */
-
- OSMO_ASSERT(-1 == gprs_match_tlv(&data, &data_len, tag, NULL, NULL));
- OSMO_ASSERT(-1 == gprs_match_tv_fixed(&data, &data_len, tag, len, NULL));
- OSMO_ASSERT((len ? -1 : 0) == gprs_shift_v_fixed(&data, &data_len, len, NULL));
- OSMO_ASSERT(-1 == gprs_shift_lv(&data, &data_len, NULL, NULL));
-
- /* Test invalid data_len */
- for (data_len = 0; data_len <= len + 2 + 1; data_len += 1) {
- check_tlv_match_data_len(data_len, tag, len, test_data);
- check_tv_fixed_match_data_len(data_len, tag, len, test_data);
- check_v_fixed_shift_data_len(data_len, len, test_data);
- check_lv_shift_data_len(data_len, len, test_data);
- }
- }
-}
-
-/* Tests for gprs_gsup_messages.c */
-
-#define TEST_IMSI_IE 0x01, 0x08, 0x21, 0x43, 0x65, 0x87, 0x09, 0x21, 0x43, 0xf5
-#define TEST_IMSI_STR "123456789012345"
-
-static void test_gsup_messages_dec_enc(void)
-{
- int test_idx;
- int rc;
- uint8_t buf[1024];
-
- static const uint8_t send_auth_info_req[] = {
- 0x08,
- TEST_IMSI_IE
- };
-
- static const uint8_t send_auth_info_err[] = {
- 0x09,
- TEST_IMSI_IE,
- 0x02, 0x01, 0x07 /* GPRS no allowed */
- };
-
- static const uint8_t send_auth_info_res[] = {
- 0x0a,
- TEST_IMSI_IE,
- 0x03, 0x22, /* Auth tuple */
- 0x20, 0x10,
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
- 0x21, 0x04,
- 0x21, 0x22, 0x23, 0x24,
- 0x22, 0x08,
- 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
- 0x03, 0x22, /* Auth tuple */
- 0x20, 0x10,
- 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
- 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90,
- 0x21, 0x04,
- 0xa1, 0xa2, 0xa3, 0xa4,
- 0x22, 0x08,
- 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8,
- };
-
- static const uint8_t update_location_req[] = {
- 0x04,
- TEST_IMSI_IE,
- };
-
- static const uint8_t update_location_err[] = {
- 0x05,
- TEST_IMSI_IE,
- 0x02, 0x01, 0x07 /* GPRS no allowed */
- };
-
- static const uint8_t update_location_res[] = {
- 0x06,
- TEST_IMSI_IE,
- 0x08, 0x07, /* MSISDN of the subscriber */
- 0x91, 0x94, 0x61, 0x46, 0x32, 0x24, 0x43,
- 0x09, 0x07, /* HLR-Number of the subscriber */
- 0x91, 0x83, 0x52, 0x38, 0x48, 0x83, 0x93,
- 0x04, 0x00, /* PDP info complete */
- 0x05, 0x15,
- 0x10, 0x01, 0x01,
- 0x11, 0x02, 0xf1, 0x21, /* IPv4 */
- 0x12, 0x09, 0x04, 't', 'e', 's', 't', 0x03, 'a', 'p', 'n',
- 0x13, 0x01, 0x02,
- 0x05, 0x11,
- 0x10, 0x01, 0x02,
- 0x11, 0x02, 0xf1, 0x21, /* IPv4 */
- 0x12, 0x08, 0x03, 'f', 'o', 'o', 0x03, 'a', 'p', 'n',
- };
-
- static const uint8_t location_cancellation_req[] = {
- 0x1c,
- TEST_IMSI_IE,
- 0x06, 0x01, 0x00,
- };
-
- static const uint8_t location_cancellation_err[] = {
- 0x1d,
- TEST_IMSI_IE,
- 0x02, 0x01, 0x03 /* Illegal MS */
- };
-
- static const uint8_t location_cancellation_res[] = {
- 0x1e,
- TEST_IMSI_IE,
- };
-
- static const uint8_t purge_ms_req[] = {
- 0x0c,
- TEST_IMSI_IE,
- };
-
- static const uint8_t purge_ms_err[] = {
- 0x0d,
- TEST_IMSI_IE,
- 0x02, 0x01, 0x03, /* Illegal MS */
- };
-
- static const uint8_t purge_ms_res[] = {
- 0x0e,
- TEST_IMSI_IE,
- 0x07, 0x00,
- };
-
- static const struct test {
- char *name;
- const uint8_t *data;
- size_t data_len;
- } test_messages[] = {
- {"Send Authentication Info Request",
- send_auth_info_req, sizeof(send_auth_info_req)},
- {"Send Authentication Info Error",
- send_auth_info_err, sizeof(send_auth_info_err)},
- {"Send Authentication Info Result",
- send_auth_info_res, sizeof(send_auth_info_res)},
- {"Update Location Request",
- update_location_req, sizeof(update_location_req)},
- {"Update Location Error",
- update_location_err, sizeof(update_location_err)},
- {"Update Location Result",
- update_location_res, sizeof(update_location_res)},
- {"Location Cancellation Request",
- location_cancellation_req, sizeof(location_cancellation_req)},
- {"Location Cancellation Error",
- location_cancellation_err, sizeof(location_cancellation_err)},
- {"Location Cancellation Result",
- location_cancellation_res, sizeof(location_cancellation_res)},
- {"Purge MS Request",
- purge_ms_req, sizeof(purge_ms_req)},
- {"Purge MS Error",
- purge_ms_err, sizeof(purge_ms_err)},
- {"Purge MS Result",
- purge_ms_res, sizeof(purge_ms_res)},
- };
-
- printf("Test GSUP message decoding/encoding\n");
-
- for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) {
- const struct test *t = &test_messages[test_idx];
- struct gprs_gsup_message gm = {0};
- struct msgb *msg = msgb_alloc(4096, "gsup_test");
-
- printf(" Testing %s\n", t->name);
-
- rc = gprs_gsup_decode(t->data, t->data_len, &gm);
- OSMO_ASSERT(rc >= 0);
-
- gprs_gsup_encode(msg, &gm);
-
- fprintf(stderr, " generated message: %s\n", msgb_hexdump(msg));
- fprintf(stderr, " original message: %s\n", osmo_hexdump(t->data, t->data_len));
- fprintf(stderr, " IMSI: %s\n", gm.imsi);
- OSMO_ASSERT(strcmp(gm.imsi, TEST_IMSI_STR) == 0);
- OSMO_ASSERT(msgb_length(msg) == t->data_len);
- OSMO_ASSERT(memcmp(msgb_data(msg), t->data, t->data_len) == 0);
-
- msgb_free(msg);
- }
-
- /* simple truncation test */
- for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) {
- int j;
- const struct test *t = &test_messages[test_idx];
- int ie_end = t->data_len;
- struct gprs_gsup_message gm = {0};
- int counter = 0;
- int parse_err = 0;
-
- for (j = t->data_len - 1; j >= 0; --j) {
- rc = gprs_gsup_decode(t->data, j, &gm);
- counter += 1;
-
- VERBOSE_FPRINTF(stderr,
- " partial message decoding: "
- "orig_len = %d, trunc = %d, rc = %d, ie_end = %d\n",
- t->data_len, j, rc, ie_end);
- if (rc >= 0) {
- VERBOSE_FPRINTF(stderr,
- " remaing partial message: %s\n",
- osmo_hexdump(t->data + j, ie_end - j));
-
- OSMO_ASSERT(j <= ie_end - 2);
- OSMO_ASSERT(t->data[j+0] <= GPRS_GSUP_KC_IE);
- OSMO_ASSERT(t->data[j+1] <= ie_end - j - 2);
-
- ie_end = j;
- } else {
- parse_err += 1;
- }
- }
-
- fprintf(stderr,
- " message %d: tested %d truncations, %d parse failures\n",
- test_idx, counter, parse_err);
- }
-
- /* message modification test (relies on ASAN or valgrind being used) */
- for (test_idx = 0; test_idx < ARRAY_SIZE(test_messages); test_idx++) {
- int j;
- const struct test *t = &test_messages[test_idx];
- struct gprs_gsup_message gm = {0};
- uint8_t val;
- int counter = 0;
- int parse_err = 0;
-
- OSMO_ASSERT(sizeof(buf) >= t->data_len);
-
- for (j = t->data_len - 1; j >= 0; --j) {
- memcpy(buf, t->data, t->data_len);
- val = 0;
- do {
- VERBOSE_FPRINTF(stderr,
- "t = %d, len = %d, val = %d\n",
- test_idx, j, val);
- buf[j] = val;
- rc = gprs_gsup_decode(buf, t->data_len, &gm);
- counter += 1;
- if (rc < 0)
- parse_err += 1;
-
- val += 1;
- } while (val != (uint8_t)256);
- }
-
- fprintf(stderr,
- " message %d: tested %d modifications, %d parse failures\n",
- test_idx, counter, parse_err);
- }
-}
-
static void test_gprs_timer_enc_dec(void)
{
int i, u, secs, tmr;
@@ -705,8 +229,6 @@ int main(int argc, char **argv)
test_8_4_2();
test_gsm_03_03_apn();
- test_tlv_shift_functions();
- test_gsup_messages_dec_enc();
test_gprs_timer_enc_dec();
printf("Done.\n");
diff --git a/openbsc/tests/gprs/gprs_test.ok b/openbsc/tests/gprs/gprs_test.ok
index cf710769e..da7888c6a 100644
--- a/openbsc/tests/gprs/gprs_test.ok
+++ b/openbsc/tests/gprs/gprs_test.ok
@@ -13,19 +13,5 @@ N(U) = 511, V(UR) = 511 => new
N(U) = 510, V(UR) = 511 => retransmit
N(U) = 481, V(UR) = 511 => retransmit
N(U) = 479, V(UR) = 511 => new
-Test shift functions
-Test GSUP message decoding/encoding
- Testing Send Authentication Info Request
- Testing Send Authentication Info Error
- Testing Send Authentication Info Result
- Testing Update Location Request
- Testing Update Location Error
- Testing Update Location Result
- Testing Location Cancellation Request
- Testing Location Cancellation Error
- Testing Location Cancellation Result
- Testing Purge MS Request
- Testing Purge MS Error
- Testing Purge MS Result
Test GPRS timer decoding/encoding
Done.