forked from acouzens/open5gs
05f74087e0
Now, we'll use 10.1.35.x network for loopback test
301 lines
9.9 KiB
C
301 lines
9.9 KiB
C
#include "core_debug.h"
|
|
#include "core_pkbuf.h"
|
|
#include "core_lib.h"
|
|
|
|
#include "mme_context.h"
|
|
#include "s1ap_message.h"
|
|
|
|
#include "testutil.h"
|
|
#include "tests1ap.h"
|
|
|
|
/**************************************************************
|
|
* eNB : MACRO
|
|
* UE : IMSI
|
|
* Protocol Configuration Options in ESM information response */
|
|
static void nas_sm_test1(abts_case *tc, void *data)
|
|
{
|
|
status_t rv;
|
|
net_sock_t *sock;
|
|
pkbuf_t *sendbuf;
|
|
pkbuf_t *recvbuf;
|
|
s1ap_message_t message;
|
|
int rc;
|
|
int i;
|
|
int msgindex = 0;
|
|
|
|
c_uint8_t tmp[MAX_SDU_LEN];
|
|
char *_authentication_request =
|
|
"000b403b00000300 000005c00100009d 000800020001001a 0025240752002008"
|
|
"0c3818183b522614 162c07601d0d10f1 1b89a2a8de8000ad 0ccf7f55e8b20d";
|
|
char *_security_mode_command =
|
|
"000b402700000300 000005c00100009d 000800020001001a 00111037f933b5d5"
|
|
"00075d010005e060 c04070";
|
|
char *_esm_information_request =
|
|
"000b402000000300 000005c00100009d 000800020001001a 000a092779012320"
|
|
"010221d9";
|
|
char *_initial_context_setup_request =
|
|
"00090080e4000006 00000005c0010000 9d00080002000100 42000a1806400000"
|
|
"6006400000001800 809200003400808c 4540092000000000 000000000f800a01"
|
|
"23d8000000017527 daddd87002074202 49064000f1105ba0 004c5221c10509ff"
|
|
"ffffff0908696e74 65726e657405012d 2d2d715e06000000 000404272980c223"
|
|
"0403000004802110 0200001081060808 0808830604040404 000d040808080800"
|
|
"0d0404040404500b f600f11000020104 0001fb5312172c59 49640125006b0005"
|
|
"1c000c0000004900 203311c603c6a6d6 7f695e5ac02bb75b 381b693c3893a6d9"
|
|
"32fd91823544e3e7 9b";
|
|
char *_emm_information =
|
|
"000b402a00000300 000005c00100009d 000800020001001a 001413279fcc7266"
|
|
"0307614771304112 527563490100";
|
|
|
|
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_ERROR);
|
|
|
|
/* eNB connects to MME */
|
|
sock = tests1ap_enb_connect();
|
|
ABTS_PTR_NOTNULL(tc, sock);
|
|
|
|
/* Send S1-Setup Reqeust */
|
|
rv = tests1ap_build_setup_req(&sendbuf, 0x54f64);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive S1-Setup Response */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
ABTS_INT_NEQUAL(tc, 0, rc);
|
|
rv = s1ap_decode_pdu(&message, recvbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
s1ap_free_pdu(&message);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send Initial-UE Message */
|
|
mme_self()->mme_ue_s1ap_id = 16777372;
|
|
rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive Authentication Request */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
ABTS_INT_NEQUAL(tc, 0, rc);
|
|
recvbuf->len = 63;
|
|
ABTS_TRUE(tc, memcmp(recvbuf->payload,
|
|
CORE_HEX(_authentication_request, strlen(_authentication_request), tmp),
|
|
recvbuf->len) == 0);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send Authentication Response */
|
|
rv = tests1ap_build_authentication_response(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive Security mode Command */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
recvbuf->len = 43;
|
|
ABTS_TRUE(tc, memcmp(recvbuf->payload,
|
|
CORE_HEX(_security_mode_command, strlen(_security_mode_command), tmp),
|
|
recvbuf->len) == 0);
|
|
ABTS_INT_NEQUAL(tc, 0, rc);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send Security mode Complete */
|
|
rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive ESM Information Request */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
recvbuf->len = 36;
|
|
ABTS_TRUE(tc, memcmp(recvbuf->payload,
|
|
CORE_HEX(_esm_information_request, strlen(_security_mode_command), tmp),
|
|
recvbuf->len) == 0);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send ESM Information Response */
|
|
rv = tests1ap_build_esm_information_response(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive Initial Context Setup Request +
|
|
* Attach Accept +
|
|
* Activate Default Bearer Context Request */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
recvbuf->len = 233;
|
|
ABTS_TRUE(tc, memcmp(recvbuf->payload,
|
|
CORE_HEX(_initial_context_setup_request,
|
|
strlen(_initial_context_setup_request), tmp),
|
|
recvbuf->len) == 0);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send UE Capability Info Indication */
|
|
rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
core_sleep(time_from_msec(300));
|
|
|
|
/* Send Initial Context Setup Response */
|
|
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Send Attach Complete + Activate default EPS bearer cotext accept */
|
|
rv = tests1ap_build_attach_complete(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive EMM information */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
recvbuf->len = 46;
|
|
CORE_HEX(_emm_information, strlen(_emm_information), tmp);
|
|
ABTS_TRUE(tc, memcmp(recvbuf->payload, tmp, 28) == 0);
|
|
ABTS_TRUE(tc, memcmp(recvbuf->payload+43, tmp+43, 3) == 0);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* eNB disonncect from MME */
|
|
rv = tests1ap_enb_close(sock);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
core_sleep(time_from_msec(300));
|
|
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_FULL);
|
|
}
|
|
|
|
/**************************************************************
|
|
* eNB : HOME
|
|
* UE : IMSI
|
|
* Protocol Configuration Options in PDN Connectivity Request */
|
|
static void nas_sm_test2(abts_case *tc, void *data)
|
|
{
|
|
status_t rv;
|
|
net_sock_t *sock;
|
|
pkbuf_t *sendbuf;
|
|
pkbuf_t *recvbuf;
|
|
s1ap_message_t message;
|
|
int rc;
|
|
int i;
|
|
int msgindex = 1;
|
|
|
|
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_ERROR);
|
|
|
|
c_uint8_t tmp[MAX_SDU_LEN];
|
|
/* eNB connects to MME */
|
|
sock = tests1ap_enb_connect();
|
|
ABTS_PTR_NOTNULL(tc, sock);
|
|
|
|
/* Send S1-Setup Reqeust */
|
|
rv = tests1ap_build_setup_req(&sendbuf, 0x002343d);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive S1-Setup Response */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
ABTS_INT_NEQUAL(tc, 0, rc);
|
|
rv = s1ap_decode_pdu(&message, recvbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
s1ap_free_pdu(&message);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send Initial-UE Message */
|
|
rv = tests1ap_build_initial_ue_msg(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive Authentication Request */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
ABTS_INT_NEQUAL(tc, 0, rc);
|
|
recvbuf->len = 60;
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send Authentication Response */
|
|
rv = tests1ap_build_authentication_response(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive Security mode Command */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
recvbuf->len = 40;
|
|
ABTS_INT_NEQUAL(tc, 0, rc);
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send Security mode Complete */
|
|
rv = tests1ap_build_security_mode_complete(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive ESM Information Request */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
recvbuf->len = 33;
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send ESM Information Response */
|
|
rv = tests1ap_build_esm_information_response(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Receive Initial Context Setup Request +
|
|
* Attach Accept +
|
|
* Activate Default Bearer Context Request */
|
|
recvbuf = pkbuf_alloc(0, MAX_SDU_LEN);
|
|
rc = tests1ap_enb_read(sock, recvbuf);
|
|
recvbuf->len = 208;
|
|
pkbuf_free(recvbuf);
|
|
|
|
/* Send UE Capability Info Indication */
|
|
rv = tests1ap_build_ue_capability_info_indication(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
core_sleep(time_from_msec(300));
|
|
|
|
/* Send Initial Context Setup Response */
|
|
rv = tests1ap_build_initial_context_setup_response(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
/* Send EMM Status */
|
|
rv = tests1ap_build_emm_status(&sendbuf, msgindex);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
rv = tests1ap_enb_send(sock, sendbuf);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
core_sleep(time_from_msec(300));
|
|
|
|
/* eNB disonncect from MME */
|
|
rv = tests1ap_enb_close(sock);
|
|
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
|
|
|
core_sleep(time_from_msec(300));
|
|
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_FULL);
|
|
}
|
|
|
|
abts_suite *test_nas_sm(abts_suite *suite)
|
|
{
|
|
suite = ADD_SUITE(suite)
|
|
|
|
abts_run_test(suite, nas_sm_test1, NULL);
|
|
abts_run_test(suite, nas_sm_test2, NULL);
|
|
|
|
return suite;
|
|
}
|