open5gs/test/nas_message_test.c

182 lines
6.0 KiB
C
Raw Normal View History

2017-02-15 06:33:39 +00:00
#include "core_debug.h"
#include "core_pkbuf.h"
2017-03-05 06:26:28 +00:00
#include "core_lib.h"
2017-02-15 06:33:39 +00:00
#include "testutil.h"
#include "nas_message.h"
static void nas_message_test1(abts_case *tc, void *data)
{
/* Attach Request */
2017-03-05 06:26:28 +00:00
char *payload =
"17df675aa8050741020bf600f1100002"
"01030003e605f07000001000050215d0"
"11d15200f11030395c0a003103e5e034"
"9011035758a65d0100e0c1";
2017-02-15 06:33:39 +00:00
nas_message_t message;
pkbuf_t *pkbuf;
status_t rv;
2017-03-05 14:36:17 +00:00
pkbuf = pkbuf_alloc(0, MESSAGE_SDU_SIZE);
2017-02-15 06:33:39 +00:00
ABTS_PTR_NOTNULL(tc, pkbuf);
pkbuf->len = 59;
2017-03-07 11:43:37 +00:00
core_ascii_to_hex(payload, strlen(payload), pkbuf->payload, pkbuf->len);
2017-02-15 06:33:39 +00:00
2017-03-08 13:39:28 +00:00
rv = nas_plain_decode(&message, pkbuf);
2017-02-15 06:33:39 +00:00
ABTS_INT_EQUAL(tc, CORE_OK, rv);
pkbuf_free(pkbuf);
}
2017-02-16 09:11:01 +00:00
static void nas_message_test2(abts_case *tc, void *data)
{
/* Attach Accept */
2017-03-05 06:26:28 +00:00
char *payload =
"07420223060014f799303900325201c1"
"01090908696e7465726e657405010ae1"
"000a271b80802110020200108106c0a8"
"a8018306c0a8a801000d04c0a8a80150"
"0bf614f7992345e1000004561300f120"
"fffd2305f400e102d4640123";
char buffer[92];
char *esm_payload =
"5201c101090908696e7465726e657405"
"010ae1000a271b808021100202001081"
"06c0a8a8018306c0a8a801000d04c0a8"
"a801";
char esm_buffer[50];
2017-02-16 09:11:01 +00:00
nas_message_t message;
nas_attach_accept_t *attach_accept = &message.emm.attach_accept;
pkbuf_t *pkbuf = NULL;
status_t rv;
memset(&message, 0, sizeof(message));
message.h.protocol_discriminator = NAS_PROTOCOL_DISCRIMINATOR_EMM;
message.h.message_type = NAS_ATTACH_ACCEPT;
attach_accept->attach_result.result =
NAS_ATTACH_RESULT_COMBINED_EPS_IMSI_ATTACH;
attach_accept->t3412_value.unit =
NAS_GRPS_TIMER_UNIT_MULTIPLES_OF_1_MM;
attach_accept->t3412_value.timer_value = 3;
attach_accept->tai_list.length = 6;
2017-03-05 14:36:17 +00:00
attach_accept->tai_list.type0.plmn.mcc_digit1 = 4;
attach_accept->tai_list.type0.plmn.mcc_digit2 = 1;
attach_accept->tai_list.type0.plmn.mcc_digit3 = 7;
attach_accept->tai_list.type0.plmn.mnc_digit1 = 9;
attach_accept->tai_list.type0.plmn.mnc_digit2 = 9;
attach_accept->tai_list.type0.plmn.mnc_digit3 = 0xf;
2017-03-05 09:09:34 +00:00
attach_accept->tai_list.type0.tac[0] = 12345;
2017-03-05 06:26:28 +00:00
attach_accept->esm_message_container.length = sizeof(esm_buffer);
attach_accept->esm_message_container.buffer =
2017-03-07 11:43:37 +00:00
core_ascii_to_hex(esm_payload, strlen(esm_payload),
esm_buffer, sizeof(esm_buffer));
2017-02-16 09:11:01 +00:00
2017-02-16 12:47:48 +00:00
attach_accept->presencemask |= NAS_ATTACH_ACCEPT_GUTI_PRESENT;
attach_accept->guti.length = 11;
2017-03-05 09:09:34 +00:00
attach_accept->guti.guti.type_of_identity = NAS_EPS_MOBILE_IDENTITY_GUTI;
2017-03-05 14:36:17 +00:00
attach_accept->guti.guti.plmn.mcc_digit1 = 4;
attach_accept->guti.guti.plmn.mcc_digit2 = 1;
attach_accept->guti.guti.plmn.mcc_digit3 = 7;
attach_accept->guti.guti.plmn.mnc_digit1 = 9;
attach_accept->guti.guti.plmn.mnc_digit2 = 9;
attach_accept->guti.guti.plmn.mnc_digit3 = 0xf;
2017-03-05 09:09:34 +00:00
attach_accept->guti.guti.mme_group_id = 9029;
attach_accept->guti.guti.mme_code = 225;
attach_accept->guti.guti.m_tmsi = 0x00000456;
2017-02-16 12:47:48 +00:00
2017-02-16 14:55:53 +00:00
attach_accept->presencemask |=
NAS_ATTACH_ACCEPT_LOCATION_AREA_IDENTIFICATION_PRESENT;
2017-03-05 14:36:17 +00:00
attach_accept->location_area_identification.plmn.mcc_digit1 = 0;
attach_accept->location_area_identification.plmn.mcc_digit2 = 0;
attach_accept->location_area_identification.plmn.mcc_digit3 = 1;
attach_accept->location_area_identification.plmn.mnc_digit1 = 0;
attach_accept->location_area_identification.plmn.mnc_digit2 = 2;
attach_accept->location_area_identification.plmn.mnc_digit3 = 0xf;
2017-02-16 14:55:53 +00:00
attach_accept->location_area_identification.lac = 0xfffd;
attach_accept->presencemask |= NAS_ATTACH_ACCEPT_MS_IDENTITY_PRESENT;
attach_accept->ms_identity.length = 5;
2017-03-05 09:09:34 +00:00
attach_accept->ms_identity.tmsi.type_of_identity =
2017-02-16 14:55:53 +00:00
NAS_MOBILE_IDENTITY_TMSI;
2017-03-05 09:09:34 +00:00
attach_accept->ms_identity.tmsi.tmsi = 0x00e102d4;
2017-02-16 14:55:53 +00:00
attach_accept->presencemask |=
NAS_ATTACH_ACCEPT_EPS_NETWORK_FEATURE_SUPPORT_PRESENT;
attach_accept->eps_network_feature_support.length = 1;
attach_accept->eps_network_feature_support.esr_ps = 1;
attach_accept->eps_network_feature_support.emc_bs = 1;
attach_accept->eps_network_feature_support.ims_vops = 1;
2017-03-08 13:39:28 +00:00
rv = nas_plain_encode(&pkbuf, &message);
2017-02-16 09:11:01 +00:00
ABTS_INT_EQUAL(tc, CORE_OK, rv);
2017-03-05 06:26:28 +00:00
ABTS_INT_EQUAL(tc, sizeof(buffer), pkbuf->len);
ABTS_TRUE(tc, memcmp(
2017-03-07 11:43:37 +00:00
core_ascii_to_hex(payload, strlen(payload), buffer, sizeof(buffer)),
2017-03-05 06:26:28 +00:00
pkbuf->payload, pkbuf->len) == 0);
2017-02-16 09:11:01 +00:00
pkbuf_free(pkbuf);
}
static void nas_message_test3(abts_case *tc, void *data)
{
2017-03-05 06:26:28 +00:00
char *payload = "074300035200c2";
nas_message_t message;
pkbuf_t *pkbuf;
status_t rv;
2017-03-05 14:36:17 +00:00
pkbuf = pkbuf_alloc(0, MESSAGE_SDU_SIZE);
ABTS_PTR_NOTNULL(tc, pkbuf);
pkbuf->len = 7;
2017-03-07 11:43:37 +00:00
core_ascii_to_hex(payload, strlen(payload), pkbuf->payload, pkbuf->len);
2017-03-08 13:39:28 +00:00
rv = nas_plain_decode(&message, pkbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
pkbuf_free(pkbuf);
}
static void nas_message_test4(abts_case *tc, void *data)
{
/* Attach Reject */
2017-03-05 06:26:28 +00:00
char *payload = "074411";
char buffer[3];
nas_message_t message;
nas_attach_reject_t *attach_reject = &message.emm.attach_reject;
pkbuf_t *pkbuf = NULL;
status_t rv;
memset(&message, 0, sizeof(message));
message.h.protocol_discriminator = NAS_PROTOCOL_DISCRIMINATOR_EMM;
message.h.message_type = NAS_ATTACH_REJECT;
attach_reject->emm_cause = NAS_EMM_CAUSE_NETWORK_FAILURE;
2017-03-08 13:39:28 +00:00
rv = nas_plain_encode(&pkbuf, &message);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
2017-03-05 06:26:28 +00:00
ABTS_INT_EQUAL(tc, sizeof(buffer), pkbuf->len);
ABTS_TRUE(tc, memcmp(
2017-03-07 11:43:37 +00:00
core_ascii_to_hex(payload, strlen(payload), buffer, sizeof(buffer)),
2017-03-05 06:26:28 +00:00
pkbuf->payload, pkbuf->len) == 0);
pkbuf_free(pkbuf);
}
2017-02-15 06:33:39 +00:00
abts_suite *test_nas_message(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, nas_message_test1, NULL);
2017-02-16 09:11:01 +00:00
abts_run_test(suite, nas_message_test2, NULL);
abts_run_test(suite, nas_message_test3, NULL);
2017-03-05 06:26:28 +00:00
abts_run_test(suite, nas_message_test4, NULL);
2017-02-15 06:33:39 +00:00
return suite;
}