forked from acouzens/open5gs
service request message is tested.
You can find the usage nas_message_test8 in test/nas_message_test.c
This commit is contained in:
parent
f48bbbd35b
commit
880eee1a16
|
@ -26,7 +26,7 @@
|
|||
/*******************************************************************************
|
||||
* This file had been created by gtpv2c_tlv.py script v0.1.0
|
||||
* Please do not modify this file but regenerate it via script.
|
||||
* Created on: 2017-04-26 11:58:32.367002 by acetcom
|
||||
* Created on: 2017-04-26 12:23:52.117713 by acetcom
|
||||
* from 24301-d80.docx
|
||||
******************************************************************************/
|
||||
|
||||
|
@ -1669,6 +1669,9 @@ status_t nas_emm_decode(nas_message_t *message, pkbuf_t *pkbuf)
|
|||
if (message->emm.h.security_header_type >=
|
||||
NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE)
|
||||
{
|
||||
d_assert(pkbuf_header(pkbuf, 1) == CORE_OK,
|
||||
return CORE_ERROR, "pkbuf_header error");
|
||||
decoded -= 1;
|
||||
size = nas_decode_service_request(message, pkbuf);
|
||||
d_assert(size >= CORE_OK, return CORE_ERROR, "decode error");
|
||||
decoded += size;
|
||||
|
@ -1869,6 +1872,7 @@ status_t nas_esm_decode(nas_message_t *message, pkbuf_t *pkbuf)
|
|||
return CORE_OK;
|
||||
}
|
||||
|
||||
#if 0 /* deprecated */
|
||||
status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf)
|
||||
{
|
||||
nas_security_header_t *h = NULL;
|
||||
|
@ -1885,3 +1889,4 @@ status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf)
|
|||
d_assert(0, return CORE_ERROR,
|
||||
"Invalid Protocol : %d", h->protocol_discriminator);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
/*******************************************************************************
|
||||
* This file had been created by gtpv2c_tlv.py script v0.1.0
|
||||
* Please do not modify this file but regenerate it via script.
|
||||
* Created on: 2017-04-26 11:58:32.382927 by acetcom
|
||||
* Created on: 2017-04-26 12:23:52.139199 by acetcom
|
||||
* from 24301-d80.docx
|
||||
******************************************************************************/
|
||||
|
||||
|
@ -1907,6 +1907,9 @@ status_t nas_emm_encode(pkbuf_t **pkbuf, nas_message_t *message)
|
|||
if (message->emm.h.security_header_type >=
|
||||
NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE)
|
||||
{
|
||||
d_assert(pkbuf_header(*pkbuf, 1) == CORE_OK,
|
||||
return CORE_ERROR, "pkbuf_header error");
|
||||
encoded -= 1;
|
||||
size = nas_encode_service_request(*pkbuf, message);
|
||||
d_assert(size >= 0, return CORE_ERROR, "decode error");
|
||||
encoded += size;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
/*******************************************************************************
|
||||
* This file had been created by gtpv2c_tlv.py script v0.1.0
|
||||
* Please do not modify this file but regenerate it via script.
|
||||
* Created on: 2017-04-26 11:58:32.330203 by acetcom
|
||||
* Created on: 2017-04-26 12:23:52.084610 by acetcom
|
||||
* from 24301-d80.docx
|
||||
******************************************************************************/
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
/*******************************************************************************
|
||||
* This file had been created by gtpv2c_tlv.py script v0.1.0
|
||||
* Please do not modify this file but regenerate it via script.
|
||||
* Created on: 2017-04-26 11:58:32.323731 by acetcom
|
||||
* Created on: 2017-04-26 12:23:52.079646 by acetcom
|
||||
* from 24301-d80.docx
|
||||
******************************************************************************/
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
/*******************************************************************************
|
||||
* This file had been created by gtpv2c_tlv.py script v0.1.0
|
||||
* Please do not modify this file but regenerate it via script.
|
||||
* Created on: 2017-04-26 11:58:32.345942 by acetcom
|
||||
* Created on: 2017-04-26 12:23:52.097586 by acetcom
|
||||
* from 24301-d80.docx
|
||||
******************************************************************************/
|
||||
|
||||
|
|
|
@ -703,6 +703,9 @@ f.write("""status_t nas_emm_decode(nas_message_t *message, pkbuf_t *pkbuf)
|
|||
if (message->emm.h.security_header_type >=
|
||||
NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE)
|
||||
{
|
||||
d_assert(pkbuf_header(pkbuf, 1) == CORE_OK,
|
||||
return CORE_ERROR, "pkbuf_header error");
|
||||
decoded -= 1;
|
||||
size = nas_decode_service_request(message, pkbuf);
|
||||
d_assert(size >= CORE_OK, return CORE_ERROR, "decode error");
|
||||
decoded += size;
|
||||
|
@ -781,6 +784,7 @@ f.write(""" default:
|
|||
return CORE_OK;
|
||||
}
|
||||
|
||||
#if 0 /* deprecated */
|
||||
status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf)
|
||||
{
|
||||
nas_security_header_t *h = NULL;
|
||||
|
@ -797,6 +801,7 @@ status_t nas_plain_decode(nas_message_t *message, pkbuf_t *pkbuf)
|
|||
d_assert(0, return CORE_ERROR,
|
||||
"Invalid Protocol : %d", h->protocol_discriminator);
|
||||
}
|
||||
#endif
|
||||
""")
|
||||
|
||||
f.close()
|
||||
|
@ -872,6 +877,9 @@ f.write("""status_t nas_emm_encode(pkbuf_t **pkbuf, nas_message_t *message)
|
|||
if (message->emm.h.security_header_type >=
|
||||
NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE)
|
||||
{
|
||||
d_assert(pkbuf_header(*pkbuf, 1) == CORE_OK,
|
||||
return CORE_ERROR, "pkbuf_header error");
|
||||
encoded -= 1;
|
||||
size = nas_encode_service_request(*pkbuf, message);
|
||||
d_assert(size >= 0, return CORE_ERROR, "decode error");
|
||||
encoded += size;
|
||||
|
|
|
@ -18,6 +18,7 @@ status_t nas_security_encode(
|
|||
switch(message->h.security_header_type)
|
||||
{
|
||||
case NAS_SECURITY_HEADER_PLAIN_NAS_MESSAGE:
|
||||
case NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE:
|
||||
return nas_plain_encode(pkbuf, message);
|
||||
case NAS_SECURITY_HEADER_INTEGRITY_PROTECTED:
|
||||
integrity_protected = 1;
|
||||
|
@ -127,6 +128,7 @@ status_t nas_security_decode(mme_ue_t *ue, pkbuf_t *pkbuf)
|
|||
switch(h->security_header_type)
|
||||
{
|
||||
case NAS_SECURITY_HEADER_PLAIN_NAS_MESSAGE:
|
||||
case NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE:
|
||||
return CORE_OK;
|
||||
case NAS_SECURITY_HEADER_INTEGRITY_PROTECTED:
|
||||
integrity_protected = 1;
|
||||
|
|
|
@ -244,6 +244,54 @@ static void nas_message_test7(abts_case *tc, void *data)
|
|||
pkbuf_free(pkbuf);
|
||||
}
|
||||
|
||||
static void nas_message_test8(abts_case *tc, void *data)
|
||||
{
|
||||
/* Security Request */
|
||||
char *payload = "c7a8640c";
|
||||
char buffer[4];
|
||||
|
||||
nas_message_t message;
|
||||
pkbuf_t *pkbuf;
|
||||
status_t rv;
|
||||
char hexbuf[MAX_SDU_LEN];
|
||||
nas_service_request_t *service_request = &message.emm.service_request;
|
||||
nas_ksi_and_sequence_number_t *ksi_and_sequence_number =
|
||||
&service_request->ksi_and_sequence_number;
|
||||
|
||||
pkbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
||||
ABTS_PTR_NOTNULL(tc, pkbuf);
|
||||
pkbuf->len = 4;
|
||||
memcpy(pkbuf->payload,
|
||||
CORE_HEX(payload, strlen(payload), hexbuf), pkbuf->len);
|
||||
|
||||
/* Decode service request */
|
||||
rv = nas_emm_decode(&message, pkbuf);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
ABTS_INT_EQUAL(tc, 5, ksi_and_sequence_number->ksi);
|
||||
ABTS_INT_EQUAL(tc, 8, ksi_and_sequence_number->sequence_number);
|
||||
ABTS_INT_EQUAL(tc, 0x640c, service_request->message_authentication_code);
|
||||
|
||||
pkbuf_free(pkbuf);
|
||||
|
||||
/* Encode service request */
|
||||
memset(&message, 0, sizeof(message));
|
||||
message.emm.h.protocol_discriminator = NAS_PROTOCOL_DISCRIMINATOR_EMM;
|
||||
message.emm.h.security_header_type =
|
||||
NAS_SECURITY_HEADER_FOR_SERVICE_REQUEST_MESSAGE;
|
||||
|
||||
ksi_and_sequence_number->ksi = 5;
|
||||
ksi_and_sequence_number->sequence_number = 8;
|
||||
service_request->message_authentication_code = 0x640c;
|
||||
|
||||
rv = nas_plain_encode(&pkbuf, &message);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
ABTS_INT_EQUAL(tc, sizeof(buffer), pkbuf->len);
|
||||
ABTS_TRUE(tc, memcmp(CORE_HEX(payload, strlen(payload), buffer),
|
||||
pkbuf->payload, pkbuf->len) == 0);
|
||||
|
||||
pkbuf_free(pkbuf);
|
||||
}
|
||||
|
||||
abts_suite *test_nas_message(abts_suite *suite)
|
||||
{
|
||||
suite = ADD_SUITE(suite)
|
||||
|
@ -255,6 +303,7 @@ abts_suite *test_nas_message(abts_suite *suite)
|
|||
abts_run_test(suite, nas_message_test5, NULL);
|
||||
abts_run_test(suite, nas_message_test6, NULL);
|
||||
abts_run_test(suite, nas_message_test7, NULL);
|
||||
abts_run_test(suite, nas_message_test8, NULL);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue