open5gs/src/mme/context.c

171 lines
3.4 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"
#include "core_rwlock.h"
#include "core_index.h"
#include "context.h"
2017-02-14 00:09:01 +00:00
#include "s1ap_message.h"
2017-02-06 06:30:12 +00:00
2017-03-04 14:48:04 +00:00
#define S1_SCTP_PORT 36412
#define GTP_C_UDP_PORT 2123
#define GTP_U_UDP_PORT 2152
2017-02-06 06:30:12 +00:00
static mme_ctx_t self;
2017-02-13 04:19:53 +00:00
pool_declare(enb_pool, enb_ctx_t, SIZE_OF_ENB_POOL);
pool_declare(ue_pool, ue_ctx_t, SIZE_OF_UE_POOL);
pool_declare(rab_pool, rab_ctx_t, SIZE_OF_RAB_POOL);
2017-02-06 06:30:12 +00:00
static int g_mme_ctx_initialized = 0;
2017-02-13 04:19:53 +00:00
static list_t g_enb_list;
2017-03-04 16:05:03 +00:00
status_t mme_ctx_init()
2017-02-06 06:30:12 +00:00
{
d_assert(g_mme_ctx_initialized == 0, return CORE_ERROR,
"MME context already has been initialized");
2017-02-13 04:19:53 +00:00
pool_init(&enb_pool, SIZE_OF_ENB_POOL);
pool_init(&ue_pool, SIZE_OF_UE_POOL);
pool_init(&rab_pool, SIZE_OF_RAB_POOL);
list_init(&g_enb_list);
2017-02-06 06:30:12 +00:00
/* Initialize MME context */
memset(&self, 0, sizeof(mme_ctx_t));
2017-02-13 04:19:53 +00:00
self.enb_local_addr = inet_addr("127.0.0.1");
self.enb_s1_port = S1_SCTP_PORT;
self.plmn_id.mnc_len = 2;
self.plmn_id.mcc = 1; /* 001 */
self.plmn_id.mnc = 1; /* 01 */
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;
self.srvd_gummei.plmn_id[0].mnc_len = 2;
self.srvd_gummei.plmn_id[0].mcc = 1; /* 001 */
self.srvd_gummei.plmn_id[0].mnc = 1; /* 01 */
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
g_mme_ctx_initialized = 1;
return CORE_OK;
}
2017-03-04 16:05:03 +00:00
status_t mme_ctx_final()
2017-02-06 06:30:12 +00:00
{
d_assert(g_mme_ctx_initialized == 1, return CORE_ERROR,
"HyperCell context already has been finalized");
2017-03-04 16:05:03 +00:00
mme_ctx_enb_remove_all();
2017-02-13 04:19:53 +00:00
pool_final(&enb_pool);
pool_final(&ue_pool);
pool_final(&rab_pool);
2017-02-06 06:30:12 +00:00
g_mme_ctx_initialized = 0;
return CORE_OK;
}
mme_ctx_t* mme_self()
{
return &self;
}
2017-02-13 04:19:53 +00:00
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;
/* Allocate new eNB context */
pool_alloc_node(&enb_pool, &enb);
d_assert(enb, return NULL, "eNB context allocation failed");
/* Initialize eNB context */
memset(enb, 0, sizeof(enb_ctx_t));
/* Add new eNB context to list */
list_append(&g_enb_list, enb);
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");
list_remove(&g_enb_list, enb);
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;
enb = list_first(&g_enb_list);
while (enb)
{
next_enb = list_next(enb);
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;
enb = list_first(&g_enb_list);
while (enb)
{
2017-02-13 05:01:38 +00:00
if (sock == enb->s1_sock)
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_find_by_id(c_uint32_t id)
2017-02-13 04:19:53 +00:00
{
enb_ctx_t *enb = NULL;
enb = list_first(&g_enb_list);
while (enb)
{
if (id == enb->id)
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
{
return list_first(&g_enb_list);
}
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);
}