From f6636453b636751c378791957ee86a12cb5d073e Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Thu, 17 Aug 2017 14:15:08 +0900 Subject: [PATCH] add initial code for PCRF --- Makefile.am | 5 +- configure.ac | 1 + lib/base/Makefile.am | 6 +- lib/base/context.c | 4 + lib/base/context.h | 1 + lib/core/src/Makefile.am | 9 +- lib/core/src/unix/Makefile.am | 6 +- lib/fd/Makefile.am | 6 +- lib/fd/extensions/dict_dcca/Makefile.am | 2 - lib/fd/extensions/dict_dcca_3gpp/Makefile.am | 2 - lib/fd/extensions/dict_legacy_xml/Makefile.am | 2 - lib/fd/extensions/dict_nasreq/Makefile.am | 2 - lib/fd/extensions/dict_s6a/Makefile.am | 2 - lib/fd/extensions/dict_s6a/dict_s6a.c | 24 +- lib/fd/gx/Makefile.am | 6 +- lib/fd/s6a/Makefile.am | 6 +- lib/fd/s6a/dict_init.c | 12 +- lib/gtp/Makefile.am | 6 +- lib/logger/Makefile.am | 7 +- lib/nas/Makefile.am | 6 +- lib/s1ap/Makefile.am | 6 +- lib/s1ap/asn1c/Makefile.am | 5 +- src/Makefile.am | 37 +-- src/app.h | 3 + src/epc.c | 62 +++++ src/hss/Makefile.am | 6 +- src/hss/hss_context.h | 12 +- src/mme/Makefile.am | 6 +- src/mme/mme_context.c | 4 - src/mme/mme_context.h | 84 +++---- src/pcrf.c | 44 ++++ src/pcrf/Makefile.am | 30 +++ src/pcrf/pcrf_context.c | 235 ++++++++++++++++++ src/pcrf/pcrf_context.h | 33 +++ src/pcrf/pcrf_gx_handler.c | 69 +++++ src/pcrf/pcrf_gx_handler.h | 18 ++ src/pcrf/pcrf_init.c | 43 ++++ src/pgw/Makefile.am | 6 +- src/sgw/Makefile.am | 6 +- 39 files changed, 645 insertions(+), 179 deletions(-) create mode 100644 src/pcrf.c create mode 100644 src/pcrf/Makefile.am create mode 100644 src/pcrf/pcrf_context.c create mode 100644 src/pcrf/pcrf_context.h create mode 100644 src/pcrf/pcrf_gx_handler.c create mode 100644 src/pcrf/pcrf_gx_handler.h create mode 100644 src/pcrf/pcrf_init.c diff --git a/Makefile.am b/Makefile.am index 510bc646ca..8ebf426a42 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = lib src test -bin_PROGRAMS = mmed hssd sgwd pgwd epcd +bin_PROGRAMS = mmed hssd sgwd pgwd pcrfd epcd dist_mmed_SOURCES = main.c mmed_LDADD = $(top_srcdir)/src/libmme.la @@ -18,6 +18,9 @@ sgwd_LDADD = $(top_srcdir)/src/libsgw.la dist_pgwd_SOURCES = main.c pgwd_LDADD = $(top_srcdir)/src/libpgw.la +dist_pcrfd_SOURCES = main.c +pcrfd_LDADD = $(top_srcdir)/src/libpcrf.la + dist_epcd_SOURCES = main.c epcd_LDADD = $(top_srcdir)/src/libepc.la diff --git a/configure.ac b/configure.ac index c896af177a..ce33b8726b 100644 --- a/configure.ac +++ b/configure.ac @@ -329,6 +329,7 @@ AC_CONFIG_FILES([src/mme/Makefile]) AC_CONFIG_FILES([src/hss/Makefile]) AC_CONFIG_FILES([src/sgw/Makefile]) AC_CONFIG_FILES([src/pgw/Makefile]) +AC_CONFIG_FILES([src/pcrf/Makefile]) AC_CONFIG_FILES([src/Makefile]) AC_CONFIG_FILES([test/Makefile]) AC_CONFIG_FILES([support/nextepc.conf]) diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index a82dfac835..a762e8dbd5 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -3,9 +3,7 @@ noinst_LTLIBRARIES = libbase.la libbase_la_SOURCES = \ - types.h context.h - -nodist_libbase_la_SOURCES = \ + types.h context.h \ types.c context.c AM_CPPFLAGS = \ @@ -19,5 +17,3 @@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/base/context.c b/lib/base/context.c index dbc68c9550..eb296c93ca 100644 --- a/lib/base/context.c +++ b/lib/base/context.c @@ -180,6 +180,10 @@ status_t context_parse_config() { if (v) self.hidden.disable_pgw = atoi(v); } + else if (jsmntok_equal(json, t+m, "DISABLE_PCRF") == 0) + { + if (v) self.hidden.disable_pcrf = atoi(v); + } } } diff --git a/lib/base/context.h b/lib/base/context.h index dd85ce27e1..099e1c82d0 100644 --- a/lib/base/context.h +++ b/lib/base/context.h @@ -42,6 +42,7 @@ typedef struct _context_t { int disable_hss; int disable_sgw; int disable_pgw; + int disable_pcrf; } hidden; } context_t; diff --git a/lib/core/src/Makefile.am b/lib/core/src/Makefile.am index 751dbef3be..f92c3760d4 100644 --- a/lib/core/src/Makefile.am +++ b/lib/core/src/Makefile.am @@ -5,7 +5,6 @@ SUBDIRS = @OSDIR@ noinst_LTLIBRARIES = libcore.la libcore_la_SOURCES = \ - version.c \ ../include/core_aes_cmac.h ../include/core_aes.h ../include/core_cond.h \ ../include/core_debug.h ../include/core_errno.h ../include/core_file.h \ ../include/core_fsm.h ../include/core_general.h ../include/core.h \ @@ -19,10 +18,8 @@ libcore_la_SOURCES = \ ../include/core_timer.h ../include/core_tlv.h ../include/core_tlv_msg.h \ ../include/core_atomic.h ../include/core_portable.h \ ../include/core_version.h ../include/core_event.h ../include/core_hash.h \ - ../include/core_jsmn.h - -nodist_libcore_la_SOURCES = \ - debug.c fsm.c msgq.c ringbuf.c timer.c tlv.c tlv_msg.c \ + ../include/core_jsmn.h \ + version.c debug.c fsm.c msgq.c ringbuf.c timer.c tlv.c tlv_msg.c \ aes.c aes_cmac.c sha1.c sha1_hmac.c sha2.c sha2_hmac.c misc.c event.c \ hash.c jsmn.c @@ -41,5 +38,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/core/src/unix/Makefile.am b/lib/core/src/unix/Makefile.am index 21ad0bde2b..2d2ef74d5d 100644 --- a/lib/core/src/unix/Makefile.am +++ b/lib/core/src/unix/Makefile.am @@ -7,9 +7,7 @@ libcoreunix_la_SOURCES = \ ../../include/arch/unix/core_arch_file.h \ ../../include/arch/unix/core_arch_mutex.h \ ../../include/arch/unix/core_arch_semaphore.h \ - ../../include/arch/unix/core_arch_thread.h - -nodist_libcoreunix_la_SOURCES = \ + ../../include/arch/unix/core_arch_thread.h \ cond.c file.c net_lib.c thread.c errorcodes.c mutex.c rwlock.c \ start.c time.c semaphore.c signal.c pkbuf.c rand.c atomic.c @@ -23,5 +21,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/fd/Makefile.am b/lib/fd/Makefile.am index 0ede69ea5a..647e950cb0 100644 --- a/lib/fd/Makefile.am +++ b/lib/fd/Makefile.am @@ -5,9 +5,7 @@ SUBDIRS = extensions gx s6a noinst_LTLIBRARIES = libfd.la libfd_la_SOURCES = \ - fd_message.h fd_logger.h fd_init.h fd_lib.h - -nodist_libfd_la_SOURCES = \ + fd_message.h fd_logger.h fd_lib.h \ libapp_sip.c fd_message.c fd_logger.c fd_init.c AM_CPPFLAGS = \ @@ -18,5 +16,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/fd/extensions/dict_dcca/Makefile.am b/lib/fd/extensions/dict_dcca/Makefile.am index 0d5f82e800..6ccc2ac6fa 100644 --- a/lib/fd/extensions/dict_dcca/Makefile.am +++ b/lib/fd/extensions/dict_dcca/Makefile.am @@ -13,5 +13,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(pkglib_LTLIBRARIES) diff --git a/lib/fd/extensions/dict_dcca_3gpp/Makefile.am b/lib/fd/extensions/dict_dcca_3gpp/Makefile.am index b64dbd4f41..81d50c11a1 100644 --- a/lib/fd/extensions/dict_dcca_3gpp/Makefile.am +++ b/lib/fd/extensions/dict_dcca_3gpp/Makefile.am @@ -13,5 +13,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(pkglib_LTLIBRARIES) diff --git a/lib/fd/extensions/dict_legacy_xml/Makefile.am b/lib/fd/extensions/dict_legacy_xml/Makefile.am index b1537eac02..30ca518eff 100644 --- a/lib/fd/extensions/dict_legacy_xml/Makefile.am +++ b/lib/fd/extensions/dict_legacy_xml/Makefile.am @@ -21,5 +21,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(pkglib_LTLIBRARIES) diff --git a/lib/fd/extensions/dict_nasreq/Makefile.am b/lib/fd/extensions/dict_nasreq/Makefile.am index 2e251459cf..132704731b 100644 --- a/lib/fd/extensions/dict_nasreq/Makefile.am +++ b/lib/fd/extensions/dict_nasreq/Makefile.am @@ -13,5 +13,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(pkglib_LTLIBRARIES) diff --git a/lib/fd/extensions/dict_s6a/Makefile.am b/lib/fd/extensions/dict_s6a/Makefile.am index 0480651e86..09780ef159 100644 --- a/lib/fd/extensions/dict_s6a/Makefile.am +++ b/lib/fd/extensions/dict_s6a/Makefile.am @@ -13,5 +13,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(pkglib_LTLIBRARIES) diff --git a/lib/fd/extensions/dict_s6a/dict_s6a.c b/lib/fd/extensions/dict_s6a/dict_s6a.c index d3fdef8fae..88c34e4be9 100644 --- a/lib/fd/extensions/dict_s6a/dict_s6a.c +++ b/lib/fd/extensions/dict_s6a/dict_s6a.c @@ -340,7 +340,7 @@ int dict_s6a_init(char * conffile) struct dict_object * cmd; struct dict_cmd_data data = { 316, /* Code */ - "3GPP/Update-Location-Request", /* Name */ + "Update-Location-Request", /* Name */ CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE /* Fixed flag values */ }; @@ -377,7 +377,7 @@ int dict_s6a_init(char * conffile) struct dict_object * cmd; struct dict_cmd_data data = { 316, /* Code */ - "3GPP/Update-Location-Answer", /* Name */ + "Update-Location-Answer", /* Name */ CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ CMD_FLAG_PROXIABLE /* Fixed flag values */ }; @@ -407,7 +407,7 @@ int dict_s6a_init(char * conffile) struct dict_object * cmd; struct dict_cmd_data data = { 318, /* Code */ - "3GPP/Authentication-Information-Request", /* Name */ + "Authentication-Information-Request", /* Name */ CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE /* Fixed flag values */ }; @@ -439,7 +439,7 @@ int dict_s6a_init(char * conffile) struct dict_object * cmd; struct dict_cmd_data data = { 318, /* Code */ - "3GPP/Authentication-Information-Answer", /* Name */ + "Authentication-Information-Answer", /* Name */ CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ CMD_FLAG_PROXIABLE /* Fixed flag values */ }; @@ -468,10 +468,10 @@ int dict_s6a_init(char * conffile) { struct dict_object * cmd; struct dict_cmd_data data = { - 321, /* Code */ - "3GPP/Purge-UE-Request", /* Name */ - CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ - CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE /* Fixed flag values */ + 321, /* Code */ + "Purge-UE-Request", /* Name */ + CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ + CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE /* Fixed flag values */ }; struct local_rules_definition rules[] = { @@ -497,10 +497,10 @@ int dict_s6a_init(char * conffile) { struct dict_object * cmd; struct dict_cmd_data data = { - 321, /* Code */ - "3GPP/Purge-UE-Answer", /* Name */ - CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ - CMD_FLAG_PROXIABLE /* Fixed flag values */ + 321, /* Code */ + "Purge-UE-Answer", /* Name */ + CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */ + CMD_FLAG_PROXIABLE /* Fixed flag values */ }; struct local_rules_definition rules[] = { diff --git a/lib/fd/gx/Makefile.am b/lib/fd/gx/Makefile.am index 1310a1b06b..06b57f93a8 100644 --- a/lib/fd/gx/Makefile.am +++ b/lib/fd/gx/Makefile.am @@ -2,13 +2,11 @@ noinst_LTLIBRARIES = libfdgx.la -nodist_libfdgx_la_SOURCES = \ - dict_init.c +libfdgx_la_SOURCES = \ + gx_lib.h dict_init.c AM_CFLAGS = \ -Wall -Werror MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/fd/s6a/Makefile.am b/lib/fd/s6a/Makefile.am index 328f4d81b0..e2c40afc9d 100644 --- a/lib/fd/s6a/Makefile.am +++ b/lib/fd/s6a/Makefile.am @@ -2,13 +2,11 @@ noinst_LTLIBRARIES = libfds6a.la -nodist_libfds6a_la_SOURCES = \ - dict_init.c +libfds6a_la_SOURCES = \ + s6a_lib.h dict_init.c AM_CFLAGS = \ -Wall -Werror MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/fd/s6a/dict_init.c b/lib/fd/s6a/dict_init.c index 8133e3b1c3..b0c57b996b 100644 --- a/lib/fd/s6a/dict_init.c +++ b/lib/fd/s6a/dict_init.c @@ -54,12 +54,12 @@ int s6a_dict_init(void) CHECK_dict_search( DICT_APPLICATION, APPLICATION_BY_ID, (void *)&id, &s6a_application); - CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "3GPP/Authentication-Information-Request", &s6a_cmd_air); - CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "3GPP/Authentication-Information-Answer", &s6a_cmd_aia); - CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "3GPP/Update-Location-Request", &s6a_cmd_ulr); - CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "3GPP/Update-Location-Answer", &s6a_cmd_ula); - CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "3GPP/Purge-UE-Request", &s6a_cmd_pur); - CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "3GPP/Purge-UE-Answer", &s6a_cmd_pua); + CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "Authentication-Information-Request", &s6a_cmd_air); + CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "Authentication-Information-Answer", &s6a_cmd_aia); + CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "Update-Location-Request", &s6a_cmd_ulr); + CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "Update-Location-Answer", &s6a_cmd_ula); + CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "Purge-UE-Request", &s6a_cmd_pur); + CHECK_dict_search( DICT_COMMAND, CMD_BY_NAME, "Purge-UE-Answer", &s6a_cmd_pua); CHECK_dict_search(DICT_AVP, AVP_BY_NAME_ALL_VENDORS, "Visited-PLMN-Id", &s6a_visited_plmn_id); CHECK_dict_search(DICT_AVP, AVP_BY_NAME_ALL_VENDORS, "RAT-Type", &s6a_rat_type); diff --git a/lib/gtp/Makefile.am b/lib/gtp/Makefile.am index a5e2e1c1cd..9d42497a66 100644 --- a/lib/gtp/Makefile.am +++ b/lib/gtp/Makefile.am @@ -3,9 +3,7 @@ noinst_LTLIBRARIES = libgtp.la libgtp_la_SOURCES = \ - gtp_tlv.h gtp_types.h gtp_path.h gtp_xact.h - -nodist_libgtp_la_SOURCES = \ + gtp_tlv.h gtp_types.h gtp_path.h gtp_xact.h \ gtp_tlv.c gtp_types.c gtp_path.c gtp_xact.c libgtp_la_DEPENDENCIES = \ @@ -23,5 +21,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/logger/Makefile.am b/lib/logger/Makefile.am index 573c4b1ef9..6e438281c5 100644 --- a/lib/logger/Makefile.am +++ b/lib/logger/Makefile.am @@ -2,9 +2,8 @@ noinst_LTLIBRARIES = liblogger.la -liblogger_la_SOURCES = logger.h - -nodist_liblogger_la_SOURCES = logger.c +liblogger_la_SOURCES = \ + logger.h logger.c AM_CPPFLAGS = \ -I$(top_srcdir)/lib/core/include @@ -14,5 +13,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/nas/Makefile.am b/lib/nas/Makefile.am index 9a6695eb5a..778ed47091 100644 --- a/lib/nas/Makefile.am +++ b/lib/nas/Makefile.am @@ -3,9 +3,7 @@ noinst_LTLIBRARIES = libnas.la libnas_la_SOURCES = \ - nas_message.h nas_ies.h nas_types.h - -nodist_libnas_la_SOURCES = \ + nas_message.h nas_ies.h nas_types.h \ nas_decoder.c nas_encoder.c nas_ies.c libnas_la_DEPENDENCIES = \ @@ -23,5 +21,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/s1ap/Makefile.am b/lib/s1ap/Makefile.am index db7e824a6e..1316136bf4 100644 --- a/lib/s1ap/Makefile.am +++ b/lib/s1ap/Makefile.am @@ -5,9 +5,7 @@ SUBDIRS = asn1c noinst_LTLIBRARIES = libs1ap.la libs1ap_la_SOURCES = \ - s1ap_asn1c.h s1ap_ies_defs.h s1ap_message.h - -nodist_libs1ap_la_SOURCES = \ + s1ap_asn1c.h s1ap_ies_defs.h s1ap_message.h \ s1ap_encoder.c s1ap_decoder.c s1ap_free.c \ s1ap_ies_encoder.c s1ap_ies_decoder.c s1ap_ies_free.c s1ap_ies_xer_print.c @@ -29,5 +27,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/lib/s1ap/asn1c/Makefile.am b/lib/s1ap/asn1c/Makefile.am index 9600f16c3d..32baf2590b 100644 --- a/lib/s1ap/asn1c/Makefile.am +++ b/lib/s1ap/asn1c/Makefile.am @@ -803,8 +803,7 @@ ASN_MODULE_INCLUDES+=per_opentype.h ASN_MODULE_SOURCES+=per_opentype.c noinst_LTLIBRARIES=libs1apasn1c.la -libs1apasn1c_la_SOURCES=$(ASN_MODULE_INCLUDES) -nodist_libs1apasn1c_la_SOURCES=$(ASN_MODULE_SOURCES) +libs1apasn1c_la_SOURCES=$(ASN_MODULE_INCLUDES) $(ASN_MODULE_SOURCES) AM_CPPFLAGS = \ -I$(top_srcdir)/lib/core/include @@ -815,8 +814,6 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump Makefile.am.sample converter-sample.c -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) - regen: regenerate-from-asn1-source regenerate-from-asn1-source: diff --git a/src/Makefile.am b/src/Makefile.am index 718c836562..da60ae9d9b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,14 +1,13 @@ ## Process this file with automake to produce Makefile.in. -SUBDIRS = mme hss sgw pgw +SUBDIRS = mme hss sgw pgw pcrf -noinst_LTLIBRARIES = libmme.la libhss.la libsgw.la libpgw.la libepc.la +noinst_LTLIBRARIES = libmme.la libhss.la libsgw.la libpgw.la libpcrf.la libepc.la COMMON_SOURCES = init.c COMMON_INCLUDES = app.h -libmme_la_SOURCES = $(COMMON_INCLUDES) -nodist_libmme_la_SOURCES = mme.c $(COMMON_SOURCES) +libmme_la_SOURCES = $(COMMON_INCLUDES) mme.c $(COMMON_SOURCES) libmme_la_DEPENDENCIES = \ $(top_srcdir)/lib/base/libbase.la \ $(top_srcdir)/lib/logger/liblogger.la \ @@ -18,8 +17,7 @@ libmme_la_LIBADD = \ $(top_srcdir)/lib/logger/liblogger.la \ $(top_srcdir)/src/mme/libmme.la -libhss_la_SOURCES = $(COMMON_INCLUDES) -nodist_libhss_la_SOURCES = hss.c $(COMMON_SOURCES) +libhss_la_SOURCES = $(COMMON_INCLUDES) hss.c $(COMMON_SOURCES) libhss_la_DEPENDENCIES = \ $(top_srcdir)/lib/base/libbase.la \ $(top_srcdir)/lib/logger/liblogger.la \ @@ -29,8 +27,7 @@ libhss_la_LIBADD = \ $(top_srcdir)/lib/logger/liblogger.la \ $(top_srcdir)/src/hss/libhss.la -libsgw_la_SOURCES = $(COMMON_INCLUDES) -nodist_libsgw_la_SOURCES = sgw.c $(COMMON_SOURCES) +libsgw_la_SOURCES = $(COMMON_INCLUDES) sgw.c $(COMMON_SOURCES) libsgw_la_DEPENDENCIES = \ $(top_srcdir)/lib/base/libbase.la \ $(top_srcdir)/lib/logger/liblogger.la \ @@ -40,8 +37,7 @@ libsgw_la_LIBADD = \ $(top_srcdir)/lib/logger/liblogger.la \ $(top_srcdir)/src/sgw/libsgw.la -libpgw_la_SOURCES = $(COMMON_INCLUDES) -nodist_libpgw_la_SOURCES = pgw.c $(COMMON_SOURCES) +libpgw_la_SOURCES = $(COMMON_INCLUDES) pgw.c $(COMMON_SOURCES) libpgw_la_DEPENDENCIES = \ $(top_srcdir)/lib/base/libbase.la \ $(top_srcdir)/lib/logger/liblogger.la \ @@ -51,22 +47,33 @@ libpgw_la_LIBADD = \ $(top_srcdir)/lib/logger/liblogger.la \ $(top_srcdir)/src/pgw/libpgw.la -libepc_la_SOURCES = $(COMMON_INCLUDES) -nodist_libepc_la_SOURCES = epc.c $(COMMON_SOURCES) +libpcrf_la_SOURCES = $(COMMON_INCLUDES) pcrf.c $(COMMON_SOURCES) +libpcrf_la_DEPENDENCIES = \ + $(top_srcdir)/lib/base/libbase.la \ + $(top_srcdir)/lib/logger/liblogger.la \ + $(top_srcdir)/src/pcrf/libpcrf.la +libpcrf_la_LIBADD = \ + $(top_srcdir)/lib/base/libbase.la \ + $(top_srcdir)/lib/logger/liblogger.la \ + $(top_srcdir)/src/pcrf/libpcrf.la + +libepc_la_SOURCES = $(COMMON_INCLUDES) epc.c $(COMMON_SOURCES) libepc_la_DEPENDENCIES = \ $(top_srcdir)/lib/base/libbase.la \ $(top_srcdir)/lib/logger/liblogger.la \ $(top_srcdir)/src/mme/libmme.la \ $(top_srcdir)/src/hss/libhss.la \ $(top_srcdir)/src/sgw/libsgw.la \ - $(top_srcdir)/src/pgw/libpgw.la + $(top_srcdir)/src/pgw/libpgw.la \ + $(top_srcdir)/src/pcrf/libpcrf.la libepc_la_LIBADD = \ $(top_srcdir)/lib/base/libbase.la \ $(top_srcdir)/lib/logger/liblogger.la \ $(top_srcdir)/src/mme/libmme.la \ $(top_srcdir)/src/hss/libhss.la \ $(top_srcdir)/src/sgw/libsgw.la \ - $(top_srcdir)/src/pgw/libpgw.la + $(top_srcdir)/src/pgw/libpgw.la \ + $(top_srcdir)/src/pcrf/libpcrf.la AM_CPPFLAGS = \ -I$(top_srcdir)/lib/core/include \ @@ -80,5 +87,3 @@ DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/src/app.h b/src/app.h index b7e7085f87..e9018c0e8a 100644 --- a/src/app.h +++ b/src/app.h @@ -31,6 +31,9 @@ CORE_DECLARE(void) sgw_terminate(void); CORE_DECLARE(status_t) pgw_initialize(); CORE_DECLARE(void) pgw_terminate(void); +CORE_DECLARE(status_t) pcrf_initialize(); +CORE_DECLARE(void) pcrf_terminate(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/epc.c b/src/epc.c index e5937005a5..a2e8c645a2 100644 --- a/src/epc.c +++ b/src/epc.c @@ -7,6 +7,9 @@ #include "context.h" #include "app.h" +static semaphore_id pcrf_sem1 = 0; +static semaphore_id pcrf_sem2 = 0; + static semaphore_id pgw_sem1 = 0; static semaphore_id pgw_sem2 = 0; @@ -32,6 +35,49 @@ status_t app_initialize(char *config_path, char *log_path) } + /************************* PCRF Process **********************/ + semaphore_create(&pcrf_sem1, 0); /* copied to PCRF/PGW/SGW/HSS process */ + semaphore_create(&pcrf_sem2, 0); /* copied to PCRF/PGW/SGW/HSS process */ + + if (context_self()->hidden.disable_pcrf == 0) + { + pid = fork(); + d_assert(pid >= 0, _exit(EXIT_FAILURE), "fork() failed"); + + if (pid == 0) + { + d_trace(1, "PCRF try to initialize\n"); + rv = pcrf_initialize(); + d_assert(rv == CORE_OK,, "Failed to intialize PCRF"); + d_trace(1, "PCRF initialize...done\n"); + + if (pcrf_sem1) semaphore_post(pcrf_sem1); + if (pcrf_sem2) semaphore_wait(pcrf_sem2); + + if (rv == CORE_OK) + { + d_trace(1, "PCRF try to terminate\n"); + pcrf_terminate(); + d_trace(1, "PCRF terminate...done\n"); + } + + if (pcrf_sem1) semaphore_post(pcrf_sem1); + + /* allocated from parent process */ + if (pcrf_sem1) semaphore_delete(pcrf_sem1); + if (pcrf_sem2) semaphore_delete(pcrf_sem2); + + app_did_terminate(); + + core_terminate(); + + _exit(EXIT_SUCCESS); + } + + if (pcrf_sem1) semaphore_wait(pcrf_sem1); + } + + /************************* PGW Process **********************/ semaphore_create(&pgw_sem1, 0); /* copied to PGW/SGW/HSS process */ @@ -44,6 +90,10 @@ status_t app_initialize(char *config_path, char *log_path) if (pid == 0) { + /* allocated from parent process */ + if (pcrf_sem1) semaphore_delete(pcrf_sem1); + if (pcrf_sem2) semaphore_delete(pcrf_sem2); + d_trace(1, "PGW try to initialize\n"); rv = pgw_initialize(); d_assert(rv == CORE_OK,, "Failed to intialize PGW"); @@ -89,6 +139,8 @@ status_t app_initialize(char *config_path, char *log_path) if (pid == 0) { /* allocated from parent process */ + if (pcrf_sem1) semaphore_delete(pcrf_sem1); + if (pcrf_sem2) semaphore_delete(pcrf_sem2); if (pgw_sem1) semaphore_delete(pgw_sem1); if (pgw_sem2) semaphore_delete(pgw_sem2); @@ -137,6 +189,8 @@ status_t app_initialize(char *config_path, char *log_path) if (pid == 0) { /* allocated from parent process */ + if (pcrf_sem1) semaphore_delete(pcrf_sem1); + if (pcrf_sem2) semaphore_delete(pcrf_sem2); if (pgw_sem1) semaphore_delete(pgw_sem1); if (pgw_sem2) semaphore_delete(pgw_sem2); if (sgw_sem1) semaphore_delete(sgw_sem1); @@ -215,5 +269,13 @@ void app_terminate(void) if (pgw_sem1) semaphore_delete(pgw_sem1); if (pgw_sem2) semaphore_delete(pgw_sem2); + if (context_self()->hidden.disable_pcrf == 0) + { + if (pcrf_sem2) semaphore_post(pcrf_sem2); + if (pcrf_sem1) semaphore_wait(pcrf_sem1); + } + if (pcrf_sem1) semaphore_delete(pcrf_sem1); + if (pcrf_sem2) semaphore_delete(pcrf_sem2); + app_did_terminate(); } diff --git a/src/hss/Makefile.am b/src/hss/Makefile.am index 79db656d3d..e5daba18a9 100644 --- a/src/hss/Makefile.am +++ b/src/hss/Makefile.am @@ -3,9 +3,7 @@ noinst_LTLIBRARIES = libhss.la libhss_la_SOURCES = \ - milenage.h hss_kdf.h hss_context.h hss_s6a_handler.h - -nodist_libhss_la_SOURCES = \ + milenage.h hss_kdf.h hss_context.h hss_s6a_handler.h \ milenage.c hss_kdf.c hss_init.c hss_context.c hss_s6a_handler.c libhss_la_DEPENDENCIES = \ @@ -30,5 +28,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/src/hss/hss_context.h b/src/hss/hss_context.h index 1de0561769..2b5c256fe6 100644 --- a/src/hss/hss_context.h +++ b/src/hss/hss_context.h @@ -47,16 +47,10 @@ typedef struct _hss_db_subscription_data_t { } hss_db_subscription_data_t; typedef struct _hss_context_t { - char* fd_conf_path; /* HSS freeDiameter conf path */ - char* hss_s6a_addr; /* HSS S6A local address (STIRNG)*/ - c_uint16_t hss_s6a_port; /* HSS S6A local port */ - c_uint16_t hss_s6a_tls_port; /* HSS S6A local TLS port */ - char* mme_s6a_addr; /* MME S6A address (STIRNG)*/ - c_uint16_t mme_s6a_port; /* MME S6A port */ - c_uint16_t mme_s6a_tls_port; /* MME S6A TLS port */ + char *fd_conf_path; /* HSS freeDiameter conf path */ - void *subscriberCollection; - mutex_id db_lock; + void *subscriberCollection; + mutex_id db_lock; } hss_context_t; CORE_DECLARE(status_t) hss_context_init(void); diff --git a/src/mme/Makefile.am b/src/mme/Makefile.am index 9bc5b01352..8ec09a916d 100644 --- a/src/mme/Makefile.am +++ b/src/mme/Makefile.am @@ -11,9 +11,7 @@ libmme_la_SOURCES = \ emm_handler.h emm_build.h \ esm_handler.h esm_build.h \ mme_s11_path.h mme_s11_build.h mme_s11_handler.h \ - mme_sm.h - -nodist_libmme_la_SOURCES = \ + mme_sm.h \ mme_kdf.c kasumi.c snow_3g.c zuc.c \ mme_init.c mme_event.c mme_context.c \ s1ap_sm.c s1ap_build.c s1ap_handler.c s1ap_conv.c s1ap_path.c \ @@ -55,5 +53,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/src/mme/mme_context.c b/src/mme/mme_context.c index 33709937a5..a3c9fbc2b9 100644 --- a/src/mme/mme_context.c +++ b/src/mme/mme_context.c @@ -105,10 +105,6 @@ static status_t mme_context_prepare() { self.relative_capacity = 0xff; - self.mme_s6a_port = DIAMETER_PORT; - self.mme_s6a_tls_port = DIAMETER_SECURE_PORT; - self.hss_s6a_port = DIAMETER_PORT; - self.hss_s6a_tls_port = DIAMETER_SECURE_PORT; self.s1ap_port = S1AP_SCTP_PORT; self.s11_port = GTPV2_C_UDP_PORT; diff --git a/src/mme/mme_context.h b/src/mme/mme_context.h index 03547bd195..b6af53ebc2 100644 --- a/src/mme/mme_context.h +++ b/src/mme/mme_context.h @@ -43,29 +43,23 @@ typedef struct _served_gummei { } served_gummei_t; typedef struct _mme_context_t { - char* fd_conf_path; /* MME freeDiameter conf path */ - char* mme_s6a_addr; /* MME S6A local address (STIRNG)*/ - c_uint16_t mme_s6a_port; /* MME S6A local port */ - c_uint16_t mme_s6a_tls_port; /* MME S6A local TLS port */ - char* hss_s6a_addr; /* HSS S6A address (STIRNG)*/ - c_uint16_t hss_s6a_port; /* HSS S6A port */ - c_uint16_t hss_s6a_tls_port; /* HSS S6A TLS port */ + char *fd_conf_path; /* MME freeDiameter conf path */ - c_uint32_t s1ap_addr; /* MME S1AP local address */ - c_uint16_t s1ap_port; /* MME S1AP local port */ - net_sock_t *s1ap_sock; /* MME S1AP local listen socket */ + c_uint32_t s1ap_addr; /* MME S1AP local address */ + c_uint16_t s1ap_port; /* MME S1AP local port */ + net_sock_t *s1ap_sock; /* MME S1AP local listen socket */ - c_uint32_t s11_addr; /* MME S11 local address */ - c_uint16_t s11_port; /* MME S11 local port */ - net_sock_t *s11_sock; /* MME S11 local listen socket */ + c_uint32_t s11_addr; /* MME S11 local address */ + c_uint16_t s11_port; /* MME S11 local port */ + net_sock_t *s11_sock; /* MME S11 local listen socket */ msgq_id queue_id; /* Queue for processing MME control plane */ tm_service_t tm_service; /* Timer Service */ gtp_xact_ctx_t gtp_xact_ctx; /* GTP Transaction Context for MME */ /* Generator for unique identification */ - c_uint32_t mme_ue_s1ap_id; /** mme_ue_s1ap_id generator */ - c_uint32_t m_tmsi; /** m_tmsi generator */ + c_uint32_t mme_ue_s1ap_id; /* mme_ue_s1ap_id generator */ + c_uint32_t m_tmsi; /* m_tmsi generator */ /* defined in 'nas_ies.h' * #define NAS_SECURITY_ALGORITHMS_EIA0 0 @@ -91,28 +85,28 @@ typedef struct _mme_context_t { served_gummei_t served_gummei[MAX_NUM_OF_SERVED_GUMMEI]; c_uint8_t relative_capacity; - /* Timer value*/ + /* Timer value */ c_uint32_t t3413_value; /* Paging retry timer */ list_t sgw_list; list_t enb_list; - hash_t *mme_ue_s1ap_id_hash; /* hash table for MME-UE-S1AP-ID */ - hash_t *imsi_ue_hash; /* hash table (IMSI : MME_UE) */ - hash_t *guti_ue_hash; /* hash table (GUTI : MME_UE) */ + hash_t *mme_ue_s1ap_id_hash; /* hash table for MME-UE-S1AP-ID */ + hash_t *imsi_ue_hash; /* hash table (IMSI : MME_UE) */ + hash_t *guti_ue_hash; /* hash table (GUTI : MME_UE) */ } mme_context_t; typedef struct _mme_sgw_t { - gtp_node_t gnode; /* SGW S11 remote GTPv2-C node */ + gtp_node_t gnode; /* SGW S11 remote GTPv2-C node */ } mme_sgw_t; typedef struct _mme_enb_t { - lnode_t node; /**< A node of list_t */ - index_t index; /**< An index of this node */ - fsm_t sm; + lnode_t node; /* A node of list_t */ + index_t index; /* An index of this node */ + fsm_t sm; /* A state machine */ - c_uint32_t enb_id; /** eNB_ID received from eNB */ + c_uint32_t enb_id; /* eNB_ID received from eNB */ net_sock_t *s1ap_sock; c_uint8_t num_of_tai; @@ -126,15 +120,13 @@ typedef struct _enb_ue_t enb_ue_t; typedef struct _mme_ue_t mme_ue_t; struct _enb_ue_t { - lnode_t node; /**< A node of list_t */ - index_t index; /**< An index of this node */ - fsm_t sm; - - /* State Machine */ + lnode_t node; /* A node of list_t */ + index_t index; /* An index of this node */ + fsm_t sm; /* A state machine */ /* UE identity */ - c_uint32_t enb_ue_s1ap_id; /** eNB-UE-S1AP-ID received from eNB */ - c_uint32_t mme_ue_s1ap_id; /** MME-UE-S1AP-ID received from MME */ + c_uint32_t enb_ue_s1ap_id; /* eNB-UE-S1AP-ID received from eNB */ + c_uint32_t mme_ue_s1ap_id; /* MME-UE-S1AP-ID received from MME */ /* UE Info */ tai_t tai; @@ -148,11 +140,9 @@ struct _enb_ue_t { }; struct _mme_ue_t { - lnode_t node; /**< A node of list_t */ - index_t index; /**< An index of this node */ - fsm_t sm; - - /* State Machine */ + lnode_t node; /* A node of list_t */ + index_t index; /* An index of this node */ + fsm_t sm; /* A state machine */ /* UE identity */ #define MME_UE_HAVE_IMSI(mme) \ @@ -215,10 +205,10 @@ struct _mme_ue_t { /* HSS Info */ c_uint32_t ula_flags; - c_uint32_t max_bandwidth_ul; /* bits per seconds */ - c_uint32_t max_bandwidth_dl; /* bits per seconds */ - c_uint32_t subscribed_rau_tau_timer; /* seconds */ - pdn_t pdn[MAX_NUM_OF_PDN]; /* APN Profile */ + c_uint32_t max_bandwidth_ul; /* bits per seconds */ + c_uint32_t max_bandwidth_dl; /* bits per seconds */ + c_uint32_t subscribed_rau_tau_timer; /* seconds */ + pdn_t pdn[MAX_NUM_OF_PDN]; /* APN Profile */ int num_of_pdn; /* ESM Info */ @@ -243,8 +233,8 @@ struct _mme_ue_t { }; typedef struct _mme_sess_t { - lnode_t node; /**< A node of list_t */ - index_t index; /**< An index of this node */ + lnode_t node; /* A node of list_t */ + index_t index; /* An index of this node */ /* IMPORTANT! * MME-S11-TEID is same with an index */ @@ -275,12 +265,12 @@ typedef struct _mme_sess_t { } mme_sess_t; typedef struct _mme_bearer_t { - lnode_t node; /**< A node of list_t */ - index_t index; /**< An index of this node */ - fsm_t sm; + lnode_t node; /* A node of list_t */ + index_t index; /* An index of this node */ + fsm_t sm; /* State Machine */ - c_uint8_t pti; /** Procedure Trasaction Identity */ - c_uint8_t ebi; /** EPS Bearer ID */ + c_uint8_t pti; /* Procedure Trasaction Identity */ + c_uint8_t ebi; /* EPS Bearer ID */ c_uint32_t enb_s1u_teid; c_uint32_t enb_s1u_addr; diff --git a/src/pcrf.c b/src/pcrf.c new file mode 100644 index 0000000000..a52e40bdd6 --- /dev/null +++ b/src/pcrf.c @@ -0,0 +1,44 @@ +#define TRACE_MODULE _pcrf_main + +#include "core_debug.h" +#include "core_signal.h" +#include "core_semaphore.h" + +#include "context.h" +#include "app.h" + +status_t app_initialize(char *config_path, char *log_path) +{ + status_t rv; + int others = 0; + + rv = app_will_initialize(config_path, log_path); + if (rv != CORE_OK) return rv; + + others = context_self()->trace_level.others; + if (others) + { + d_trace_level(&_pcrf_main, others); + } + + d_trace(1, "PCRF try to initialize\n"); + rv = pcrf_initialize(); + d_assert(rv == CORE_OK, return rv, "Failed to intialize PCRF"); + d_trace(1, "PCRF initialize...done\n"); + + rv = app_did_initialize(config_path, log_path); + if (rv != CORE_OK) return rv; + + return CORE_OK; +} + +void app_terminate(void) +{ + app_will_terminate(); + + d_trace(1, "PCRF try to terminate\n"); + pcrf_terminate(); + d_trace(1, "PCRF terminate...done\n"); + + app_did_terminate(); +} diff --git a/src/pcrf/Makefile.am b/src/pcrf/Makefile.am new file mode 100644 index 0000000000..5652663219 --- /dev/null +++ b/src/pcrf/Makefile.am @@ -0,0 +1,30 @@ +## Process this file with automake to produce Makefile.in. + +noinst_LTLIBRARIES = libpcrf.la + +libpcrf_la_SOURCES = \ + pcrf_context.h pcrf_gx_handler.h \ + pcrf_init.c pcrf_context.c pcrf_gx_handler.c + +libpcrf_la_DEPENDENCIES = \ + $(top_srcdir)/lib/core/src/libcore.la \ + $(top_srcdir)/lib/fd/gx/libfdgx.la \ + $(top_srcdir)/lib/fd/libfd.la + +libpcrf_la_LIBADD = \ + $(top_srcdir)/lib/core/src/libcore.la \ + $(top_srcdir)/lib/fd/gx/libfdgx.la \ + $(top_srcdir)/lib/fd/libfd.la + +AM_CPPFLAGS = \ + -I$(top_srcdir)/lib/core/include \ + -I$(top_srcdir)/lib/base \ + -I$(top_srcdir)/lib/fd/gx \ + -I$(top_srcdir)/lib/fd \ + @MONGOC_CFLAGS@ + +AM_CFLAGS = \ + -Wall -Werror + +MAINTAINERCLEANFILES = Makefile.in +MOSTLYCLEANFILES = core *.stackdump diff --git a/src/pcrf/pcrf_context.c b/src/pcrf/pcrf_context.c new file mode 100644 index 0000000000..eaca137b83 --- /dev/null +++ b/src/pcrf/pcrf_context.c @@ -0,0 +1,235 @@ +#define TRACE_MODULE _pcrf_context + +#include "core_debug.h" +#include "core_lib.h" + +#include + +#include "fd_lib.h" + +#include "context.h" +#include "pcrf_context.h" + +static pcrf_context_t self; +static int context_initialized = 0; + +pcrf_context_t* pcrf_self() +{ + return &self; +} + +status_t pcrf_context_init(void) +{ + d_assert(context_initialized == 0, return CORE_ERROR, + "PCRF context already has been context_initialized"); + + /* Initialize PCRF context */ + memset(&self, 0, sizeof(pcrf_context_t)); + + if (mutex_create(&self.db_lock, MUTEX_DEFAULT) != CORE_OK) + { + d_error("Mutex creation failed"); + return CORE_ERROR; + } + + context_initialized = 1; + + return CORE_OK; +} + +status_t pcrf_context_final(void) +{ + d_assert(context_initialized == 1, return CORE_ERROR, + "PCRF context already has been finalized"); + + mutex_delete(self.db_lock); + + context_initialized = 0; + + return CORE_OK; +} + +static status_t pcrf_context_prepare() +{ + return CORE_OK; +} + +static status_t pcrf_context_validation() +{ + if (self.fd_conf_path == NULL) + { + d_error("No PCRF.FD_CONF_PATH in '%s'", + context_self()->config.path); + return CORE_ERROR; + } + + return CORE_OK; +} + +status_t pcrf_context_parse_config() +{ + status_t rv; + config_t *config = &context_self()->config; + + char *json = config->json; + jsmntok_t *token = config->token; + + typedef enum { + START, ROOT, + PCRF_START, PCRF_ROOT, + SKIP, STOP + } parse_state; + parse_state state = START; + parse_state stack = STOP; + + size_t root_tokens = 0; + size_t pcrf_tokens = 0; + size_t skip_tokens = 0; + int i, j; + + rv = pcrf_context_prepare(); + if (rv != CORE_OK) return rv; + + 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: + { + if (jsmntok_equal(json, t, "PCRF") == 0) + { + state = PCRF_START; + } + else + { + state = SKIP; + stack = ROOT; + skip_tokens = t->size; + + root_tokens--; + if (root_tokens == 0) state = STOP; + } + + break; + } + case PCRF_START: + { + state = PCRF_ROOT; + pcrf_tokens = t->size; + + break; + } + case PCRF_ROOT: + { + if (jsmntok_equal(json, t, "FD_CONF_PATH") == 0) + { + self.fd_conf_path = jsmntok_to_string(json, t+1); + } + + state = SKIP; + stack = PCRF_ROOT; + skip_tokens = t->size; + + pcrf_tokens--; + if (pcrf_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; + } + + } + } + + rv = pcrf_context_validation(); + if (rv != CORE_OK) return rv; + + return CORE_OK; +} + +status_t pcrf_context_setup_trace_module() +{ + int fd = context_self()->trace_level.fd; + int others = context_self()->trace_level.others; + + if (fd) + { + if (fd <= 1) fd_g_debug_lvl = FD_LOG_ERROR; + else if (fd <= 3) fd_g_debug_lvl = FD_LOG_NOTICE; + else if (fd <= 5) fd_g_debug_lvl = FD_LOG_DEBUG; + else fd_g_debug_lvl = FD_LOG_ANNOYING; + + extern int _pcrf_gx_handler; + d_trace_level(&_pcrf_gx_handler, fd); + extern int _fd_init; + d_trace_level(&_fd_init, fd); + extern int _fd_logger; + d_trace_level(&_fd_logger, fd); + } + + if (others) + { + extern int _mutex; + d_trace_level(&_mutex, others); + extern int _pkbuf; + d_trace_level(&_pkbuf, others); + + extern int _context; + d_trace_level(&_context, others); + extern int _pcrf_context; + d_trace_level(&_pcrf_context, others); + } + + return CORE_OK; +} + +status_t pcrf_db_init() +{ + if (context_self()->db_client && context_self()->db_name) + { + self.subscriberCollection = mongoc_client_get_collection( + context_self()->db_client, + context_self()->db_name, "subscribers"); + d_assert(self.subscriberCollection, return CORE_ERROR, + "Couldn't find Subscriber Collection in '%s'", + context_self()->db_name) + } + + return CORE_OK; +} + +status_t pcrf_db_final() +{ + if (self.subscriberCollection) + { + mongoc_collection_destroy(self.subscriberCollection); + } + + return CORE_OK; +} diff --git a/src/pcrf/pcrf_context.h b/src/pcrf/pcrf_context.h new file mode 100644 index 0000000000..f874b76516 --- /dev/null +++ b/src/pcrf/pcrf_context.h @@ -0,0 +1,33 @@ +#ifndef __PCRF_CONTEXT_H__ +#define __PCRF_CONTEXT_H__ + +#include "core_errno.h" +#include "core_mutex.h" +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct _pcrf_context_t { + char *fd_conf_path; /* PCRF freeDiameter conf path */ + + void *subscriberCollection; + mutex_id db_lock; +} pcrf_context_t; + +CORE_DECLARE(status_t) pcrf_context_init(void); +CORE_DECLARE(status_t) pcrf_context_final(void); +CORE_DECLARE(pcrf_context_t*) pcrf_self(void); + +CORE_DECLARE(status_t) pcrf_context_parse_config(void); +CORE_DECLARE(status_t) pcrf_context_setup_trace_module(void); + +CORE_DECLARE(status_t) pcrf_db_init(void); +CORE_DECLARE(status_t) pcrf_db_final(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __PCRF_CONTEXT_H__ */ diff --git a/src/pcrf/pcrf_gx_handler.c b/src/pcrf/pcrf_gx_handler.c new file mode 100644 index 0000000000..244fa7edb0 --- /dev/null +++ b/src/pcrf/pcrf_gx_handler.c @@ -0,0 +1,69 @@ +#define TRACE_MODULE _pcrf_gx_handler + +#include "core_debug.h" + +#include "fd_lib.h" +#include "gx_lib.h" + +#include "pcrf_context.h" + +/* handler for fallback cb */ +static struct disp_hdl *hdl_fb = NULL; +/* handler for Credit-Control-Request cb */ +static struct disp_hdl *hdl_ccr = NULL; + +/* Default callback for the application. */ +static int pcrf_fb_cb(struct msg **msg, struct avp *avp, + struct session *sess, void *opaque, enum disp_action *act) +{ + /* This CB should never be called */ + d_warn("Unexpected message received!"); + + return ENOTSUP; +} + +/* Callback for incoming Credit-Control-Request messages */ +static int pcrf_ccr_cb( struct msg **msg, struct avp *avp, + struct session *sess, void *opaque, enum disp_action *act) +{ + return 0; +} + +int pcrf_gx_init(void) +{ + struct disp_when data; + + CHECK_FCT( fd_init(FD_MODE_SERVER, pcrf_self()->fd_conf_path) ); + + /* Install objects definitions for this application */ + CHECK_FCT( gx_dict_init() ); + + memset(&data, 0, sizeof(data)); + data.app = gx_application; + + /* fallback CB if command != unexpected message received */ + CHECK_FCT( fd_disp_register(pcrf_fb_cb, DISP_HOW_APPID, &data, NULL, + &hdl_fb) ); + + /* specific handler for Credit-Control-Request */ + data.command = gx_cmd_ccr; + CHECK_FCT( fd_disp_register(pcrf_ccr_cb, DISP_HOW_CC, &data, NULL, + &hdl_ccr) ); + + /* Advertise the support for the application in the peer */ + CHECK_FCT( fd_disp_app_support(gx_application, fd_vendor, 1, 0) ); + + return 0; +} + +void pcrf_gx_final(void) +{ + if (hdl_fb) { + (void) fd_disp_unregister(&hdl_fb, NULL); + } + if (hdl_ccr) { + (void) fd_disp_unregister(&hdl_ccr, NULL); + } + + fd_final(); +} diff --git a/src/pcrf/pcrf_gx_handler.h b/src/pcrf/pcrf_gx_handler.h new file mode 100644 index 0000000000..898b2b6db0 --- /dev/null +++ b/src/pcrf/pcrf_gx_handler.h @@ -0,0 +1,18 @@ +#ifndef __PCRF_GX_HANDLER_H__ +#define __PCRF_GX_HANDLER_H__ + +#include "core_errno.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +CORE_DECLARE(int) pcrf_gx_init(void); +CORE_DECLARE(void) pcrf_gx_final(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __PCRF_GX_HANDLER_H__ */ + diff --git a/src/pcrf/pcrf_init.c b/src/pcrf/pcrf_init.c new file mode 100644 index 0000000000..d0781c4c8d --- /dev/null +++ b/src/pcrf/pcrf_init.c @@ -0,0 +1,43 @@ +#define TRACE_MODULE _pcrf_init + +#include "pcrf_context.h" +#include "pcrf_gx_handler.h" + +static int initialized = 0; + +status_t pcrf_initialize(void) +{ + status_t rv; + int ret; + + rv = pcrf_context_init(); + if (rv != CORE_OK) return rv; + + rv = pcrf_context_parse_config(); + if (rv != CORE_OK) return rv; + + rv = pcrf_context_setup_trace_module(); + if (rv != CORE_OK) return rv; + + rv = pcrf_db_init(); + if (rv != CORE_OK) return rv; + + ret = pcrf_gx_init(); + if (ret != CORE_OK) return CORE_ERROR; + + initialized = 1; + + return CORE_OK; +} + +void pcrf_terminate(void) +{ + if (!initialized) return; + + pcrf_gx_final(); + + pcrf_db_final(); + pcrf_context_final(); + + return; +} diff --git a/src/pgw/Makefile.am b/src/pgw/Makefile.am index 65021bd198..a7b89c3023 100644 --- a/src/pgw/Makefile.am +++ b/src/pgw/Makefile.am @@ -5,9 +5,7 @@ noinst_LTLIBRARIES = libpgw.la libpgw_la_SOURCES = \ pgw_event.h pgw_context.h pgw_sm.h \ pgw_gtp_path.h pgw_s5c_handler.h \ - pgw_gx_handler.h - -nodist_libpgw_la_SOURCES = \ + pgw_gx_handler.h \ pgw_init.c pgw_event.c pgw_context.c pgw_sm.c \ pgw_gtp_path.c pgw_s5c_handler.c \ pgw_gx_handler.c @@ -36,5 +34,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES) diff --git a/src/sgw/Makefile.am b/src/sgw/Makefile.am index 8cae3cd061..86b5ab5da7 100644 --- a/src/sgw/Makefile.am +++ b/src/sgw/Makefile.am @@ -4,9 +4,7 @@ noinst_LTLIBRARIES = libsgw.la libsgw_la_SOURCES = \ sgw_event.h sgw_context.h \ - sgw_path.h sgw_sm.h sgw_handler.h - -nodist_libsgw_la_SOURCES = \ + sgw_path.h sgw_sm.h sgw_handler.h \ sgw_init.c sgw_event.c sgw_context.c \ sgw_path.c sgw_sm.c sgw_handler.c @@ -28,5 +26,3 @@ AM_CFLAGS = \ MAINTAINERCLEANFILES = Makefile.in MOSTLYCLEANFILES = core *.stackdump - -EXTRA_DIST = .libs $(noinst_LTLIBRARIES)