diff --git a/lib/asn/src/Makefile.am b/lib/asn/src/Makefile.am index 95ac8e9a8b..d344fe30fb 100644 --- a/lib/asn/src/Makefile.am +++ b/lib/asn/src/Makefile.am @@ -5,7 +5,7 @@ SUBDIRS = asn1c noinst_LTLIBRARIES = libasn.la libasn_la_SOURCES = \ - s1ap_ies_defs.h s1ap_message.h + s1ap_ies_defs.h s1ap_codecs.h nodist_libasn_la_SOURCES = \ s1ap_encoder.c s1ap_decoder.c \ diff --git a/lib/asn/src/s1ap_message.h b/lib/asn/src/s1ap_codecs.h similarity index 86% rename from lib/asn/src/s1ap_message.h rename to lib/asn/src/s1ap_codecs.h index d1faee5b5c..9e72b69b31 100644 --- a/lib/asn/src/s1ap_message.h +++ b/lib/asn/src/s1ap_codecs.h @@ -1,5 +1,5 @@ -#ifndef _S1AP_MESSAGE_H__ -#define _S1AP_MESSAGE_H__ +#ifndef _S1AP_CODECS_H__ +#define _S1AP_CODECS_H__ #include "core_pkbuf.h" #include "s1ap_ies_defs.h" diff --git a/lib/asn/src/s1ap_decoder.c b/lib/asn/src/s1ap_decoder.c index af486e94ec..3736ecaf1a 100644 --- a/lib/asn/src/s1ap_decoder.c +++ b/lib/asn/src/s1ap_decoder.c @@ -1,8 +1,7 @@ -#define TRACE_MODULE _decoder +#define TRACE_MODULE _s1dec #include "core_debug.h" -#include "s1ap_message.h" - +#include "s1ap_codecs.h" static int s1ap_decode_initiating(s1ap_message *message, S1ap_InitiatingMessage_t *initiating_p); diff --git a/lib/asn/src/s1ap_encoder.c b/lib/asn/src/s1ap_encoder.c index 4ebd8c1a20..f57f471ef3 100644 --- a/lib/asn/src/s1ap_encoder.c +++ b/lib/asn/src/s1ap_encoder.c @@ -1,7 +1,7 @@ -#define TRACE_MODULE _encoder +#define TRACE_MODULE _s1enc #include "core_debug.h" -#include "s1ap_message.h" +#include "s1ap_codecs.h" static inline int s1ap_encode_initiating( s1ap_message *message_p, pkbuf_t *pkbuf); diff --git a/src/Makefile.am b/src/Makefile.am index 81159fe1ac..2039730fc5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,10 +3,10 @@ noinst_LTLIBRARIES = libcellwire.la libcellwire_la_SOURCES = \ - cellwire.h + cellwire.h context.h nodist_libcellwire_la_SOURCES = \ - init.c + init.c context.c AM_CPPFLAGS = \ -I$(top_srcdir)/include \ diff --git a/src/context.c b/src/context.c new file mode 100644 index 0000000000..04e5150038 --- /dev/null +++ b/src/context.c @@ -0,0 +1,95 @@ +#define TRACE_MODULE _ctx +#include "core_debug.h" +#include "core_pool.h" +#include "core_rwlock.h" +#include "core_index.h" + +#include "cellwire.h" +#include "context.h" + +static mme_ctx_t self; + +static int g_mme_ctx_initialized = 0; + +static rwlock_id g_rwlock; +static int g_cpath_post_q; + +status_t context_init() +{ + d_assert(g_mme_ctx_initialized == 0, return CORE_ERROR, + "MME context already has been initialized"); + + rwlock_create(&g_rwlock); + d_assert(g_rwlock, return CORE_ERROR, "RW-lock creation failed"); + + /* Initialize MME context */ + memset(&self, 0, sizeof(mme_ctx_t)); + + self.plmn_id.num_mnc_digits = 2; + self.plmn_id.mcc[2] = 1; + self.plmn_id.mnc[1] = 1; + self.mme_capacity = 0xff; + + self.srvd_gummei.num_of_plmn = 1; + self.srvd_gummei.plmn_id[0].num_mnc_digits = 2; + self.srvd_gummei.plmn_id[0].mcc[0] = 0; + self.srvd_gummei.plmn_id[0].mcc[1] = 0; + self.srvd_gummei.plmn_id[0].mcc[2] = 1; + self.srvd_gummei.plmn_id[0].mnc[0] = 0; + self.srvd_gummei.plmn_id[0].mnc[1] = 1; + + self.srvd_gummei.num_of_grp_id = 1; + self.srvd_gummei.grp_id[0] = 2; + self.srvd_gummei.num_of_code = 1; + self.srvd_gummei.code[0] = 1; + + g_mme_ctx_initialized = 1; + + return CORE_OK; +} + +status_t context_final() +{ + d_assert(g_mme_ctx_initialized == 1, return CORE_ERROR, + "HyperCell context already has been finalized"); + + g_mme_ctx_initialized = 0; + + return CORE_OK; +} + +status_t context_read_lock() +{ + return rwlock_rdlock(g_rwlock); +} + +status_t context_write_lock() +{ + return rwlock_wrlock(g_rwlock); +} + +status_t context_unlock() +{ + return rwlock_unlock(g_rwlock); +} + +void context_post_cpath() +{ + g_cpath_post_q = 1; +} + +int context_fetch_cpath() +{ + if (g_cpath_post_q) + { + g_cpath_post_q = 0; + return 1; + } + + return 0; +} + +mme_ctx_t* mme_self() +{ + return &self; +} diff --git a/src/context.h b/src/context.h new file mode 100644 index 0000000000..df43962a1a --- /dev/null +++ b/src/context.h @@ -0,0 +1,57 @@ +#ifndef __CELLWIRE_CONTEXT_H__ +#define __CELLWIRE_CONTEXT_H__ + +#include "core_list.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define MAX_PLMN_ID 6 +#define GRP_PER_MME 256 /* According to spec it is 65535 */ +#define CODE_PER_MME 256 /* According to spec it is 256*/ + +typedef struct _plmn_id_t { + c_uint8_t num_mnc_digits; + c_uint8_t mcc[3]; + c_uint8_t mnc[3]; +} plmn_id_t; + +typedef struct _served_gummei { + c_uint32_t num_of_plmn; + plmn_id_t plmn_id[MAX_PLMN_ID]; + + c_uint32_t num_of_grp_id; + c_uint16_t grp_id[GRP_PER_MME]; + c_uint32_t num_of_code; + c_uint8_t code[CODE_PER_MME]; +} srvd_gummei_t; + +/** + * This structure represents HypcerCell */ +typedef struct _mme_ctx_t { + plmn_id_t plmn_id; + + c_uint8_t mme_capacity; + + srvd_gummei_t srvd_gummei; +} mme_ctx_t; + +CORE_DECLARE(status_t) context_init(void); +CORE_DECLARE(status_t) context_final(void); + +CORE_DECLARE(status_t) context_read_lock(void); +CORE_DECLARE(status_t) context_write_lock(void); +CORE_DECLARE(status_t) context_unlock(void); + +CORE_DECLARE(void) context_post_cpath(void); +CORE_DECLARE(int) context_fetch_cpath(void); + +CORE_DECLARE(mme_ctx_t*) mme_self(void); +#define self() mme_self() + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* !__CELLWIRE_CONTEXT_H__ */