open5gs/src/mme/mme_context.c

1204 lines
29 KiB
C
Raw Normal View History

2017-04-06 11:10:00 +00:00
#define TRACE_MODULE _mme_context
2017-03-04 15:54:15 +00:00
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-07-14 10:00:26 +00:00
#include "context.h"
2017-04-06 10:20:33 +00:00
#include "mme_context.h"
2017-04-28 03:39:14 +00:00
#include "mme_event.h"
2017-02-06 06:30:12 +00:00
2017-04-04 05:00:02 +00:00
#define MAX_CELL_PER_ENB 8
2017-03-05 04:03:11 +00:00
2017-04-04 05:00:02 +00:00
#define MAX_NUM_OF_SGW 8
2017-04-12 04:45:57 +00:00
2017-03-23 14:05:40 +00:00
#define S1AP_SCTP_PORT 36412
2017-03-04 14:48:04 +00:00
2017-04-11 14:55:21 +00:00
#define MIN_EPS_BEARER_ID 5
#define MAX_EPS_BEARER_ID 15
2017-04-06 11:10:00 +00:00
static mme_context_t self;
2017-02-06 06:30:12 +00:00
2017-04-06 11:10:00 +00:00
pool_declare(mme_sgw_pool, mme_sgw_t, MAX_NUM_OF_SGW);
2017-04-10 14:59:59 +00:00
2017-04-11 00:19:33 +00:00
index_declare(mme_enb_pool, mme_enb_t, MAX_NUM_OF_ENB);
2017-04-10 14:59:59 +00:00
index_declare(mme_ue_pool, mme_ue_t, MAX_NUM_OF_UE);
index_declare(enb_ue_pool, enb_ue_t, MAX_NUM_OF_UE);
2017-04-27 14:06:10 +00:00
index_declare(mme_sess_pool, mme_sess_t, MAX_NUM_OF_UE);
2017-04-13 10:15:53 +00:00
index_declare(mme_bearer_pool, mme_bearer_t, MAX_NUM_OF_UE_BEARER);
2017-04-12 04:45:57 +00:00
pool_declare(mme_pdn_pool, pdn_t, MAX_NUM_OF_UE_PDN);
2017-02-13 04:19:53 +00:00
2017-04-06 11:10:00 +00:00
static int context_initialized = 0;
2017-02-06 06:30:12 +00:00
2017-04-18 09:24:37 +00:00
/* FIXME : Global IP information and port.
* This should be read from configuration file or arguments
*/
static char g_mme_ip_addr[20] = "10.1.35.215";
static unsigned int g_mme_gtp_c_port = GTPV2_C_UDP_PORT;
static char g_sgw_s11_ip_addr[20] = "10.1.35.216";
static unsigned int g_sgw_s11_port = GTPV2_C_UDP_PORT;
2017-04-06 11:10:00 +00:00
status_t mme_context_init()
2017-02-06 06:30:12 +00:00
{
2017-04-18 09:24:37 +00:00
2017-04-06 11:10:00 +00:00
d_assert(context_initialized == 0, return CORE_ERROR,
"MME context already has been context_initialized");
2017-02-06 06:30:12 +00:00
2017-04-06 12:44:30 +00:00
/* Initialize MME context */
memset(&self, 0, sizeof(mme_context_t));
2017-04-06 11:10:00 +00:00
pool_init(&mme_sgw_pool, MAX_NUM_OF_SGW);
2017-04-12 01:05:23 +00:00
list_init(&self.sgw_list);
2017-04-11 00:19:33 +00:00
index_init(&mme_enb_pool, MAX_NUM_OF_ENB);
2017-04-12 01:05:23 +00:00
list_init(&self.enb_list);
2017-04-10 14:59:59 +00:00
index_init(&mme_ue_pool, MAX_NUM_OF_UE);
index_init(&enb_ue_pool, MAX_NUM_OF_UE);
2017-04-27 14:06:10 +00:00
index_init(&mme_sess_pool, MAX_NUM_OF_UE);
2017-04-13 10:15:53 +00:00
index_init(&mme_bearer_pool, MAX_NUM_OF_UE_BEARER);
2017-04-12 04:45:57 +00:00
pool_init(&mme_pdn_pool, MAX_NUM_OF_UE_PDN);
2017-02-13 04:19:53 +00:00
2017-04-18 09:24:37 +00:00
self.mme_addr = inet_addr(g_mme_ip_addr);
2017-04-12 12:20:00 +00:00
2017-04-06 12:44:30 +00:00
self.mme_ue_s1ap_id_hash = hash_make();
self.imsi_ue_hash = hash_make();
self.guti_ue_hash = hash_make();
2017-02-06 06:30:12 +00:00
2017-04-12 12:20:00 +00:00
self.s1ap_addr = self.mme_addr;
2017-03-24 09:47:05 +00:00
self.s1ap_port = S1AP_SCTP_PORT;
2017-02-13 04:19:53 +00:00
2017-04-06 11:10:00 +00:00
mme_sgw_t *sgw = mme_sgw_add();
2017-03-27 04:22:42 +00:00
d_assert(sgw, return CORE_ERROR, "Can't add SGW context");
2017-04-12 12:20:00 +00:00
self.s11_addr = self.mme_addr;
2017-04-18 09:24:37 +00:00
self.s11_port = g_mme_gtp_c_port;
2017-03-28 07:35:57 +00:00
2017-04-18 09:24:37 +00:00
/* FIXME : It should be removed : Peer SGW ?*/
sgw->gnode.addr = inet_addr(g_sgw_s11_ip_addr);
sgw->gnode.port = g_sgw_s11_port;
2017-03-27 04:22:42 +00:00
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-04-06 11:10:00 +00:00
context_initialized = 1;
2017-02-06 06:30:12 +00:00
return CORE_OK;
}
2017-07-14 10:00:26 +00:00
status_t mme_context_parse_config()
{
config_t *config = &context_self()->config;
char *json = config->json;
jsmntok_t *token = config->token;
typedef enum {
START, ROOT,
MME_START, MME_ROOT,
SGW_START, SGW_ROOT,
SKIP, STOP
} parse_state;
parse_state state = START;
parse_state stack = STOP;
size_t root_tokens = 0;
size_t mme_tokens = 0;
size_t sgw_tokens = 0;
size_t skip_tokens = 0;
int i, j, m, n, p;
int arr, size;
for (i = 0, j = 1; j > 0; i++, j--)
{
jsmntok_t *t = &token[i];
j += t->size;
switch (state)
{
case START:
{
state = ROOT;
root_tokens = t->size;
break;
}
case ROOT:
{
printf("root key = %s\n", jsmntok_to_string(json, t));
if (jsmntok_equal(json, t, "MME") == 0)
{
state = MME_START;
}
else if (jsmntok_equal(json, t, "SGW") == 0)
{
state = SGW_START;
}
else
{
state = SKIP;
stack = ROOT;
skip_tokens = t->size;
}
root_tokens--;
if (root_tokens == 0) state = STOP;
break;
}
case MME_START:
{
state = MME_ROOT;
mme_tokens = t->size;
break;
}
case MME_ROOT:
{
if (jsmntok_equal(json, t, "DEFAULT_PAGING_DRX") == 0)
{
printf("paging_drx : %s\n", jsmntok_to_string(json, t+1));
}
else if (jsmntok_equal(json, t, "RELATIVE_CAPACITY") == 0)
{
printf("relative : %s\n", jsmntok_to_string(json, t+1));
}
else if (jsmntok_equal(json, t, "NETWORK") == 0)
{
m = 1;
size = 1;
if ((t+1)->type == JSMN_ARRAY)
{
m = 2;
}
for (arr = 0; arr < size; arr++)
{
for (n = 1; n > 0; m++, n--)
{
n += (t+m)->size;
if (jsmntok_equal(json, t+m, "S1AP_ADDR") == 0)
{
printf("s1ap_addr : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "S1AP_PORT") == 0)
{
printf("s1ap_port : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "S11_ADDR") == 0)
{
printf("s11_addr : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "S11_PORT") == 0)
{
printf("s11_port : %s\n", jsmntok_to_string(json, t+m+1));
}
}
}
}
else if (jsmntok_equal(json, t, "GUMMEI") == 0)
{
m = 1;
size = 1;
if ((t+1)->type == JSMN_ARRAY)
{
m = 2;
size = (t+1)->size;
}
for (arr = 0; arr < size; arr++)
{
for (n = 1; n > 0; m++, n--)
{
n += (t+m)->size;
if (jsmntok_equal(json, t+m, "MCC") == 0)
{
printf("mcc : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "MNC") == 0)
{
printf("mnc : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "MME_GID") == 0)
{
printf("gid : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "MME_CODE") == 0)
{
printf("code : %s\n", jsmntok_to_string(json, t+m+1));
}
}
}
}
else if (jsmntok_equal(json, t, "TAI") == 0)
{
m = 1;
size = 1;
if ((t+1)->type == JSMN_ARRAY)
{
m = 2;
size = (t+1)->size;
}
for (arr = 0; arr < size; arr++)
{
for (n = 1; n > 0; m++, n--)
{
n += (t+m)->size;
if (jsmntok_equal(json, t+m, "MCC") == 0)
{
printf("mcc : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "MNC") == 0)
{
printf("mnc : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "TAC") == 0)
{
printf("tac : %s\n", jsmntok_to_string(json, t+m+1));
}
}
}
}
else if (jsmntok_equal(json, t, "SECURITY") == 0)
{
for (m = 1, n = 1; n > 0; m++, n--)
{
n += (t+m)->size;
if (jsmntok_equal(json, t+m, "INTEGRITY_ORDER") == 0)
{
p = 1;
size = 1;
if ((t+m+1)->type == JSMN_ARRAY)
{
p = 2;
size = (t+m+1)->size;
}
for (arr = 0; arr < size; arr++)
{
printf("%s\n",
jsmntok_to_string(json, t+m+p));
p++;
}
}
else if (jsmntok_equal(json, t+m, "CIPHERING_ORDER") == 0)
{
p = 1;
size = 1;
if ((t+m+1)->type == JSMN_ARRAY)
{
p = 2;
size = (t+m+1)->size;
}
for (arr = 0; arr < size; arr++)
{
printf("%s\n",
jsmntok_to_string(json, t+m+p));
p++;
}
}
}
}
state = SKIP;
stack = MME_ROOT;
skip_tokens = t->size;
mme_tokens--;
if (mme_tokens == 0) stack = ROOT;
break;
}
case SGW_START:
{
state = SGW_ROOT;
sgw_tokens = t->size;
break;
}
case SGW_ROOT:
{
printf("sgw key = %s\n", jsmntok_to_string(json, t));
if (jsmntok_equal(json, t, "NETWORK") == 0)
{
m = 1;
size = 1;
if ((t+1)->type == JSMN_ARRAY)
{
m = 2;
size = (t+1)->size;
}
for (arr = 0; arr < size; arr++)
{
for (n = 1; n > 0; m++, n--)
{
n += (t+m)->size;
if (jsmntok_equal(json, t+m, "S11_ADDR") == 0)
{
printf("s11_addr : %s\n", jsmntok_to_string(json, t+m+1));
}
else if (jsmntok_equal(json, t+m, "S11_PORT") == 0)
{
printf("s11_port : %s\n", jsmntok_to_string(json, t+m+1));
}
}
}
}
state = SKIP;
stack = SGW_ROOT;
skip_tokens = t->size;
sgw_tokens--;
if (sgw_tokens == 0) stack = ROOT;
break;
}
case SKIP:
{
skip_tokens += t->size;
skip_tokens--;
if (skip_tokens == 0) state = stack;
break;
}
case STOP:
{
break;
}
default:
{
d_error("Failed to parse configuration in the state(%u)",
state);
break;
}
}
}
return CORE_OK;
}
2017-04-06 11:10:00 +00:00
status_t mme_context_final()
2017-02-06 06:30:12 +00:00
{
2017-04-06 11:10:00 +00:00
d_assert(context_initialized == 1, return CORE_ERROR,
2017-07-13 01:31:07 +00:00
"MME context already has been finalized");
2017-02-06 06:30:12 +00:00
2017-04-06 11:10:00 +00:00
mme_sgw_remove_all();
mme_enb_remove_all();
2017-02-13 04:19:53 +00:00
2017-04-06 12:44:30 +00:00
d_assert(self.mme_ue_s1ap_id_hash, , "Null param");
hash_destroy(self.mme_ue_s1ap_id_hash);
d_assert(self.imsi_ue_hash, , "Null param");
hash_destroy(self.imsi_ue_hash);
d_assert(self.guti_ue_hash, , "Null param");
hash_destroy(self.guti_ue_hash);
2017-04-12 04:45:57 +00:00
pool_final(&mme_pdn_pool);
2017-04-13 10:15:53 +00:00
index_final(&mme_bearer_pool);
2017-04-27 14:06:10 +00:00
index_final(&mme_sess_pool);
2017-04-11 00:19:33 +00:00
index_final(&mme_ue_pool);
index_final(&enb_ue_pool);
2017-04-10 14:59:59 +00:00
2017-04-12 04:45:57 +00:00
index_final(&mme_enb_pool);
2017-04-10 14:59:59 +00:00
pool_final(&mme_sgw_pool);
2017-02-13 04:19:53 +00:00
2017-04-06 11:10:00 +00:00
context_initialized = 0;
2017-02-06 06:30:12 +00:00
return CORE_OK;
}
2017-04-06 11:10:00 +00:00
mme_context_t* mme_self()
2017-02-06 06:30:12 +00:00
{
return &self;
}
2017-02-13 04:19:53 +00:00
2017-04-06 11:10:00 +00:00
mme_sgw_t* mme_sgw_add()
2017-03-26 15:48:33 +00:00
{
2017-04-06 11:10:00 +00:00
mme_sgw_t *sgw = NULL;
2017-03-26 15:48:33 +00:00
2017-04-06 11:10:00 +00:00
pool_alloc_node(&mme_sgw_pool, &sgw);
2017-03-26 15:48:33 +00:00
d_assert(sgw, return NULL, "Null param");
2017-04-06 11:10:00 +00:00
memset(sgw, 0, sizeof(mme_sgw_t));
2017-03-26 15:48:33 +00:00
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-04-06 11:58:13 +00:00
list_append(&self.sgw_list, sgw);
2017-03-26 15:48:33 +00:00
return sgw;
}
2017-04-06 11:10:00 +00:00
status_t mme_sgw_remove(mme_sgw_t *sgw)
2017-03-26 15:48:33 +00:00
{
d_assert(sgw, return CORE_ERROR, "Null param");
2017-04-11 13:44:57 +00:00
gtp_xact_delete_all(&sgw->gnode);
2017-04-06 11:58:13 +00:00
list_remove(&self.sgw_list, sgw);
2017-04-06 11:10:00 +00:00
pool_free_node(&mme_sgw_pool, sgw);
2017-03-26 15:48:33 +00:00
return CORE_OK;
}
2017-04-06 11:10:00 +00:00
status_t mme_sgw_remove_all()
2017-03-26 15:48:33 +00:00
{
2017-04-06 11:10:00 +00:00
mme_sgw_t *sgw = NULL, *next_sgw = NULL;
2017-03-26 15:48:33 +00:00
2017-04-06 11:10:00 +00:00
sgw = mme_sgw_first();
2017-03-26 15:48:33 +00:00
while (sgw)
{
2017-04-06 11:10:00 +00:00
next_sgw = mme_sgw_next(sgw);
2017-03-26 15:48:33 +00:00
2017-04-06 11:10:00 +00:00
mme_sgw_remove(sgw);
2017-03-26 15:48:33 +00:00
sgw = next_sgw;
}
return CORE_OK;
}
2017-04-06 11:10:00 +00:00
mme_sgw_t* mme_sgw_find_by_node(gtp_node_t *gnode)
2017-03-26 15:48:33 +00:00
{
2017-04-06 11:10:00 +00:00
mme_sgw_t *sgw = NULL;
2017-03-26 15:48:33 +00:00
2017-04-06 11:10:00 +00:00
sgw = mme_sgw_first();
2017-03-26 15:48:33 +00:00
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;
2017-04-06 11:10:00 +00:00
sgw = mme_sgw_next(sgw);
2017-03-26 15:48:33 +00:00
}
return sgw;
}
2017-04-06 11:10:00 +00:00
mme_sgw_t* mme_sgw_first()
2017-03-26 15:48:33 +00:00
{
2017-04-06 11:58:13 +00:00
return list_first(&self.sgw_list);
2017-03-26 15:48:33 +00:00
}
2017-04-06 11:10:00 +00:00
mme_sgw_t* mme_sgw_next(mme_sgw_t *sgw)
2017-03-26 15:48:33 +00:00
{
return list_next(sgw);
}
2017-04-08 01:45:48 +00:00
mme_enb_t* mme_enb_add(net_sock_t *s1ap_sock)
2017-02-13 04:19:53 +00:00
{
2017-04-06 11:10:00 +00:00
mme_enb_t *enb = NULL;
2017-02-13 04:19:53 +00:00
2017-04-11 00:19:33 +00:00
index_alloc(&mme_enb_pool, &enb);
2017-03-05 04:03:11 +00:00
d_assert(enb, return NULL, "Null param");
2017-04-11 00:19:33 +00:00
/* IMPORTANT!
* eNB Index is saved in net_sock_t structure */
s1ap_sock->app_index = enb->index;
2017-02-13 04:19:53 +00:00
2017-04-08 01:45:48 +00:00
enb->s1ap_sock = s1ap_sock;
list_init(&enb->enb_ue_list);
2017-04-08 02:38:09 +00:00
list_append(&self.enb_list, enb);
2017-04-08 01:45:48 +00:00
2017-04-11 00:32:34 +00:00
fsm_create(&enb->sm, s1ap_state_initial, s1ap_state_final);
fsm_init(&enb->sm, 0);
2017-02-13 04:19:53 +00:00
return enb;
}
2017-04-06 11:10:00 +00:00
status_t mme_enb_remove(mme_enb_t *enb)
2017-02-13 04:19:53 +00:00
{
d_assert(enb, return CORE_ERROR, "Null param");
2017-04-11 00:32:34 +00:00
fsm_final(&enb->sm, 0);
fsm_clear(&enb->sm);
2017-04-08 01:18:48 +00:00
enb_ue_remove_in_enb(enb);
2017-04-08 02:38:09 +00:00
2017-04-08 01:18:48 +00:00
net_unregister_sock(enb->s1ap_sock);
net_close(enb->s1ap_sock);
2017-04-06 11:58:13 +00:00
list_remove(&self.enb_list, enb);
2017-04-11 00:19:33 +00:00
index_free(&mme_enb_pool, enb);
2017-02-13 04:19:53 +00:00
return CORE_OK;
}
2017-04-06 11:10:00 +00:00
status_t mme_enb_remove_all()
2017-02-13 04:19:53 +00:00
{
2017-04-06 11:10:00 +00:00
mme_enb_t *enb = NULL, *next_enb = NULL;
2017-02-13 04:19:53 +00:00
2017-04-06 11:10:00 +00:00
enb = mme_enb_first();
2017-02-13 04:19:53 +00:00
while (enb)
{
2017-04-06 11:10:00 +00:00
next_enb = mme_enb_next(enb);
2017-02-13 04:19:53 +00:00
2017-04-06 11:10:00 +00:00
mme_enb_remove(enb);
2017-02-13 04:19:53 +00:00
enb = next_enb;
}
return CORE_OK;
}
2017-04-11 00:19:33 +00:00
mme_enb_t* mme_enb_find(index_t index)
{
d_assert(index, return NULL, "Invalid Index");
return index_find(&mme_enb_pool, index);
}
2017-04-06 11:10:00 +00:00
mme_enb_t* mme_enb_find_by_sock(net_sock_t *sock)
2017-02-13 04:19:53 +00:00
{
2017-04-06 11:10:00 +00:00
mme_enb_t *enb = NULL;
2017-02-13 04:19:53 +00:00
2017-04-06 11:10:00 +00:00
enb = mme_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-04-06 11:10:00 +00:00
enb = mme_enb_next(enb);
2017-02-13 04:19:53 +00:00
}
return enb;
}
2017-04-06 11:10:00 +00:00
mme_enb_t* mme_enb_find_by_enb_id(c_uint32_t enb_id)
2017-02-13 04:19:53 +00:00
{
2017-04-06 11:10:00 +00:00
mme_enb_t *enb = NULL;
2017-02-13 04:19:53 +00:00
2017-04-06 11:58:13 +00:00
enb = list_first(&self.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-04-06 11:10:00 +00:00
mme_enb_t* mme_enb_first()
2017-02-13 04:19:53 +00:00
{
2017-04-06 11:58:13 +00:00
return list_first(&self.enb_list);
2017-02-13 04:19:53 +00:00
}
2017-04-06 11:10:00 +00:00
mme_enb_t* mme_enb_next(mme_enb_t *enb)
2017-02-13 04:19:53 +00:00
{
return list_next(enb);
}
2017-03-05 04:03:11 +00:00
/** enb_ue_context handling function */
enb_ue_t* enb_ue_add(mme_enb_t *enb)
2017-03-05 04:03:11 +00:00
{
enb_ue_t *enb_ue = NULL;
2017-03-05 04:03:11 +00:00
2017-04-06 12:44:30 +00:00
d_assert(self.mme_ue_s1ap_id_hash, return NULL, "Null param");
2017-03-05 04:03:11 +00:00
d_assert(enb, return NULL, "Null param");
index_alloc(&enb_ue_pool, &enb_ue);
d_assert(enb_ue, return NULL, "Null param");
2017-03-05 04:03:11 +00:00
enb_ue->mme_ue_s1ap_id = NEXT_ID(self.mme_ue_s1ap_id, 1, 0xffffffff);
hash_set(self.mme_ue_s1ap_id_hash, &enb_ue->mme_ue_s1ap_id,
sizeof(enb_ue->mme_ue_s1ap_id), enb_ue);
list_append(&enb->enb_ue_list, enb_ue);
2017-04-08 02:38:09 +00:00
enb_ue->enb = enb;
2017-04-12 04:45:57 +00:00
return enb_ue;
2017-03-05 04:03:11 +00:00
}
unsigned int enb_ue_count()
{
d_assert(self.mme_ue_s1ap_id_hash, return 0, "Null param");
return hash_count(self.mme_ue_s1ap_id_hash);
}
status_t enb_ue_remove(enb_ue_t *enb_ue)
2017-03-05 04:03:11 +00:00
{
2017-04-06 12:44:30 +00:00
d_assert(self.mme_ue_s1ap_id_hash, return CORE_ERROR, "Null param");
d_assert(enb_ue, return CORE_ERROR, "Null param");
d_assert(enb_ue->enb, return CORE_ERROR, "Null param");
2017-03-05 04:03:11 +00:00
list_remove(&enb_ue->enb->enb_ue_list, enb_ue);
hash_set(self.mme_ue_s1ap_id_hash, &enb_ue->mme_ue_s1ap_id,
sizeof(enb_ue->mme_ue_s1ap_id), NULL);
2017-04-06 12:44:30 +00:00
index_free(&enb_ue_pool, enb_ue);
if (enb_ue->mme_ue)
enb_ue->mme_ue->enb_ue = NULL;
return CORE_OK;
}
status_t enb_ue_remove_in_enb(mme_enb_t *enb)
{
enb_ue_t *enb_ue = NULL, *next_enb_ue = NULL;
enb_ue = enb_ue_first_in_enb(enb);
while (enb_ue)
{
next_enb_ue = enb_ue_next_in_enb(enb_ue);
enb_ue_remove(enb_ue);
enb_ue = next_enb_ue;
}
return CORE_OK;
}
enb_ue_t* enb_ue_find(index_t index)
{
d_assert(index, return NULL, "Invalid Index");
return index_find(&enb_ue_pool, index);
}
enb_ue_t* enb_ue_find_by_enb_ue_s1ap_id(
mme_enb_t *enb, c_uint32_t enb_ue_s1ap_id)
{
enb_ue_t *enb_ue = NULL;
enb_ue = enb_ue_first_in_enb(enb);
while (enb_ue)
{
if (enb_ue_s1ap_id == enb_ue->enb_ue_s1ap_id)
break;
enb_ue = enb_ue_next_in_enb(enb_ue);
}
return enb_ue;
}
enb_ue_t* enb_ue_find_by_mme_ue_s1ap_id(c_uint32_t mme_ue_s1ap_id)
{
d_assert(self.mme_ue_s1ap_id_hash, return NULL, "Null param");
return hash_get(self.mme_ue_s1ap_id_hash,
&mme_ue_s1ap_id, sizeof(mme_ue_s1ap_id));
}
enb_ue_t* enb_ue_first_in_enb(mme_enb_t *enb)
{
return list_first(&enb->enb_ue_list);
}
enb_ue_t* enb_ue_next_in_enb(enb_ue_t *enb_ue)
{
return list_next(enb_ue);
}
mme_ue_t* mme_ue_add(enb_ue_t *enb_ue)
{
mme_ue_t *mme_ue = NULL;
d_assert(enb_ue, return NULL, "Null param");
index_alloc(&mme_ue_pool, &mme_ue);
d_assert(mme_ue, return NULL, "Null param");
mme_ue->ebi = MIN_EPS_BEARER_ID - 1; /* Setup EBI Generator */
list_init(&mme_ue->pdn_list);
list_init(&mme_ue->sess_list);
mme_ue->enb_ue = enb_ue;
enb_ue->mme_ue = mme_ue;
2017-04-28 03:39:14 +00:00
#define MME_UE_T3_DURATION 3000 /* 3 seconds */
mme_ue->tm_t3 = event_timer(&self.tm_service, MME_EVT_EMM_UE_T3,
MME_UE_T3_DURATION, mme_ue->index);
2017-04-28 03:39:14 +00:00
#if 1 /* example code : please remove if you know the usage */
tm_start(mme_ue->tm_t3);
tm_stop(mme_ue->tm_t3);
2017-04-28 03:39:14 +00:00
#endif
fsm_create(&mme_ue->sm, emm_state_initial, emm_state_final);
fsm_init(&mme_ue->sm, 0);
return mme_ue;
}
status_t mme_ue_remove(mme_ue_t *mme_ue)
{
d_assert(mme_ue, return CORE_ERROR, "Null param");
2017-03-05 04:03:11 +00:00
tm_delete(mme_ue->tm_t3);
fsm_final(&mme_ue->sm, 0);
fsm_clear(&mme_ue->sm);
mme_sess_remove_all(mme_ue);
mme_pdn_remove_all(mme_ue);
index_free(&mme_ue_pool, mme_ue);
2017-03-05 04:03:11 +00:00
return CORE_OK;
}
2017-04-06 12:44:30 +00:00
status_t mme_ue_remove_all()
{
hash_index_t *hi = NULL;
mme_ue_t *mme_ue = NULL;
2017-04-06 12:44:30 +00:00
for (hi = mme_ue_first(); hi; hi = mme_ue_next(hi))
{
mme_ue = mme_ue_this(hi);
mme_ue_remove(mme_ue);
2017-04-06 12:44:30 +00:00
}
return CORE_OK;
}
2017-04-10 14:59:59 +00:00
mme_ue_t* mme_ue_find(index_t index)
{
d_assert(index, return NULL, "Invalid Index");
return index_find(&mme_ue_pool, index);
}
mme_ue_t* mme_ue_find_by_imsi(c_uint8_t *imsi, int imsi_len)
{
d_assert(imsi && imsi_len, return NULL,"Invalid Param");
return (mme_ue_t *)hash_get(self.imsi_ue_hash, imsi, imsi_len);
}
mme_ue_t* mme_ue_find_by_guti(guti_t *guti)
{
d_assert(guti, return NULL,"Invalid Param");
return (mme_ue_t *)hash_get(self.guti_ue_hash, guti, sizeof(guti_t));
}
2017-04-06 12:44:30 +00:00
hash_index_t *mme_ue_first()
{
d_assert(self.imsi_ue_hash, return NULL, "Null param");
return hash_first(self.imsi_ue_hash);
2017-04-06 12:44:30 +00:00
}
hash_index_t *mme_ue_next(hash_index_t *hi)
{
return hash_next(hi);
}
mme_ue_t *mme_ue_this(hash_index_t *hi)
{
d_assert(hi, return NULL, "Null param");
return hash_this_val(hi);
}
#if 0
2017-04-06 12:44:30 +00:00
unsigned int mme_ue_count()
{
d_assert(self.mme_ue_s1ap_id_hash, return 0, "Null param");
return hash_count(self.mme_ue_s1ap_id_hash);
}
status_t mme_ue_remove_in_enb(mme_enb_t *enb)
2017-03-05 04:03:11 +00:00
{
mme_ue_t *mme_ue = NULL, *next_mme_ue = NULL;
2017-03-05 04:03:11 +00:00
mme_ue = mme_ue_first_in_enb(enb);
while (mme_ue)
2017-03-05 04:03:11 +00:00
{
next_mme_ue = mme_ue_next_in_enb(mme_ue);
2017-03-05 04:03:11 +00:00
mme_ue_remove(mme_ue);
2017-03-05 04:03:11 +00:00
mme_ue = next_mme_ue;
2017-03-05 04:03:11 +00:00
}
return CORE_OK;
}
2017-04-06 11:10:00 +00:00
mme_ue_t* mme_ue_find_by_enb_ue_s1ap_id(
mme_enb_t *enb, c_uint32_t enb_ue_s1ap_id)
2017-03-05 04:03:11 +00:00
{
mme_ue_t *mme_ue = NULL;
2017-03-05 04:03:11 +00:00
mme_ue = mme_ue_first_in_enb(enb);
while (mme_ue)
2017-03-05 04:03:11 +00:00
{
if (enb_ue_s1ap_id == mme_ue->enb_ue_s1ap_id)
2017-03-05 04:03:11 +00:00
break;
mme_ue = mme_ue_next_in_enb(mme_ue);
2017-03-05 04:03:11 +00:00
}
return mme_ue;
2017-03-05 04:03:11 +00:00
}
2017-04-06 12:44:30 +00:00
mme_ue_t* mme_ue_first_in_enb(mme_enb_t *enb)
2017-03-05 04:03:11 +00:00
{
return list_first(&enb->enb_ue_list);
2017-03-05 04:03:11 +00:00
}
mme_ue_t* mme_ue_next_in_enb(mme_ue_t *mme_ue)
2017-03-05 04:03:11 +00:00
{
return list_next(mme_ue);
2017-03-05 04:03:11 +00:00
}
#endif
2017-03-05 04:03:11 +00:00
mme_bearer_t *mme_sess_add(mme_ue_t *mme_ue, c_uint8_t pti)
2017-04-08 01:18:48 +00:00
{
2017-04-27 14:06:10 +00:00
mme_sess_t *sess = NULL;
2017-04-13 10:15:53 +00:00
mme_bearer_t *bearer = NULL;
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
index_alloc(&mme_sess_pool, &sess);
d_assert(sess, return NULL, "Null param");
sess->mme_s11_teid = sess->index;
sess->mme_s11_addr = mme_self()->s11_addr;
list_init(&sess->bearer_list);
list_append(&mme_ue->sess_list, sess);
2017-04-27 14:06:10 +00:00
sess->mme_ue = mme_ue;
2017-04-27 14:06:10 +00:00
bearer = mme_bearer_add(sess, pti);
d_assert(bearer, mme_sess_remove(sess); return NULL,
"Can't add default bearer context");
return bearer;
2017-04-27 14:06:10 +00:00
}
status_t mme_sess_remove(mme_sess_t *sess)
{
d_assert(sess, return CORE_ERROR, "Null param");
d_assert(sess->mme_ue, return CORE_ERROR, "Null param");
2017-04-27 14:06:10 +00:00
mme_bearer_remove_all(sess);
list_remove(&sess->mme_ue->sess_list, sess);
2017-04-27 14:06:10 +00:00
index_free(&mme_sess_pool, sess);
return CORE_OK;
}
status_t mme_sess_remove_all(mme_ue_t *mme_ue)
2017-04-27 14:06:10 +00:00
{
mme_sess_t *sess = NULL, *next_sess = NULL;
sess = mme_sess_first(mme_ue);
2017-04-27 14:06:10 +00:00
while (sess)
{
next_sess = mme_sess_next(sess);
mme_sess_remove(sess);
sess = next_sess;
}
return CORE_OK;
}
mme_sess_t* mme_sess_find(index_t index)
{
d_assert(index, return NULL, "Invalid Index");
return index_find(&mme_sess_pool, index);
}
mme_sess_t* mme_sess_find_by_teid(c_uint32_t teid)
{
return mme_sess_find(teid);
}
mme_sess_t* mme_sess_find_by_ebi(mme_ue_t *mme_ue, c_uint8_t ebi)
2017-04-27 14:06:10 +00:00
{
mme_sess_t *sess = NULL;
mme_bearer_t *bearer = NULL;
sess = mme_sess_first(mme_ue);
2017-04-27 14:06:10 +00:00
while (sess)
{
bearer = mme_bearer_first(sess);
while (bearer)
{
if (ebi == bearer->ebi)
return sess;
bearer = mme_bearer_next(bearer);
}
sess = mme_sess_next(sess);
}
return NULL;
}
mme_sess_t* mme_sess_first(mme_ue_t *mme_ue)
2017-04-27 23:28:04 +00:00
{
return list_first(&mme_ue->sess_list);
2017-04-27 23:28:04 +00:00
}
mme_sess_t* mme_sess_next(mme_sess_t *sess)
{
return list_next(sess);
}
2017-04-27 14:06:10 +00:00
mme_bearer_t* mme_bearer_add(mme_sess_t *sess, c_uint8_t pti)
2017-04-08 01:18:48 +00:00
{
2017-04-13 10:15:53 +00:00
mme_bearer_t *bearer = NULL;
mme_ue_t *mme_ue = NULL;
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
d_assert(sess, return NULL, "Null param");
mme_ue = sess->mme_ue;
d_assert(mme_ue, return NULL, "Null param");
2017-04-08 01:18:48 +00:00
2017-04-13 10:15:53 +00:00
index_alloc(&mme_bearer_pool, &bearer);
d_assert(bearer, return NULL, "Null param");
2017-04-08 01:18:48 +00:00
2017-04-13 10:15:53 +00:00
bearer->pti = pti;
bearer->ebi = NEXT_ID(mme_ue->ebi, MIN_EPS_BEARER_ID, MAX_EPS_BEARER_ID);
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
list_append(&sess->bearer_list, bearer);
2017-04-08 01:18:48 +00:00
bearer->mme_ue = mme_ue;
2017-04-27 14:06:10 +00:00
bearer->sess = sess;
2017-04-13 10:15:53 +00:00
fsm_create(&bearer->sm, esm_state_initial, esm_state_final);
fsm_init(&bearer->sm, 0);
2017-04-08 02:38:09 +00:00
2017-04-13 10:15:53 +00:00
return bearer;
2017-04-08 01:18:48 +00:00
}
2017-04-13 10:15:53 +00:00
status_t mme_bearer_remove(mme_bearer_t *bearer)
2017-04-08 01:18:48 +00:00
{
2017-04-13 10:15:53 +00:00
d_assert(bearer, return CORE_ERROR, "Null param");
2017-04-27 14:06:10 +00:00
d_assert(bearer->sess, return CORE_ERROR, "Null param");
2017-04-08 01:18:48 +00:00
2017-04-13 10:15:53 +00:00
fsm_final(&bearer->sm, 0);
fsm_clear(&bearer->sm);
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
list_remove(&bearer->sess->bearer_list, bearer);
2017-04-13 10:15:53 +00:00
index_free(&mme_bearer_pool, bearer);
2017-04-08 01:18:48 +00:00
return CORE_OK;
}
2017-04-27 14:06:10 +00:00
status_t mme_bearer_remove_all(mme_sess_t *sess)
2017-04-08 01:18:48 +00:00
{
2017-04-13 10:15:53 +00:00
mme_bearer_t *bearer = NULL, *next_bearer = NULL;
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
d_assert(sess, return CORE_ERROR, "Null param");
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
bearer = mme_bearer_first(sess);
2017-04-13 10:15:53 +00:00
while (bearer)
2017-04-08 01:18:48 +00:00
{
2017-04-13 10:15:53 +00:00
next_bearer = mme_bearer_next(bearer);
2017-04-08 01:18:48 +00:00
2017-04-13 10:15:53 +00:00
mme_bearer_remove(bearer);
2017-04-08 01:18:48 +00:00
2017-04-13 10:15:53 +00:00
bearer = next_bearer;
2017-04-08 01:18:48 +00:00
}
return CORE_OK;
}
2017-04-13 10:15:53 +00:00
mme_bearer_t* mme_bearer_find(index_t index)
2017-04-10 14:59:59 +00:00
{
d_assert(index, return NULL, "Invalid Index");
2017-04-13 10:15:53 +00:00
return index_find(&mme_bearer_pool, index);
2017-04-10 14:59:59 +00:00
}
mme_bearer_t* mme_bearer_find_by_ue_pti(mme_ue_t *mme_ue, c_uint8_t pti)
2017-04-08 01:18:48 +00:00
{
2017-04-27 14:06:10 +00:00
mme_sess_t *sess = NULL;
2017-04-13 10:15:53 +00:00
mme_bearer_t *bearer = NULL;
2017-04-08 01:18:48 +00:00
d_assert(mme_ue, return NULL, "Null param");
2017-04-27 14:06:10 +00:00
sess = mme_sess_first(mme_ue);
2017-04-27 14:06:10 +00:00
while (sess)
2017-04-08 01:18:48 +00:00
{
2017-04-27 14:06:10 +00:00
bearer = mme_bearer_first(sess);
while (bearer)
{
if (pti == bearer->pti)
return bearer;
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
bearer = mme_bearer_next(bearer);
}
sess = mme_sess_next(sess);
2017-04-08 01:18:48 +00:00
}
2017-04-27 14:06:10 +00:00
return NULL;
2017-04-08 01:18:48 +00:00
}
mme_bearer_t* mme_bearer_find_by_ue_ebi(mme_ue_t *mme_ue, c_uint8_t ebi)
2017-04-12 12:44:18 +00:00
{
2017-04-27 14:06:10 +00:00
mme_sess_t *sess = NULL;
2017-04-13 10:15:53 +00:00
mme_bearer_t *bearer = NULL;
2017-04-12 12:44:18 +00:00
d_assert(mme_ue, return NULL, "Null param");
2017-04-27 14:06:10 +00:00
sess = mme_sess_first(mme_ue);
2017-04-27 14:06:10 +00:00
while (sess)
{
bearer = mme_bearer_first(sess);
while (bearer)
{
if (ebi == bearer->ebi)
return bearer;
bearer = mme_bearer_next(bearer);
}
sess = mme_sess_next(sess);
}
return NULL;
}
mme_bearer_t* mme_bearer_find_by_sess_ebi(mme_sess_t *sess, c_uint8_t ebi)
{
mme_bearer_t *bearer = NULL;
d_assert(sess, return NULL, "Null param");
bearer = mme_bearer_first(sess);
2017-04-13 10:15:53 +00:00
while (bearer)
2017-04-12 12:44:18 +00:00
{
2017-04-13 10:15:53 +00:00
if (ebi == bearer->ebi)
2017-04-27 14:06:10 +00:00
return bearer;
2017-04-12 12:44:18 +00:00
2017-04-13 10:15:53 +00:00
bearer = mme_bearer_next(bearer);
2017-04-12 12:44:18 +00:00
}
2017-04-27 14:06:10 +00:00
return NULL;
2017-04-12 12:44:18 +00:00
}
2017-04-27 23:28:04 +00:00
mme_bearer_t* mme_default_bearer_in_sess(mme_sess_t *sess)
2017-04-08 01:18:48 +00:00
{
2017-04-27 23:28:04 +00:00
return mme_bearer_first(sess);
}
2017-04-27 14:06:10 +00:00
mme_bearer_t* mme_bearer_first(mme_sess_t *sess)
2017-04-08 01:18:48 +00:00
{
2017-04-27 14:06:10 +00:00
d_assert(sess, return NULL, "Null param");
2017-04-08 01:18:48 +00:00
2017-04-27 14:06:10 +00:00
return list_first(&sess->bearer_list);
2017-04-08 01:18:48 +00:00
}
2017-04-13 10:15:53 +00:00
mme_bearer_t* mme_bearer_next(mme_bearer_t *bearer)
2017-04-08 01:18:48 +00:00
{
2017-04-13 10:15:53 +00:00
return list_next(bearer);
2017-04-08 01:18:48 +00:00
}
2017-04-12 04:45:57 +00:00
pdn_t* mme_pdn_add(mme_ue_t *mme_ue, c_int8_t *apn)
2017-04-12 04:45:57 +00:00
{
pdn_t *pdn = NULL;
d_assert(mme_ue, return NULL, "Null param");
2017-04-12 04:45:57 +00:00
d_assert(apn, return NULL, "Null param");
pool_alloc_node(&mme_pdn_pool, &pdn);
d_assert(pdn, return NULL, "PDN context allocation failed");
memset(pdn, 0, sizeof(pdn_t));
strcpy(pdn->apn, apn);
pdn->context = mme_ue;
list_append(&mme_ue->pdn_list, pdn);
2017-04-12 04:45:57 +00:00
return pdn;
}
status_t mme_pdn_remove(pdn_t *pdn)
{
mme_ue_t *mme_ue = NULL;
2017-04-12 04:45:57 +00:00
d_assert(pdn, return CORE_ERROR, "Null param");
mme_ue = pdn->context;
d_assert(mme_ue, return CORE_ERROR, "Null param");
2017-04-12 04:45:57 +00:00
list_remove(&mme_ue->pdn_list, pdn);
2017-04-12 04:45:57 +00:00
pool_free_node(&mme_pdn_pool, pdn);
return CORE_OK;
}
status_t mme_pdn_remove_all(mme_ue_t *mme_ue)
2017-04-12 04:45:57 +00:00
{
pdn_t *pdn = NULL, *next_pdn = NULL;
d_assert(mme_ue, return CORE_ERROR, "Null param");
2017-04-12 04:45:57 +00:00
pdn = list_first(&mme_ue->pdn_list);
2017-04-12 04:45:57 +00:00
while (pdn)
{
next_pdn = list_next(pdn);
mme_pdn_remove(pdn);
pdn = next_pdn;
}
return CORE_OK;
}
pdn_t* mme_pdn_find_by_apn(mme_ue_t *mme_ue, c_int8_t *apn)
2017-04-12 04:45:57 +00:00
{
pdn_t *pdn = NULL;
d_assert(mme_ue, return NULL, "Null param");
2017-04-12 04:45:57 +00:00
pdn = list_first(&mme_ue->pdn_list);
2017-04-12 04:45:57 +00:00
while (pdn)
{
if (strcmp(pdn->apn, apn) == 0)
break;
pdn = list_next(pdn);
}
return pdn;
}
pdn_t* mme_pdn_first(mme_ue_t *mme_ue)
2017-04-12 04:45:57 +00:00
{
d_assert(mme_ue, return NULL, "Null param");
return list_first(&mme_ue->pdn_list);
2017-04-12 04:45:57 +00:00
}
pdn_t* mme_pdn_next(pdn_t *pdn)
{
return list_next(pdn);
}