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
This commit is contained in:
Philipp Maier 2017-03-29 15:50:05 +02:00 committed by Harald Welte
parent 783047e86e
commit b478dd38d2
5 changed files with 78 additions and 0 deletions

View File

@ -35,6 +35,8 @@ struct msgb *gsm0808_create_reset(void);
struct msgb *gsm0808_create_reset_ack(void);
struct msgb *gsm0808_create_clear_command(uint8_t reason);
struct msgb *gsm0808_create_clear_complete(void);
struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
const uint8_t *cipher_response_mode);
struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id);
struct msgb *gsm0808_create_cipher_reject(uint8_t cause);
struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,

View File

@ -131,6 +131,39 @@ struct msgb *gsm0808_create_clear_command(uint8_t reason)
return msg;
}
struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
const uint8_t *cipher_response_mode)
{
/* See also: 3GPP TS 48.008 3.2.1.30 CIPHER MODE COMMAND */
struct msgb *msg;
/* Mandatory emelent! */
OSMO_ASSERT(ei);
msg =
msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
"cipher-mode-command");
if (!msg)
return NULL;
/* Message Type 3.2.2.1 */
msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_CMD);
/* Encryption Information 3.2.2.10 */
gsm0808_enc_encrypt_info(msg, ei);
/* Cipher Response Mode 3.2.2.34 */
if (cipher_response_mode)
msgb_tv_put(msg, GSM0808_IE_CIPHER_RESPONSE_MODE,
*cipher_response_mode);
/* pre-pend the header */
msg->l3h =
msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
return msg;
}
struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id)
{
struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,

View File

@ -128,6 +128,7 @@ gsm0808_create_assignment_completed;
gsm0808_create_ass_compl;
gsm0808_create_assignment_failure;
gsm0808_create_ass_fail;
gsm0808_create_cipher;
gsm0808_create_cipher_complete;
gsm0808_create_cipher_reject;
gsm0808_create_classmark_update;

View File

@ -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();

View File

@ -4,6 +4,7 @@ Testing creating Layer3 (AoIP)
Testing creating Reset
Testing creating Clear Command
Testing creating Clear Complete
Testing creating Chipher Mode Command
Testing creating Cipher Complete
Testing creating Cipher Reject
Testing creating CM U