forked from acouzens/open5gs
update it
This commit is contained in:
parent
953d63c2db
commit
982dddc4de
|
@ -191,6 +191,10 @@ ue_ctx_t* mme_ctx_ue_add(enb_ctx_t *enb)
|
|||
ue->enb = enb;
|
||||
list_init(&ue->rab_list);
|
||||
|
||||
self.mme_ue_s1ap_id = self.mme_ue_s1ap_id + 1;
|
||||
if (self.mme_ue_s1ap_id == 0) self.mme_ue_s1ap_id = 1;
|
||||
ue->mme_ue_s1ap_id = self.mme_ue_s1ap_id;
|
||||
|
||||
list_append(&enb->ue_list, ue);
|
||||
|
||||
return ue;
|
||||
|
|
|
@ -34,6 +34,8 @@ typedef struct _mme_ctx_t {
|
|||
c_uint16_t enb_s1ap_port;
|
||||
c_uint32_t enb_local_addr; /** Network byte order */
|
||||
|
||||
c_uint32_t mme_ue_s1ap_id;
|
||||
|
||||
plmn_id_t plmn_id;
|
||||
|
||||
/* S1SetupRequest */
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
/**
|
||||
* @file enb_s1ap_state.c
|
||||
*/
|
||||
|
||||
/* Server */
|
||||
#include "sm.h"
|
||||
#include "context.h"
|
||||
#include "event.h"
|
||||
|
||||
/* Core libaray */
|
||||
#define TRACE_MODULE _enb_s1_sm
|
||||
|
||||
#include "core_debug.h"
|
||||
|
||||
#include "s1ap_build.h"
|
||||
#include "s1ap_conv.h"
|
||||
#include "s1ap_path.h"
|
||||
|
||||
status_t enb_s1ap_handle_s1setuprequest(enb_ctx_t *enb, s1ap_message *message);
|
||||
#include "sm.h"
|
||||
#include "context.h"
|
||||
#include "event.h"
|
||||
|
||||
static status_t enb_s1ap_handle_s1setuprequest(
|
||||
enb_ctx_t *enb, s1ap_message *message);
|
||||
static status_t enb_s1ap_handle_initialuemessage(
|
||||
enb_ctx_t *enb, s1ap_message *message);
|
||||
|
||||
void enb_s1ap_state_initial(enb_s1ap_sm_t *s, event_t *e)
|
||||
{
|
||||
|
@ -74,10 +72,14 @@ void enb_s1ap_state_operational(enb_s1ap_sm_t *s, event_t *e)
|
|||
{
|
||||
case S1ap_ProcedureCode_id_S1Setup :
|
||||
{
|
||||
d_info("S1-Setup-Request is received");
|
||||
enb_s1ap_handle_s1setuprequest(enb, &message);
|
||||
break;
|
||||
}
|
||||
case S1ap_ProcedureCode_id_initialUEMessage :
|
||||
{
|
||||
enb_s1ap_handle_initialuemessage(enb, &message);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
d_warn("Not implemented(choice:%d, proc:%d",
|
||||
|
@ -151,7 +153,6 @@ status_t enb_s1ap_handle_s1setuprequest(enb_ctx_t *enb, s1ap_message *message)
|
|||
char buf[INET_ADDRSTRLEN];
|
||||
|
||||
S1ap_S1SetupRequestIEs_t *ies = NULL;
|
||||
status_t rv;
|
||||
pkbuf_t *sendbuf = NULL;
|
||||
c_uint32_t enb_id;
|
||||
|
||||
|
@ -176,30 +177,50 @@ status_t enb_s1ap_handle_s1setuprequest(enb_ctx_t *enb, s1ap_message *message)
|
|||
S1ap_CauseProtocol_message_not_compatible_with_receiver_state;
|
||||
rv = s1ap_build_setup_failure(&sendbuf, cause);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
d_info("eNB-id[0x%x] sends S1-Setup-Request from [%s]", enb_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf));
|
||||
|
||||
enb->enb_id = enb_id;
|
||||
rv = s1ap_build_setup_rsp(&sendbuf);
|
||||
}
|
||||
d_info("eNB[0x%x] sends S1-Setup-Request from [%s]", enb_id,
|
||||
INET_NTOP(&enb->s1ap_sock->remote.sin_addr.s_addr, buf));
|
||||
|
||||
if (rv != CORE_OK)
|
||||
{
|
||||
d_error("Can't build S1-Setup-Response/Failure");
|
||||
return CORE_ERROR;
|
||||
}
|
||||
enb->enb_id = enb_id;
|
||||
|
||||
rv = s1ap_send_to_enb(enb, sendbuf);
|
||||
if (rv != CORE_OK)
|
||||
{
|
||||
d_error("Can't send S1 Setup Response");
|
||||
}
|
||||
d_assert(s1ap_build_setup_rsp(&sendbuf) == CORE_OK,
|
||||
return CORE_ERROR, "build error");
|
||||
d_assert(s1ap_send_to_enb(enb, sendbuf) == CORE_OK,
|
||||
return CORE_ERROR, "send error");
|
||||
|
||||
pkbuf_free(sendbuf);
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t enb_s1ap_handle_initialuemessage(
|
||||
enb_ctx_t *enb, s1ap_message *message)
|
||||
{
|
||||
S1ap_InitialUEMessage_IEs_t *ies = NULL;
|
||||
ue_ctx_t *ue = NULL;
|
||||
|
||||
d_assert(enb, return CORE_ERROR, "Null param");
|
||||
d_assert(message, return CORE_ERROR, "Null param");
|
||||
|
||||
ies = &message->s1ap_InitialUEMessage_IEs;
|
||||
d_assert(ies, return CORE_ERROR, "Null param");
|
||||
|
||||
ue = mme_ctx_ue_add(enb);
|
||||
d_assert(ue, return CORE_ERROR, "Null param");
|
||||
|
||||
ue->enb_ue_s1ap_id = ies->eNB_UE_S1AP_ID;
|
||||
|
||||
d_info("eNB[0x%x] sends Initial-UE Message[eNB-UE-S1AP-ID(%d)]",
|
||||
enb->enb_id, ue->enb_ue_s1ap_id);
|
||||
#if 0
|
||||
fsm_create((fsm_t*)&enb->s1ap_sm,
|
||||
enb_s1ap_state_initial, enb_s1ap_state_final);
|
||||
enb->s1ap_sm.ctx = enb;
|
||||
enb->s1ap_sm.queue_id = s->queue_id;
|
||||
enb->s1ap_sm.tm_service = s->tm_service;
|
||||
fsm_init((fsm_t*)&enb->s1ap_sm, 0);
|
||||
#endif
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ int event_send(msgq_id queue_id, event_t *e)
|
|||
r = msgq_send(queue_id, (const char*)e, EVENT_SIZE);
|
||||
if (r != EVENT_SIZE)
|
||||
{
|
||||
d_error("msgq_send() failed");
|
||||
d_warn("msgq_send() failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ int event_timedrecv(msgq_id queue_id, event_t *e, c_time_t timeout)
|
|||
r = msgq_timedrecv(queue_id, (char*)e, EVENT_SIZE, timeout);
|
||||
if (r != CORE_TIMEUP && r != EVENT_SIZE)
|
||||
{
|
||||
d_error("msgq_timedrecv() failed");
|
||||
d_warn("msgq_timedrecv() failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ void* event_timer_expire_func(
|
|||
r = msgq_send(queue_id, (const char*)&e, EVENT_SIZE);
|
||||
if (r <= 0)
|
||||
{
|
||||
d_error("msgq_send() failed");
|
||||
d_warn("msgq_send() failed");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -134,7 +134,7 @@ void mme_state_operational(mme_sm_t *s, event_t *e)
|
|||
}
|
||||
else
|
||||
{
|
||||
d_error("Can't find eNB-S1 for [%s]!!!",
|
||||
d_warn("Can't find eNB-S1 for [%s]!!!",
|
||||
INET_NTOP(&sock->remote.sin_addr.s_addr, buf));
|
||||
}
|
||||
|
||||
|
|
14
src/mme/sm.h
14
src/mme/sm.h
|
@ -38,6 +38,20 @@ void enb_s1ap_state_final(enb_s1ap_sm_t *s, event_t *e);
|
|||
void enb_s1ap_state_operational(enb_s1ap_sm_t *s, event_t *e);
|
||||
void enb_s1ap_state_exception(enb_s1ap_sm_t *s, event_t *e);
|
||||
|
||||
typedef struct _ue_emm_sm_t {
|
||||
|
||||
fsm_t fsm;
|
||||
void *ctx;
|
||||
msgq_id queue_id;
|
||||
tm_service_t tm_service;
|
||||
|
||||
} ue_emm_sm_t;
|
||||
|
||||
void ue_emm_state_initial(ue_emm_sm_t *s, event_t *e);
|
||||
void ue_emm_state_final(ue_emm_sm_t *s, event_t *e);
|
||||
void ue_emm_state_operational(ue_emm_sm_t *s, event_t *e);
|
||||
void ue_emm_state_exception(ue_emm_sm_t *s, event_t *e);
|
||||
|
||||
#define sm_print(__pe) \
|
||||
d_print("%s(): %s\n", __func__, event_get_name(__pe))
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
#define TRACE_MODULE _ue_emm_sm
|
||||
|
||||
#include "core_debug.h"
|
||||
|
||||
#include "sm.h"
|
||||
#include "context.h"
|
||||
#include "event.h"
|
||||
|
||||
void ue_emm_state_initial(ue_emm_sm_t *s, event_t *e)
|
||||
{
|
||||
d_assert(s, return, "Null param");
|
||||
|
||||
sm_trace(1, e);
|
||||
|
||||
FSM_TRAN(s, &ue_emm_state_operational);
|
||||
}
|
||||
|
||||
void ue_emm_state_final(ue_emm_sm_t *s, event_t *e)
|
||||
{
|
||||
d_assert(s, return, "Null param");
|
||||
|
||||
sm_trace(1, e);
|
||||
}
|
||||
|
||||
void ue_emm_state_operational(ue_emm_sm_t *s, event_t *e)
|
||||
{
|
||||
d_assert(s, return, "Null param");
|
||||
d_assert(e, return, "Null param");
|
||||
|
||||
ue_ctx_t *ue = s->ctx;
|
||||
d_assert(ue, return, "Null param");
|
||||
|
||||
sm_trace(1, e);
|
||||
|
||||
switch (event_get(e))
|
||||
{
|
||||
case FSM_ENTRY_SIG:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case FSM_EXIT_SIG:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case EVT_ENB_S1AP_INF:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
d_error("Unknown event %s", event_get_name(e));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ue_emm_state_exception(ue_emm_sm_t *s, event_t *e)
|
||||
{
|
||||
d_assert(s, return, "Null param");
|
||||
d_assert(e, return, "Null param");
|
||||
|
||||
sm_trace(1, e);
|
||||
|
||||
switch (event_get(e))
|
||||
{
|
||||
case FSM_ENTRY_SIG:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case FSM_EXIT_SIG:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
d_error("Unknown event %s", event_get_name(e));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ testcellwire_SOURCES = \
|
|||
abts.h abts_tests.h testutil.h \
|
||||
abts.c testutil.c tests1ap.h tests1ap.c \
|
||||
s1ap_message_test.c nas_message_test.c security_test.c \
|
||||
s1ap_sm_test.c
|
||||
s1ap_sm_test.c nas_sm_test.c
|
||||
|
||||
testcellwire_LDADD = \
|
||||
$(top_srcdir)/src/libcellwire.la
|
||||
|
|
|
@ -26,6 +26,7 @@ const struct testlist {
|
|||
{test_s1ap_message},
|
||||
{test_s1ap_sm},
|
||||
{test_nas_message},
|
||||
{test_nas_sm},
|
||||
{test_security},
|
||||
};
|
||||
|
||||
|
|
|
@ -157,8 +157,6 @@ static void nas_message_test4(abts_case *tc, void *data)
|
|||
message.h.message_type = NAS_ATTACH_REJECT;
|
||||
attach_reject->emm_cause = NAS_EMM_CAUSE_NETWORK_FAILURE;
|
||||
|
||||
d_msg_to(D_MSG_TO_STDOUT, 1);
|
||||
|
||||
rv = nas_encode_pdu(&pkbuf, &message);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
ABTS_INT_EQUAL(tc, sizeof(buffer), pkbuf->len);
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#include "core_debug.h"
|
||||
#include "core_pkbuf.h"
|
||||
|
||||
#include "s1ap_message.h"
|
||||
|
||||
#include "testutil.h"
|
||||
#include "tests1ap.h"
|
||||
|
||||
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 message;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
/* 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);
|
||||
pkbuf_free(sendbuf);
|
||||
|
||||
/* Receive S1-Setup Response */
|
||||
recvbuf = pkbuf_alloc(0, MSG_SDU_SIZE);
|
||||
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);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
rv = tests1ap_enb_send(sock, sendbuf);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
pkbuf_free(sendbuf);
|
||||
|
||||
/* Receive XXXX */
|
||||
#if 0
|
||||
recvbuf = pkbuf_alloc(0, MSG_SDU_SIZE);
|
||||
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);
|
||||
#endif
|
||||
|
||||
/* eNB disonncect from MME */
|
||||
rv = tests1ap_enb_close(sock);
|
||||
ABTS_INT_EQUAL(tc, CORE_OK, rv);
|
||||
|
||||
core_sleep(time_from_msec(300));
|
||||
}
|
||||
|
||||
abts_suite *test_nas_sm(abts_suite *suite)
|
||||
{
|
||||
suite = ADD_SUITE(suite)
|
||||
|
||||
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_FULL);
|
||||
|
||||
abts_run_test(suite, nas_sm_test1, NULL);
|
||||
|
||||
return suite;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "core_debug.h"
|
||||
#include "core_pkbuf.h"
|
||||
#include "core_lib.h"
|
||||
|
||||
#include "context.h"
|
||||
#include "s1ap_build.h"
|
||||
|
@ -110,3 +111,22 @@ status_t tests1ap_build_setup_req(pkbuf_t **pkbuf, c_uint32_t enb_id)
|
|||
}
|
||||
|
||||
|
||||
status_t tests1ap_build_initial_ue_msg(
|
||||
pkbuf_t **pkbuf)
|
||||
{
|
||||
char *payload =
|
||||
"000c405800000500 0800020001001a00"
|
||||
"302f177ca0b38802 0741020809101010"
|
||||
"3254869104e060c0 4000050221d011d1"
|
||||
"5c0a003103e5e034 9011035758a65d01"
|
||||
"00004300060000f1 105ba00064400800"
|
||||
"00f1101079baf000 86400130";
|
||||
|
||||
*pkbuf = pkbuf_alloc(0, MSG_SDU_SIZE);
|
||||
if (!(*pkbuf)) return CORE_ERROR;
|
||||
|
||||
core_ascii_to_hex(payload, strlen(payload), (*pkbuf)->payload);
|
||||
(*pkbuf)->len = 92;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ CORE_DECLARE(int) tests1ap_enb_read(net_sock_t *sock, pkbuf_t *recvbuf);
|
|||
|
||||
CORE_DECLARE(status_t) tests1ap_build_setup_req(
|
||||
pkbuf_t **pkbuf, c_uint32_t enb_id);
|
||||
CORE_DECLARE(status_t) tests1ap_build_initial_ue_msg(
|
||||
pkbuf_t **pkbuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -38,14 +38,14 @@ void core_assert_ok(abts_case* tc, const char* context, status_t rv,
|
|||
|
||||
void test_terminate(void)
|
||||
{
|
||||
d_msg_to(D_MSG_TO_STDOUT, 1);
|
||||
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_FULL);
|
||||
cellwire_terminate();
|
||||
}
|
||||
|
||||
void test_initialize(void)
|
||||
{
|
||||
cellwire_initialize(NULL, NULL);
|
||||
d_msg_to(D_MSG_TO_STDOUT, 0);
|
||||
d_log_set_level(D_MSG_TO_STDOUT, D_LOG_LEVEL_ERROR);
|
||||
|
||||
inet_pton(AF_INET, "127.0.0.1", &mme_self()->enb_local_addr);
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ void test_initialize(void);
|
|||
abts_suite *test_s1ap_message(abts_suite *suite);
|
||||
abts_suite *test_s1ap_sm(abts_suite *suite);
|
||||
abts_suite *test_nas_message(abts_suite *suite);
|
||||
abts_suite *test_nas_sm(abts_suite *suite);
|
||||
abts_suite *test_security(abts_suite *suite);
|
||||
|
||||
#endif /* __TESTUTIL_H__ */
|
||||
|
|
Loading…
Reference in New Issue