From b478dd38d29b0dfdf9d9c4d6f22ec4a24e4c8fcd Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Wed, 29 Mar 2017 15:50:05 +0200 Subject: gsm0808: Add create functions for CIPHER MODE COMMAND gsm0808.h/c lacks functionality to generate CIPHER MODE COMMAND messages. These messages are required if the code is used in an MSC implementation. This commit adds a gsm0808_create_cipher() function, that generates an A/AoiP CIPHER MODE COMMAND message. Change-Id: I8eb1c357860c3e740b0f5d17e1c256bc87920958 --- tests/gsm0808/gsm0808_test.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/gsm0808/gsm0808_test.c') diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c index af457b4d..f33e0bd1 100644 --- a/tests/gsm0808/gsm0808_test.c +++ b/tests/gsm0808/gsm0808_test.c @@ -144,6 +144,46 @@ static void test_create_clear_complete() msgb_free(msg); } +static void test_create_cipher() +{ + static const uint8_t res[] = + { 0x00, 0x0c, 0x53, 0x0a, 0x09, 0x03, 0xaa, + 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42 }; + static const uint8_t res2[] = + { 0x00, 0x0e, 0x53, 0x0a, 0x09, 0x03, 0xaa, + 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x23, 0x42, + GSM0808_IE_CIPHER_RESPONSE_MODE, 0x01 }; + struct msgb *msg; + struct gsm0808_encrypt_info ei; + uint8_t include_imeisv; + + memset(&ei, 0, sizeof(ei)); + ei.perm_algo[0] = GSM0808_ALG_ID_A5_0; + ei.perm_algo[1] = GSM0808_ALG_ID_A5_1; + ei.perm_algo_len = 2; + ei.key[0] = 0xaa; + ei.key[1] = 0xbb; + ei.key[2] = 0xcc; + ei.key[3] = 0xdd; + ei.key[4] = 0xee; + ei.key[5] = 0xff; + ei.key[6] = 0x23; + ei.key[7] = 0x42; + ei.key_len = 8; + include_imeisv = 1; + + printf("Testing creating Chipher Mode Command\n"); + msg = gsm0808_create_cipher(&ei, NULL); + OSMO_ASSERT(msg); + VERIFY(msg, res, ARRAY_SIZE(res)); + msgb_free(msg); + + msg = gsm0808_create_cipher(&ei, &include_imeisv); + OSMO_ASSERT(msg); + VERIFY(msg, res2, ARRAY_SIZE(res2)); + msgb_free(msg); +} + static void test_create_cipher_complete() { static const uint8_t res1[] = { @@ -700,6 +740,7 @@ int main(int argc, char **argv) test_create_reset(); test_create_clear_command(); test_create_clear_complete(); + test_create_cipher(); test_create_cipher_complete(); test_create_cipher_reject(); test_create_cm_u(); -- cgit v1.2.3