diff options
Diffstat (limited to 'src/shared/libosmocore/tests')
-rw-r--r-- | src/shared/libosmocore/tests/Makefile.am | 2 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/auth/milenage_test.c | 20 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/auth/milenage_test.ok | 2 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/gsm0808/Makefile.am | 6 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/gsm0808/gsm0808_test.c | 269 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok | 15 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/lapd/lapd_test.c | 31 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/lapd/lapd_test.ok | 4 | ||||
-rw-r--r-- | src/shared/libosmocore/tests/testsuite.at | 6 |
9 files changed, 346 insertions, 9 deletions
diff --git a/src/shared/libosmocore/tests/Makefile.am b/src/shared/libosmocore/tests/Makefile.am index 348355f2..eff1ac44 100644 --- a/src/shared/libosmocore/tests/Makefile.am +++ b/src/shared/libosmocore/tests/Makefile.am @@ -1,5 +1,5 @@ if ENABLE_TESTS -SUBDIRS = timer sms ussd smscb bits a5 conv auth lapd +SUBDIRS = timer sms ussd smscb bits a5 conv auth lapd gsm0808 if ENABLE_MSGFILE SUBDIRS += msgfile endif diff --git a/src/shared/libosmocore/tests/auth/milenage_test.c b/src/shared/libosmocore/tests/auth/milenage_test.c index da7c800a..7c996f02 100644 --- a/src/shared/libosmocore/tests/auth/milenage_test.c +++ b/src/shared/libosmocore/tests/auth/milenage_test.c @@ -37,6 +37,24 @@ static struct osmo_sub_auth_data test_aud = { }, }; +static int opc_test(const struct osmo_sub_auth_data *aud) +{ + int rc; + uint8_t opc[16]; +#if 0 + const uint8_t op[16] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; +#else + const uint8_t op[16] = { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 }; +#endif + + rc = milenage_opc_gen(opc, aud->u.umts.k, op); + + printf("OP:\t%s\n", osmo_hexdump(op, sizeof(op))); + printf("OPC:\t%s\n", osmo_hexdump(opc, sizeof(opc))); + return rc; +} + int main(int argc, char **argv) { struct osmo_auth_vector _vec; @@ -73,6 +91,8 @@ int main(int argc, char **argv) printf("AUTS success: SEQ.MS = %lu\n", test_aud.u.umts.sqn); } + opc_test(&test_aud); + exit(0); } diff --git a/src/shared/libosmocore/tests/auth/milenage_test.ok b/src/shared/libosmocore/tests/auth/milenage_test.ok index 66337ca9..00ffc222 100644 --- a/src/shared/libosmocore/tests/auth/milenage_test.ok +++ b/src/shared/libosmocore/tests/auth/milenage_test.ok @@ -6,3 +6,5 @@ RES: e9 fc 88 cc c8 a3 53 81 SRES: 21 5f db 4d Kc: 6d e8 16 a7 59 a4 29 12 AUTS success: SEQ.MS = 33 +OP: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +OPC: c6 a1 3b 37 87 8f 5b 82 6f 4f 81 62 a1 c8 d8 79 diff --git a/src/shared/libosmocore/tests/gsm0808/Makefile.am b/src/shared/libosmocore/tests/gsm0808/Makefile.am new file mode 100644 index 00000000..a238e7f3 --- /dev/null +++ b/src/shared/libosmocore/tests/gsm0808/Makefile.am @@ -0,0 +1,6 @@ +INCLUDES = $(all_includes) -I$(top_srcdir)/include +noinst_PROGRAMS = gsm0808_test +EXTRA_DIST = gsm0808_test.ok + +gsm0808_test_SOURCES = gsm0808_test.c +gsm0808_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la diff --git a/src/shared/libosmocore/tests/gsm0808/gsm0808_test.c b/src/shared/libosmocore/tests/gsm0808/gsm0808_test.c new file mode 100644 index 00000000..7e5e97b5 --- /dev/null +++ b/src/shared/libosmocore/tests/gsm0808/gsm0808_test.c @@ -0,0 +1,269 @@ +/* + * (C) 2012 by Holger Hans Peter Freyther + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include <osmocom/gsm/gsm0808.h> + +#include <stdio.h> +#include <stdlib.h> + +#define VERIFY(msg, data, len) \ + if (msgb_l3len(msg) != len) { \ + printf("%s:%d Length don't match: %d vs. %d. %s\n", \ + __func__, __LINE__, msgb_l3len(msg), len, \ + osmo_hexdump(msg->l3h, msgb_l3len(msg))); \ + abort(); \ + } else if (memcmp(msg->l3h, data, len) != 0) { \ + printf("%s:%d didn't match: got: %s\n", \ + __func__, __LINE__, \ + osmo_hexdump(msg->l3h, msgb_l3len(msg))); \ + abort(); \ + } + + +static void test_create_layer3(void) +{ + static const uint8_t res[] = { + 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62, + 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 }; + struct msgb *msg, *in_msg; + printf("Testing creating Layer3\n"); + + in_msg = msgb_alloc_headroom(512, 128, "foo"); + in_msg->l3h = in_msg->data; + msgb_v_put(in_msg, 0x23); + + msg = gsm0808_create_layer3(in_msg, 0x1122, 0x2244, 0x3366, 0x4488); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); + msgb_free(in_msg); +} + +static void test_create_reset() +{ + static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 }; + struct msgb *msg; + + printf("Testing creating Reset\n"); + msg = gsm0808_create_reset(); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); +} + +static void test_create_clear_command() +{ + static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 }; + struct msgb *msg; + + printf("Testing creating Clear Command\n"); + msg = gsm0808_create_clear_command(0x23); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); +} + +static void test_create_clear_complete() +{ + static const uint8_t res[] = { 0x00, 0x01, 0x21 }; + struct msgb *msg; + + printf("Testing creating Clear Complete\n"); + msg = gsm0808_create_clear_complete(); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); +} + +static void test_create_cipher_complete() +{ + static const uint8_t res1[] = { + 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 }; + static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04}; + struct msgb *l3, *msg; + + printf("Testing creating Cipher Complete\n"); + l3 = msgb_alloc_headroom(512, 128, "l3h"); + l3->l3h = l3->data; + msgb_v_put(l3, 0x23); + msgb_v_put(l3, 0x42); + msgb_v_put(l3, 0x21); + + /* with l3 data */ + msg = gsm0808_create_cipher_complete(l3, 4); + VERIFY(msg, res1, ARRAY_SIZE(res1)); + msgb_free(msg); + + /* with l3 data but short */ + l3->len -= 1; + l3->tail -= 1; + msg = gsm0808_create_cipher_complete(l3, 4); + VERIFY(msg, res2, ARRAY_SIZE(res2)); + msgb_free(msg); + + /* without l3 data */ + msg = gsm0808_create_cipher_complete(NULL, 4); + VERIFY(msg, res2, ARRAY_SIZE(res2)); + msgb_free(msg); + + + msgb_free(l3); +} + +static void test_create_cipher_reject() +{ + static const uint8_t res[] = { 0x00, 0x02, 0x59, 0x23 }; + struct msgb *msg; + + printf("Testing creating Cipher Reject\n"); + msg = gsm0808_create_cipher_reject(0x23); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); +} + +static void test_create_cm_u() +{ + static const uint8_t res[] = { + 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 }; + static const uint8_t res2o[] = { + 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 }; + struct msgb *msg; + const uint8_t cm2 = 0x23; + const uint8_t cm3 = 0x42; + + printf("Testing creating CM U\n"); + msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1); + VERIFY(msg, res, ARRAY_SIZE(res)); + + msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0); + VERIFY(msg, res2o, ARRAY_SIZE(res2o)); + + msgb_free(msg); +} + +static void test_create_sapi_reject() +{ + static const uint8_t res[] = { 0x00, 0x03, 0x25, 0x03, 0x25 }; + struct msgb *msg; + + printf("Testing creating SAPI Reject\n"); + msg = gsm0808_create_sapi_reject(3); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); +} + +static void test_create_ass_compl() +{ + static const uint8_t res1[] = { + 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, + 0x11, 0x40, 0x22 }; + static const uint8_t res2[] = { + 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11}; + struct msgb *msg; + + printf("Testing creating Assignment Complete\n"); + msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22); + VERIFY(msg, res1, ARRAY_SIZE(res1)); + msgb_free(msg); + + msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0); + VERIFY(msg, res2, ARRAY_SIZE(res2)); + msgb_free(msg); +} + +static void test_create_ass_fail() +{ + static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 }; + static const uint8_t res2[] = { + 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02}; + uint8_t rr_res = 2; + struct msgb *msg; + + printf("Testing creating Assignment Failure\n"); + msg = gsm0808_create_assignment_failure(0x23, NULL); + VERIFY(msg, res1, ARRAY_SIZE(res1)); + msgb_free(msg); + + msg = gsm0808_create_assignment_failure(0x23, &rr_res); + VERIFY(msg, res2, ARRAY_SIZE(res2)); + msgb_free(msg); +} + +static void test_create_clear_rqst() +{ + static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 }; + struct msgb *msg; + + printf("Testing creating Clear Request\n"); + msg = gsm0808_create_clear_rqst(0x23); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); +} + +static void test_create_dtap() +{ + static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 }; + struct msgb *msg, *l3; + + printf("Testing creating DTAP\n"); + l3 = msgb_alloc_headroom(512, 128, "test"); + l3->l3h = l3->data; + msgb_v_put(l3, 0x23); + msgb_v_put(l3, 0x42); + + msg = gsm0808_create_dtap(l3, 0x3); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); + msgb_free(l3); +} + +static void test_prepend_dtap() +{ + static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 }; + struct msgb *in_msg; + + printf("Testing prepend DTAP\n"); + + in_msg = msgb_alloc_headroom(512, 128, "test"); + msgb_v_put(in_msg, 0x23); + msgb_v_put(in_msg, 0x42); + + gsm0808_prepend_dtap_header(in_msg, 0x3); + in_msg->l3h = in_msg->data; + VERIFY(in_msg, res, ARRAY_SIZE(res)); + msgb_free(in_msg); +} + +int main(int argc, char **argv) +{ + printf("Testing generation of GSM0808 messages\n"); + test_create_layer3(); + test_create_reset(); + test_create_clear_command(); + test_create_clear_complete(); + test_create_cipher_complete(); + test_create_cipher_reject(); + test_create_cm_u(); + test_create_sapi_reject(); + test_create_ass_compl(); + test_create_ass_fail(); + test_create_clear_rqst(); + test_create_dtap(); + test_prepend_dtap(); + + printf("Done\n"); + return EXIT_SUCCESS; +} diff --git a/src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok b/src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok new file mode 100644 index 00000000..eb431267 --- /dev/null +++ b/src/shared/libosmocore/tests/gsm0808/gsm0808_test.ok @@ -0,0 +1,15 @@ +Testing generation of GSM0808 messages +Testing creating Layer3 +Testing creating Reset +Testing creating Clear Command +Testing creating Clear Complete +Testing creating Cipher Complete +Testing creating Cipher Reject +Testing creating CM U +Testing creating SAPI Reject +Testing creating Assignment Complete +Testing creating Assignment Failure +Testing creating Clear Request +Testing creating DTAP +Testing prepend DTAP +Done diff --git a/src/shared/libosmocore/tests/lapd/lapd_test.c b/src/shared/libosmocore/tests/lapd/lapd_test.c index 8c6b0df2..d58bec65 100644 --- a/src/shared/libosmocore/tests/lapd/lapd_test.c +++ b/src/shared/libosmocore/tests/lapd/lapd_test.c @@ -73,8 +73,8 @@ static const uint8_t cm_padded[] = { }; static const uint8_t mm[] = { - 0x05, 0x24, 0x31, 0x03, 0x50, 0x18, 0x93, 0x08, - 0x29, 0x47, 0x80, 0x00, + 0x00, 0x0c, 0x00, 0x03, 0x01, 0x01, 0x20, 0x02, + 0x00, 0x0b, 0x00, 0x03, 0x05, 0x04, 0x0d }; static const uint8_t dummy1[] = { @@ -95,6 +95,20 @@ static struct msgb *create_mm_id_req(void) struct msgb *msg; msg = msgb_from_array(mm, sizeof(mm)); + msg->l2h = msg->data + 3; + ASSERT(msgb_l2len(msg) == 12); + msg->l3h = msg->l2h + 6; + ASSERT(msgb_l3len(msg) == 6); + + return msg; +} + +static struct msgb *create_empty_msg(void) +{ + struct msgb *msg; + + msg = msgb_from_array(NULL, 0); + ASSERT(msgb_l3len(msg) == 0); rsl_rll_push_l3(msg, RSL_MT_DATA_REQ, 0, 0, 1); return msg; } @@ -194,9 +208,9 @@ static int ms_to_bts_tx_cb(struct msgb *msg, struct lapdm_entity *le, void *_ctx /* ASSERT(msg->data[7] == 0x0 && msg->data[8] == 0x9c); */ /* this should be 0x0 and 0x0... but we have a bug */ } else if (state->ms_read == 1) { - printf("MS: Verifying incoming MM message.\n"); - ASSERT(msgb_l3len(msg) == ARRAY_SIZE(mm)); - ASSERT(memcmp(msg->l3h, mm, msgb_l3len(msg)) == 0); + printf("MS: Verifying incoming MM message: %d\n", msgb_l3len(msg)); + ASSERT(msgb_l3len(msg) == 3); + ASSERT(memcmp(msg->l3h, &mm[12], msgb_l3len(msg)) == 0); } else { printf("MS: Do not know to verify: %d\n", state->ms_read); } @@ -271,7 +285,7 @@ static void test_lapdm_polling() lapdm_rslms_recvmsg(create_dummy_data_req(), &ms_to_bts_channel); - /* 4. And back to the MS */ + /* 4. And back to the MS, but let's move data/l2h apart */ ASSERT(test_state.bts_read == 2) ASSERT(test_state.ms_read == 2); rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp); @@ -284,6 +298,11 @@ static void test_lapdm_polling() rc = lapdm_phsap_dequeue_prim(&bts_to_ms_channel.lapdm_dcch, &pp); ASSERT(rc < 0); + /* check sending an empty L3 message fails */ + rc = lapdm_rslms_recvmsg(create_empty_msg(), &bts_to_ms_channel); + ASSERT(rc == -1); + ASSERT(test_state.ms_read == 2); + /* clean up */ lapdm_channel_exit(&bts_to_ms_channel); lapdm_channel_exit(&ms_to_bts_channel); diff --git a/src/shared/libosmocore/tests/lapd/lapd_test.ok b/src/shared/libosmocore/tests/lapd/lapd_test.ok index 058ac3d7..d67a0a80 100644 --- a/src/shared/libosmocore/tests/lapd/lapd_test.ok +++ b/src/shared/libosmocore/tests/lapd/lapd_test.ok @@ -9,8 +9,8 @@ ms_to_bts_tx_cb: BTS->MS(us) message 9 MS: Verifying incoming primitive. Sending back to MS -ms_to_bts_tx_cb: BTS->MS(us) message 21 -MS: Verifying incoming MM message. +ms_to_bts_tx_cb: BTS->MS(us) message 12 +MS: Verifying incoming MM message: 3 ms_to_bts_l1_cb: MS(us) -> BTS prim message Sending back to BTS diff --git a/src/shared/libosmocore/tests/testsuite.at b/src/shared/libosmocore/tests/testsuite.at index 6aae04d4..69624c12 100644 --- a/src/shared/libosmocore/tests/testsuite.at +++ b/src/shared/libosmocore/tests/testsuite.at @@ -65,3 +65,9 @@ AT_KEYWORDS([lapd]) cat $abs_srcdir/lapd/lapd_test.ok > expout AT_CHECK([$abs_top_builddir/tests/lapd/lapd_test], [], [expout], [ignore]) AT_CLEANUP + +AT_SETUP([gsm0808]) +AT_KEYWORDS([gsm0808]) +cat $abs_srcdir/gsm0808/gsm0808_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/gsm0808/gsm0808_test], [], [expout], [ignore]) +AT_CLEANUP |