open5gs/src/mme/mme_context.c

345 lines
6.5 KiB
C
Raw Normal View History

2017-03-04 15:54:15 +00:00
#define TRACE_MODULE _mme_ctx
2017-02-06 06:30:12 +00:00
#include "core_debug.h"
#include "core_pool.h"
2017-03-23 14:15:55 +00:00
#include "gtp_path.h"
2017-03-26 06:34:34 +00:00
#include "s1ap_message.h"
2017-04-06 10:20:33 +00:00
#include "mme_context.h"
2017-02-06 06:30:12 +00:00
2017-04-04 05:00:02 +00:00
#define MAX_CELL_PER_ENB 8
#define MAX_ERAB_PER_UE 16
2017-03-05 04:03:11 +00:00
2017-04-04 05:00:02 +00:00
#define MAX_NUM_OF_SGW 8
#define MAX_NUM_OF_ERAB (MAX_NUM_OF_UE * MAX_ERAB_PER_UE)
2017-03-05 04:03:11 +00:00
2017-03-23 14:05:40 +00:00
#define S1AP_SCTP_PORT 36412
2017-03-04 14:48:04 +00:00
2017-02-06 06:30:12 +00:00
static mme_ctx_t self;
2017-04-04 05:00:02 +00:00
pool_declare(sgw_pool, sgw_ctx_t, MAX_NUM_OF_SGW);
pool_declare(enb_pool, enb_ctx_t, MAX_NUM_OF_ENB);
pool_declare(ue_pool, ue_ctx_t, MAX_NUM_OF_UE);
2017-02-13 04:19:53 +00:00
2017-03-24 09:47:05 +00:00
static int ctx_initialized = 0;
2017-02-06 06:30:12 +00:00
2017-03-26 15:48:33 +00:00
static list_t sgw_list;
2017-03-24 09:47:05 +00:00
static list_t enb_list;
2017-02-13 04:19:53 +00:00
2017-03-04 16:05:03 +00:00
status_t mme_ctx_init()
2017-02-06 06:30:12 +00:00
{
2017-03-24 09:47:05 +00:00
d_assert(ctx_initialized == 0, return CORE_ERROR,
"MME context already has been ctx_initialized");
2017-02-06 06:30:12 +00:00
2017-04-04 05:00:02 +00:00
pool_init(&sgw_pool, MAX_NUM_OF_SGW);
pool_init(&enb_pool, MAX_NUM_OF_ENB);
pool_init(&ue_pool, MAX_NUM_OF_UE);
2017-02-13 04:19:53 +00:00
2017-03-26 15:48:33 +00:00
list_init(&sgw_list);
2017-03-24 09:47:05 +00:00
list_init(&enb_list);
2017-02-13 04:19:53 +00:00
2017-02-06 06:30:12 +00:00
/* Initialize MME context */
memset(&self, 0, sizeof(mme_ctx_t));
2017-03-26 15:48:33 +00:00
self.s1ap_addr = inet_addr("127.0.0.1");
2017-03-24 09:47:05 +00:00
self.s1ap_port = S1AP_SCTP_PORT;
2017-02-13 04:19:53 +00:00
2017-03-27 04:22:42 +00:00
sgw_ctx_t *sgw = mme_ctx_sgw_add();
d_assert(sgw, return CORE_ERROR, "Can't add SGW context");
2017-03-28 07:35:57 +00:00
self.s11_addr = inet_addr("127.0.0.1");
self.s11_port = GTPV2_C_UDP_PORT;
2017-03-27 04:22:42 +00:00
sgw->gnode.addr = inet_addr("127.0.0.1");
sgw->gnode.port = GTPV2_C_UDP_PORT+1;
2017-03-24 13:52:55 +00:00
/* MCC : 001, MNC : 01 */
plmn_id_build(&self.plmn_id, 1, 1, 2);
2017-02-14 00:09:01 +00:00
self.tracking_area_code = 12345;
self.default_paging_drx = S1ap_PagingDRX_v64;
2017-02-06 10:12:10 +00:00
self.relative_capacity = 0xff;
2017-02-06 06:30:12 +00:00
2017-02-06 10:12:10 +00:00
self.srvd_gummei.num_of_plmn_id = 1;
2017-03-24 13:52:55 +00:00
/* MCC : 001, MNC : 01 */
plmn_id_build(&self.srvd_gummei.plmn_id[0], 1, 1, 2);
2017-02-06 06:30:12 +00:00
2017-02-13 05:41:20 +00:00
self.srvd_gummei.num_of_mme_gid = 1;
self.srvd_gummei.mme_gid[0] = 2;
self.srvd_gummei.num_of_mme_code = 1;
self.srvd_gummei.mme_code[0] = 1;
2017-02-06 06:30:12 +00:00
2017-03-07 05:47:17 +00:00
self.selected_enc_algorithm = NAS_SECURITY_ALGORITHMS_EEA0;
2017-03-07 00:30:12 +00:00
self.selected_int_algorithm = NAS_SECURITY_ALGORITHMS_128_EIA1;
2017-03-24 09:47:05 +00:00
ctx_initialized = 1;
2017-02-06 06:30:12 +00:00
return CORE_OK;
}
2017-03-04 16:05:03 +00:00
status_t mme_ctx_final()
2017-02-06 06:30:12 +00:00
{
2017-03-24 09:47:05 +00:00
d_assert(ctx_initialized == 1, return CORE_ERROR,
2017-02-06 06:30:12 +00:00
"HyperCell context already has been finalized");
2017-03-27 04:22:42 +00:00
mme_ctx_sgw_remove_all();
2017-03-04 16:05:03 +00:00
mme_ctx_enb_remove_all();
2017-02-13 04:19:53 +00:00
2017-03-26 15:48:33 +00:00
pool_final(&sgw_pool);
2017-02-13 04:19:53 +00:00
pool_final(&enb_pool);
pool_final(&ue_pool);
2017-03-24 09:47:05 +00:00
ctx_initialized = 0;
2017-02-06 06:30:12 +00:00
return CORE_OK;
}
mme_ctx_t* mme_self()
{
return &self;
}
2017-02-13 04:19:53 +00:00
2017-03-26 15:48:33 +00:00
sgw_ctx_t* mme_ctx_sgw_add()
{
sgw_ctx_t *sgw = NULL;
pool_alloc_node(&sgw_pool, &sgw);
d_assert(sgw, return NULL, "Null param");
memset(sgw, 0, sizeof(sgw_ctx_t));
2017-04-03 06:31:57 +00:00
list_init(&sgw->gnode.local_list);
list_init(&sgw->gnode.remote_list);
2017-03-30 12:17:05 +00:00
2017-03-26 15:48:33 +00:00
list_append(&sgw_list, sgw);
return sgw;
}
status_t mme_ctx_sgw_remove(sgw_ctx_t *sgw)
{
d_assert(sgw, return CORE_ERROR, "Null param");
list_remove(&sgw_list, sgw);
pool_free_node(&sgw_pool, sgw);
return CORE_OK;
}
status_t mme_ctx_sgw_remove_all()
{
sgw_ctx_t *sgw = NULL, *next_sgw = NULL;
sgw = mme_ctx_sgw_first();
while (sgw)
{
next_sgw = mme_ctx_sgw_next(sgw);
mme_ctx_sgw_remove(sgw);
sgw = next_sgw;
}
return CORE_OK;
}
sgw_ctx_t* mme_ctx_sgw_find_by_node(gtp_node_t *gnode)
{
sgw_ctx_t *sgw = NULL;
sgw = mme_ctx_sgw_first();
while (sgw)
{
2017-03-27 04:22:42 +00:00
if (GTP_COMPARE_NODE(&sgw->gnode, gnode))
2017-03-26 15:48:33 +00:00
break;
sgw = mme_ctx_sgw_next(sgw);
}
return sgw;
}
sgw_ctx_t* mme_ctx_sgw_first()
{
return list_first(&sgw_list);
}
sgw_ctx_t* mme_ctx_sgw_next(sgw_ctx_t *sgw)
{
return list_next(sgw);
}
2017-03-04 16:05:03 +00:00
enb_ctx_t* mme_ctx_enb_add()
2017-02-13 04:19:53 +00:00
{
enb_ctx_t *enb = NULL;
pool_alloc_node(&enb_pool, &enb);
2017-03-05 04:03:11 +00:00
d_assert(enb, return NULL, "Null param");
2017-02-13 04:19:53 +00:00
memset(enb, 0, sizeof(enb_ctx_t));
2017-03-05 04:03:11 +00:00
list_init(&enb->ue_list);
2017-03-24 09:47:05 +00:00
list_append(&enb_list, enb);
2017-02-13 04:19:53 +00:00
return enb;
}
2017-03-04 16:05:03 +00:00
status_t mme_ctx_enb_remove(enb_ctx_t *enb)
2017-02-13 04:19:53 +00:00
{
d_assert(enb, return CORE_ERROR, "Null param");
2017-03-05 04:03:11 +00:00
mme_ctx_ue_remove_all(enb);
2017-03-24 09:47:05 +00:00
list_remove(&enb_list, enb);
2017-02-13 04:19:53 +00:00
pool_free_node(&enb_pool, enb);
return CORE_OK;
}
2017-03-04 16:05:03 +00:00
status_t mme_ctx_enb_remove_all()
2017-02-13 04:19:53 +00:00
{
enb_ctx_t *enb = NULL, *next_enb = NULL;
2017-03-05 04:03:11 +00:00
enb = mme_ctx_enb_first();
2017-02-13 04:19:53 +00:00
while (enb)
{
2017-03-05 04:03:11 +00:00
next_enb = mme_ctx_enb_next(enb);
2017-02-13 04:19:53 +00:00
2017-03-04 16:05:03 +00:00
mme_ctx_enb_remove(enb);
2017-02-13 04:19:53 +00:00
enb = next_enb;
}
return CORE_OK;
}
2017-03-04 16:05:03 +00:00
enb_ctx_t* mme_ctx_enb_find_by_sock(net_sock_t *sock)
2017-02-13 04:19:53 +00:00
{
enb_ctx_t *enb = NULL;
2017-03-05 04:03:11 +00:00
enb = mme_ctx_enb_first();
2017-02-13 04:19:53 +00:00
while (enb)
{
2017-03-05 04:03:11 +00:00
if (sock == enb->s1ap_sock)
2017-02-13 04:19:53 +00:00
break;
2017-03-05 04:03:11 +00:00
enb = mme_ctx_enb_next(enb);
2017-02-13 04:19:53 +00:00
}
return enb;
}
2017-03-05 04:03:11 +00:00
enb_ctx_t* mme_ctx_enb_find_by_enb_id(c_uint32_t enb_id)
2017-02-13 04:19:53 +00:00
{
enb_ctx_t *enb = NULL;
2017-03-24 09:47:05 +00:00
enb = list_first(&enb_list);
2017-02-13 04:19:53 +00:00
while (enb)
{
2017-03-05 04:03:11 +00:00
if (enb_id == enb->enb_id)
2017-02-13 04:19:53 +00:00
break;
enb = list_next(enb);
}
return enb;
}
2017-03-04 16:05:03 +00:00
enb_ctx_t* mme_ctx_enb_first()
2017-02-13 04:19:53 +00:00
{
2017-03-24 09:47:05 +00:00
return list_first(&enb_list);
2017-02-13 04:19:53 +00:00
}
2017-03-04 16:05:03 +00:00
enb_ctx_t* mme_ctx_enb_next(enb_ctx_t *enb)
2017-02-13 04:19:53 +00:00
{
return list_next(enb);
}
2017-03-05 04:03:11 +00:00
ue_ctx_t* mme_ctx_ue_add(enb_ctx_t *enb)
{
ue_ctx_t *ue = NULL;
d_assert(enb, return NULL, "Null param");
pool_alloc_node(&ue_pool, &ue);
d_assert(ue, return NULL, "Null param");
memset(ue, 0, sizeof(ue_ctx_t));
ue->enb = enb;
2017-04-06 08:23:18 +00:00
ue->mme_ue_s1ap_id = NEXT_ID(self.mme_ue_s1ap_id, 0xffffffff);
2017-03-08 10:10:01 +00:00
2017-03-05 04:03:11 +00:00
list_append(&enb->ue_list, ue);
return ue;
}
status_t mme_ctx_ue_remove(ue_ctx_t *ue)
{
d_assert(ue, return CORE_ERROR, "Null param");
d_assert(ue->enb, return CORE_ERROR, "Null param");
2017-03-27 10:32:24 +00:00
if (FSM_STATE(&ue->emm_sm))
{
fsm_final((fsm_t*)&ue->emm_sm, 0);
fsm_clear((fsm_t*)&ue->emm_sm);
}
if (FSM_STATE(&ue->esm_sm))
{
fsm_final((fsm_t*)&ue->esm_sm, 0);
fsm_clear((fsm_t*)&ue->esm_sm);
}
2017-03-05 04:03:11 +00:00
list_remove(&ue->enb->ue_list, ue);
pool_free_node(&ue_pool, ue);
return CORE_OK;
}
status_t mme_ctx_ue_remove_all(enb_ctx_t *enb)
{
ue_ctx_t *ue = NULL, *next_ue = NULL;
ue = mme_ctx_ue_first(enb);
while (ue)
{
next_ue = mme_ctx_ue_next(ue);
mme_ctx_ue_remove(ue);
ue = next_ue;
}
return CORE_OK;
}
ue_ctx_t* mme_ctx_ue_find_by_enb_ue_s1ap_id(
enb_ctx_t *enb, c_uint32_t enb_ue_s1ap_id)
{
ue_ctx_t *ue = NULL;
ue = mme_ctx_ue_first(enb);
while (ue)
{
if (enb_ue_s1ap_id == ue->enb_ue_s1ap_id)
break;
ue = mme_ctx_ue_next(ue);
}
return ue;
}
ue_ctx_t* mme_ctx_ue_first(enb_ctx_t *enb)
{
return list_first(&enb->ue_list);
}
ue_ctx_t* mme_ctx_ue_next(ue_ctx_t *ue)
{
return list_next(ue);
}