2019-05-31 05:05:45 +00:00
|
|
|
#include "ogs-sctp.h"
|
2017-02-13 00:58:55 +00:00
|
|
|
|
2019-06-11 09:28:25 +00:00
|
|
|
#include "gtp/gtp-xact.h"
|
2019-04-27 14:54:30 +00:00
|
|
|
#include "app/context.h"
|
|
|
|
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "mme-context.h"
|
|
|
|
#include "mme-sm.h"
|
|
|
|
#include "mme-event.h"
|
2017-02-13 00:58:55 +00:00
|
|
|
|
2019-06-11 13:10:47 +00:00
|
|
|
#include "mme-fd-path.h"
|
2017-03-04 15:20:09 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static ogs_thread_t *thread;
|
|
|
|
static void mme_main(void *data);
|
2017-02-02 11:34:37 +00:00
|
|
|
|
2017-08-02 15:11:09 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
int mme_initialize()
|
2017-02-02 11:34:37 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
int rv;
|
2017-02-02 11:34:37 +00:00
|
|
|
|
2019-05-06 11:43:50 +00:00
|
|
|
mme_context_init();
|
|
|
|
mme_event_init();
|
|
|
|
|
|
|
|
rv = gtp_xact_init(mme_self()->timer_mgr);
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2017-02-26 12:16:03 +00:00
|
|
|
|
2017-07-14 10:00:26 +00:00
|
|
|
rv = mme_context_parse_config();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2017-07-14 10:00:26 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
rv = context_setup_log_module();
|
|
|
|
if (rv != OGS_OK) return rv;
|
2017-07-31 13:35:25 +00:00
|
|
|
|
2018-01-21 06:44:30 +00:00
|
|
|
rv = mme_m_tmsi_pool_generate();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return rv;
|
2018-01-21 06:44:30 +00:00
|
|
|
|
2018-01-10 05:15:00 +00:00
|
|
|
rv = mme_fd_init();
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv != OGS_OK) return OGS_ERROR;
|
2017-02-27 04:56:13 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
thread = ogs_thread_create(mme_main, NULL);
|
|
|
|
if (!thread) return OGS_ERROR;
|
2017-10-18 16:09:06 +00:00
|
|
|
|
2017-08-02 15:11:09 +00:00
|
|
|
initialized = 1;
|
2017-03-04 14:48:04 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
return OGS_OK;
|
2017-02-02 11:34:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 14:48:04 +00:00
|
|
|
void mme_terminate(void)
|
2017-02-02 11:34:37 +00:00
|
|
|
{
|
2017-08-02 15:11:09 +00:00
|
|
|
if (!initialized) return;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
mme_event_term();
|
|
|
|
|
|
|
|
ogs_thread_destroy(thread);
|
2017-03-04 14:48:04 +00:00
|
|
|
|
2017-08-25 11:31:08 +00:00
|
|
|
mme_fd_final();
|
2017-03-04 15:20:09 +00:00
|
|
|
|
2017-04-06 11:10:00 +00:00
|
|
|
mme_context_final();
|
2017-04-11 13:44:57 +00:00
|
|
|
|
|
|
|
gtp_xact_final();
|
2019-04-27 14:54:30 +00:00
|
|
|
|
|
|
|
mme_event_final();
|
2017-02-02 11:34:37 +00:00
|
|
|
}
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
static void mme_main(void *data)
|
2017-02-13 04:19:53 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_fsm_t mme_sm;
|
|
|
|
int rv;
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_fsm_create(&mme_sm, mme_state_initial, mme_state_final);
|
|
|
|
ogs_fsm_init(&mme_sm, 0);
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
for ( ;; )
|
2017-02-13 04:19:53 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_pollset_poll(mme_self()->pollset,
|
|
|
|
ogs_timer_mgr_next(mme_self()->timer_mgr));
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_timer_mgr_expire(mme_self()->timer_mgr);
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
for ( ;; )
|
2017-02-13 04:19:53 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
mme_event_t *e = NULL;
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
rv = ogs_queue_trypop(mme_self()->queue, (void**)&e);
|
|
|
|
ogs_assert(rv != OGS_ERROR);
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv == OGS_DONE)
|
|
|
|
goto done;
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
if (rv == OGS_RETRY)
|
|
|
|
break;
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_assert(e);
|
|
|
|
ogs_fsm_dispatch(&mme_sm, e);
|
|
|
|
mme_event_free(e);
|
|
|
|
}
|
2017-02-13 04:19:53 +00:00
|
|
|
}
|
2019-04-27 14:54:30 +00:00
|
|
|
done:
|
2017-02-13 04:19:53 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_fsm_fini(&mme_sm, 0);
|
|
|
|
ogs_fsm_delete(&mme_sm);
|
2017-02-13 04:19:53 +00:00
|
|
|
}
|