diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index b30d60013687d402b699e778da9966077e2a669c..058eeb48723e7da09462db323f797ef808d62ca0 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -205,7 +205,7 @@ endif (${RTAI})
 # (so creating new asn.1 objects instead of modifying the object attributes)
 # New C code source file, cmake must be re-run (instead of re-running make only) 
 #############
-set(asn1c_call "${OPENAIR_CMAKE}/tools/generate_asn1.bash")
+set(asn1c_call "${OPENAIR_CMAKE}/tools/generate_asn1")
 set(asn1_generated_dir ${OPENAIR_BIN_DIR})
 
 # RRC
@@ -325,7 +325,7 @@ add_list1_option(NB_ANTENNAS_RX "2" "Number of antennas in reception" "1" "2" "4
 add_list1_option(NB_ANTENNAS_TX "2" "Number of antennas in transmission" "1" "2" "4")
 add_list1_option(NB_ANTENNAS_TXRX "2" "Number of antennas in ????" "1" "2" "4")
 
-add_list2_option(RF_BOARD "EXMIMO" "RF head type" "False" "EXMIMO" "USRP" "ETHERNET" "CPRIGW")
+add_list2_option(RF_BOARD "EXMIMO" "RF head type" "False" "EXMIMO" "OAI_USRP" "ETHERNET" "CPRIGW")
 
 if (${RF_BOARD} STREQUAL "EXMIMO")
   set(DRIVER2013)
@@ -335,7 +335,7 @@ if (${RF_BOARD} STREQUAL "EXMIMO")
     ${OPENAIR_TARGETS}/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c 
     ${OPENAIR_TARGETS}/ARCH/EXMIMO/USERSPACE/LIB/gain_control.c)   
 
-elseif (${RF_BOARD} STREQUAL "USRP")
+elseif (${RF_BOARD} STREQUAL "OAI_USRP")
   include_directories("${OPENAIR_TARGETS}/ARCH/USRP/USERSPACE/LIB/")
   include_directories("/opt/include/uhd")
   set(HW_SOURCE ${HW_SOURCE}
@@ -376,7 +376,6 @@ add_boolean_option(ENABLE_USE_NETFILTER_FOR_SGI False "SGI option")
 add_boolean_option(ENABLE_USE_PCAP_FOR_SGI False "SGI option")
 add_boolean_option(ENABLE_USE_RAW_SOCKET_FOR_SGI False "As per name")
 add_boolean_option(EPC_BUILD False "???")
-add_boolean_option(LINK_PDCP_TO_GTPV1U True "????")
 add_boolean_option(LOWLATENCY  True "Use the Linux scheduler SCHED_DEADLINE: kernel >= 3.14")
 add_boolean_option(NAS_ADDRESS_FIX False "specific to oaisim: for nasmesh driver")
 add_boolean_option(NAS_NETLINK False "???? Must be True to compile nasmesh driver without rtai")
@@ -385,6 +384,7 @@ add_boolean_option(OAI_NW_DRIVER_USE_NETLINK True "????")
 add_boolean_option(UE_BUILD False "????")
 add_boolean_option(USE_MME False "this flag is used only one time in lte-softmodem.c")
 add_list_string_option(PACKAGE_NAME "NotDefined" "As per attribute name")
+add_boolean_option(MESSAGE_CHART_GENERATOR False "For generating sequence diagrams")
 
 ########################
 # Include order
@@ -608,6 +608,11 @@ add_library(HASHTABLE
 )
 include_directories(${OPENAIRCN_DIR}/UTILS/HASHTABLE)
 
+add_library(MSC
+  ${OPENAIR_DIR}/common/utils/msc/msc.c
+)
+include_directories(${OPENAIR_DIR}/common/utils/msc)
+
 set(UTIL_SRC 
   ${OPENAIR2_DIR}/UTIL/CLI/cli.c
   ${OPENAIR2_DIR}/UTIL/CLI/cli_cmd.c
@@ -818,7 +823,7 @@ set(L2_SRC
   ${RRC_DIR}/rrc_UE.c
   ${RRC_DIR}/rrc_eNB.c
   ${RRC_DIR}/rrc_eNB_S1AP.c
-  #${RRC_DIR}/rrc_eNB_UE_context.c
+  ${RRC_DIR}/rrc_eNB_UE_context.c
   ${RRC_DIR}/rrc_common.c
   ${RRC_DIR}/L2_interface.c
   )
@@ -1395,10 +1400,10 @@ pkg_search_module(CRYPTO libcrypto REQUIRED)
 include_directories(${CRYPTO_INCLUDE_DIRS})
 
 #use native cmake method as this package is not in pkg-config
-if (${RF_BOARD} STREQUAL "USRP")
+if (${RF_BOARD} STREQUAL "OAI_USRP")
   find_package(Boost REQUIRED)
   include_directories(${LIBBOOST_INCLUDE_DIR})
-endif (${RF_BOARD} STREQUAL "USRP")
+endif (${RF_BOARD} STREQUAL "OAI_USRP")
 
 pkg_search_module(OPENPGM openpgm-5.1)
 if(NOT ${OPENPGM_FOUND})
@@ -1440,6 +1445,9 @@ if (${XFORMS})
   set(XFORMS_LIBRARIES "forms")
 endif (${XFORMS})
 
+set(CMAKE_MODULE_PATH "${OPENAIR_DIR}/cmake_targets/tools/MODULES" "${CMAKE_MODULE_PATH}")
+
+
 # Hack on a test of asn1c version (already dirty)
 add_definitions(-DASN1_MINIMUM_VERSION=924)
 
@@ -1470,7 +1478,7 @@ add_executable(lte-softmodem
   )
 target_link_libraries (lte-softmodem 
   -Wl,--start-group 
-  RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS L2 ${RAL_LIB} ${NAS_LIB} ${ITTI_LIB} ${MIH_LIB}
+  RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS L2 MSC ${RAL_LIB} ${NAS_LIB} ${ITTI_LIB} ${MIH_LIB}
   -Wl,--end-group )
 target_link_libraries (lte-softmodem ${LIBXML2_LIBRARIES})
 target_link_libraries (lte-softmodem pthread m ${CONFIG_LIBRARIES} rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} sctp ${option_HW_lib} ${XFORMS_LIBRARIES} )
@@ -1488,32 +1496,82 @@ add_executable(mme_gw
   )
 target_link_libraries (mme_gw
   -Wl,--start-group 
-   NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA SGI S6A SGW MME_APP LFDS ${ITTI_LIB} CN_UTILS HASHTABLE
+   NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA SGI S6A SGW MME_APP LFDS MSC ${ITTI_LIB} CN_UTILS HASHTABLE
   -Wl,--end-group 
   pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
   )
 
 # Default parameters
-site_name(SITE_HSS_HOSTNAME)
-site_name(SITE_MME_HOSTNAME)
-add_option(MME_HOSTNAME      ${SITE_MME_HOSTNAME} "HSS Fully qualified domain name")
-add_option(HSS_HOSTNAME      ${SITE_HSS_HOSTNAME} "HSS Fully qualified domain name")
-add_option(HSS_IP            127.0.1.1            "HSS IP address, default is local")
-add_option(REALM             openair4G.eur     "Realm TODO: extract this default value from SITE_MME_FQDN")
-add_option(MME_FQDN          ${SITE_MME_HOSTNAME}.${REALM} "MME Fully qualified domain name")
-add_option(HSS_FQDN          ${SITE_HSS_HOSTNAME}.${REALM} "HSS Fully qualified domain name")
-add_option(TRANSPORT_option  No_SCTP     "No_TCP or No_SCTP")
-add_option(TRANSPORT_PREFER_TCP_option  Prefer_TCP "Prefer_TCP or null string ")
-
-configure_file(
-  ${OPENAIR_CMAKE}/tools/s6a.conf.in 
-  ${CMAKE_CURRENT_BINARY_DIR}/epc_s6a.conf)
-configure_file(
-  ${OPENAIR_CMAKE}/tools/epc.local.enb.conf.in 
-  ${CMAKE_CURRENT_BINARY_DIR}/epc.local.enb.conf)
-configure_file(
-  ${OPENAIR_CMAKE}/tools/epc.conf.in 
-  ${CMAKE_CURRENT_BINARY_DIR}/epc.conf)
+# Does not work on simple install (fqdn in /etc/hosts 127.0.1.1)
+#cmake_host_system_information(RESULT HSS_FQDN_STR QUERY FQDN)
+#cmake_host_system_information(RESULT MME_FQDN_STR QUERY FQDN)
+IF( EPC_BUILD )
+  INCLUDE(FindFreeDiameter)
+  # if standalone eNB or UE no need for FreeDiameter
+  IF( FREEDIAMETER_FOUND )
+    IF( NOT FREEDIAMETER_HSS_S6A_ENABLED )
+      MESSAGE( SEND_ERROR "FreeDiameter is not enabled for OPENAIRHSS" )
+    ENDIF( NOT FREEDIAMETER_HSS_S6A_ENABLED )
+  ENDIF( FREEDIAMETER_FOUND )
+
+
+  execute_process(COMMAND hostname --fqdn OUTPUT_VARIABLE HSS_FQDN_STR TIMEOUT 3)
+  execute_process(COMMAND hostname --fqdn OUTPUT_VARIABLE MME_FQDN_STR TIMEOUT 3)
+  string(STRIP ${HSS_FQDN_STR} HSS_FQDN_STR)
+  string(STRIP ${MME_FQDN_STR} MME_FQDN_STR)
+
+  set(HSS_IP                       127.0.1.1                 CACHE STRING     "HSS IP address, default is local")
+  set(MME_FQDN                     ${MME_FQDN_STR}           CACHE STRING     "MME Fully qualified domain name")
+  set(HSS_FQDN                     ${HSS_FQDN_STR}           CACHE STRING     "HSS Fully qualified domain name")
+  set(TRANSPORT_option             "#No_TCP"                 CACHE STRING     "No_TCP or No_SCTP or comment string, FreeDiameter config option")
+  set(TRANSPORT_PREFER_TCP_option  "#Prefer_TCP"             CACHE STRING     "Prefer_TCP or comment string, FreeDiameter config option")
+  IF( NOT DEFINED REALM )
+    string(FIND ${MME_FQDN} "." pos)
+    math(EXPR pos1 "${pos}+1")
+    string(SUBSTRING ${MME_FQDN} ${pos1} -1 realm_string)
+    message("REALM extracted from MME FQDN is ${realm_string}")
+    set(REALM                      ${realm_string}           CACHE STRING     "EPC realm")
+  ENDIF( NOT DEFINED REALM )
+  message("REALM is ${REALM}")
+  IF( NOT DEFINED MME_HOSTNAME )
+    string(FIND ${MME_FQDN} "." pos)
+    string(SUBSTRING ${MME_FQDN} 0 ${pos} mme_hostname_string)
+    message("MME_HOSTNAME extracted from MME FQDN is ${mme_hostname_string}")
+    set(MME_HOSTNAME         ${mme_hostname_string}           CACHE STRING     "MME hostname")
+  ENDIF( NOT DEFINED MME_HOSTNAME )
+  IF( NOT DEFINED HSS_HOSTNAME )
+    string(FIND ${HSS_FQDN} "." pos)
+    string(SUBSTRING ${HSS_FQDN} 0 ${pos} hss_hostname_string)
+    message("HSS_HOSTNAME extracted from HSS FQDN is ${hss_hostname_string}")
+    set(HSS_HOSTNAME         ${hss_hostname_string}           CACHE STRING     "HSS hostname")
+  ENDIF( NOT DEFINED HSS_HOSTNAME )
+
+  if ( ${MME_HOSTNAME} STREQUAL ${HSS_HOSTNAME} )
+    set(MME_S6A_IS_SERVER      1 )
+  endif( ${MME_HOSTNAME} STREQUAL ${HSS_HOSTNAME} )
+
+  IF( MME_S6A_IS_SERVER )
+    set(ConnectPeer        "#ConnectPeer"     CACHE STRING   "HSS connect to MME")
+    set(DIAMETER_PORT      "Port = 3870"      CACHE STRING   "Diameter bind port, 3868 is always used by default by HSS, even if HSS client")
+    set(DIAMETER_SEC_PORT  "SecPort = 3871"   CACHE STRING   "Diameter bind sec port")
+  ELSE( MME_S6A_IS_SERVER )
+    set(ConnectPeer        "#ConnectPeer"     CACHE STRING   "HSS act as a server")
+    set(DIAMETER_PORT      "#Port = 3870"     CACHE STRING   "Diameter bind port")
+    set(DIAMETER_SEC_PORT  "#SecPort = 3871"  CACHE STRING   "Diameter bind sec port")
+  ENDIF( MME_S6A_IS_SERVER )
+
+  execute_process(COMMAND sudo ${OPENAIR_CMAKE}/tools/check_mme_s6a_certificate ${FREEDIAMETER_PATH}/.. ${MME_FQDN} WORKING_DIRECTORY ${OPENAIR_CMAKE})
+
+  configure_file(
+    ${OPENAIR_CMAKE}/tools/s6a.conf.in 
+    ${CMAKE_CURRENT_BINARY_DIR}/mme_fd.conf)
+  configure_file(
+    ${OPENAIR_CMAKE}/tools/epc.local.enb.conf.in 
+    ${CMAKE_CURRENT_BINARY_DIR}/epc.local.enb.conf)
+  configure_file(
+    ${OPENAIR_CMAKE}/tools/epc.conf.in 
+    ${CMAKE_CURRENT_BINARY_DIR}/epc.conf)
+ENDIF( EPC_BUILD )
 
 # oai_sgw is SGW  node implementation
 ################################
@@ -1524,7 +1582,7 @@ add_executable(oai_sgw
   )
 target_link_libraries (oai_sgw
   -Wl,--start-group 
-  GTPV1U SECU_CN SECU_OSA SGI S6A SGW CN_UTILS LFDS ${ITTI_LIB}
+  GTPV1U SECU_CN SECU_OSA SGI S6A SGW CN_UTILS LFDS MSC ${ITTI_LIB}
   -Wl,--end-group  
   pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
   )
@@ -1572,7 +1630,7 @@ add_executable(oaisim
 target_include_directories(oaisim PUBLIC  ${OPENAIR_TARGETS}/SIMU/USER)
 target_link_libraries (oaisim
   -Wl,--start-group 
-  RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS L2 ${RAL_LIB} ${NAS_LIB} SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
+  RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS L2 MSC ${RAL_LIB} ${NAS_LIB} SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
   -Wl,--end-group )
 target_link_libraries (oaisim ${LIBXML2_LIBRARIES} ${LAPACK_LIBRARIES})
 target_link_libraries (oaisim pthread m ${CONFIG_LIBRARIES} rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES}  ${NETTLE_LIBRARIES} sctp ${option_HW_lib} 
@@ -1631,7 +1689,7 @@ add_executable(oaisim_mme
 )
 target_link_libraries (oaisim_mme
   -Wl,--start-group 
-   NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA SGI S6A S11 SGW MME_APP LFDS ${ITTI_LIB} CN_UTILS HASHTABLE
+   NAS S1AP_LIB S1AP_EPC GTPV1U GTPV2C SCTP_SERVER UDP_SERVER SECU_CN SECU_OSA SGI S6A S11 SGW MME_APP LFDS MSC ${ITTI_LIB} CN_UTILS HASHTABLE
   -Wl,--end-group 
   pthread m sctp  rt crypt ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${NETTLE_LIBRARIES} ${CONFIG_LIBRARIES} fdproto fdcore
 )
diff --git a/cmake_targets/epc_build_oai/CMakeLists.template b/cmake_targets/epc_build_oai/CMakeLists.template
index 6f6316bfec66f204a5c7d044011fa2e8546735cc..e4596c44c16c6c5d6fb32ac1e2df8202cf303589 100644
--- a/cmake_targets/epc_build_oai/CMakeLists.template
+++ b/cmake_targets/epc_build_oai/CMakeLists.template
@@ -3,7 +3,9 @@ cmake_minimum_required(VERSION 2.8)
 set (  CMAKE_BUILD_TYPE "RelWithDebInfo" )
 set (  ADDR_CONF False )
 set (  ASSERT False )
+set (  BYTE_ORDER=LITTLE_ENDIAN )
 set (  DEBUG_OMG False )
+set (  DISABLE_ITTI_DETECT_SUB_TASK_ID True )
 set (  DISABLE_XER_PRINT False )
 set (  DRIVER2013 False )
 set (  EMOS False )
@@ -39,6 +41,7 @@ set (  MSG_PRINT False )
 set (  MU_RECEIVER False )
 set (  NAS_ADDRESS_FIX False )
 set (  NAS_BUILT_IN_EPC True )
+set (  NAS_DEBUG True )
 set (  NAS_MME True )
 set (  NAS_NETLINK False )
 set (  NAS_UE False )
diff --git a/cmake_targets/hss_build/CMakeLists.txt b/cmake_targets/hss_build/CMakeLists.txt
index 56626ad54e206f2d0fa9b12e20005739436d9387..bae1cad0478c0a0b8c03f9c20124b6e158a76c47 100755
--- a/cmake_targets/hss_build/CMakeLists.txt
+++ b/cmake_targets/hss_build/CMakeLists.txt
@@ -38,7 +38,10 @@ ENABLE_LANGUAGE(C)
 
 ADD_DEFINITIONS(-D_GNU_SOURCE)
 
-set(OPENAIR_DIR           $ENV{OPENAIR_DIR})
+if( NOT DEFINED OPENAIR_DIR)
+  message(SEND_ERROR "OPENAIR_DIR not set: ${OPENAIR_DIR}")
+endif( NOT DEFINED OPENAIR_DIR)
+
 set(OPENAIR1_DIR          ${OPENAIR_DIR}/openair1)
 set(OPENAIR2_DIR          ${OPENAIR_DIR}/openair2)
 set(OPENAIR3_DIR          ${OPENAIR_DIR}/openair3)
@@ -49,8 +52,7 @@ set(OPENAIRHSS_DIR        ${OPENAIRCN_DIR}/OPENAIRHSS)
 set(OPENAIR_BIN_DIR       ${OPENAIR_TARGETS}/bin)
 
 
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OPENAIR_CMAKE_SCRIPTS}/MODULES")
-include(cmake_useful)
+set(CMAKE_MODULE_PATH "${OPENAIR_DIR}/cmake_targets/tools/MODULES" "${CMAKE_MODULE_PATH}")
 
 macro(add_option name val helpstr)
   if(DEFINED ${name})
@@ -265,46 +267,60 @@ target_link_libraries (openair-hss
                        ${CMAKE_THREAD_LIBS_INIT} )
 
 # Default parameters
-site_name(SITE_HSS_FQDN)
+# Does not work on simple install (fqdn in /etc/hosts 127.0.1.1)
+cmake_host_system_information(RESULT SITE_HSS_FQDN QUERY FQDN)
 add_option(HSS_FQDN          ${SITE_HSS_FQDN} "HSS Fully qualified domain name")
-add_option(REALM             openair4G.eur    "HSS realm TODO: extract this default value from SITE_HSS_FQDN")
-add_option(MYSQL_server      "127.0.0.1"      "Database server IP address")
-add_option(MYSQL_admin       "root"           "Database admin login")
-add_option(MYSQL_admin_pass  "linux"          "Database admin password")
-add_option(MYSQL_user        "hssadmin"       "Database username login")
-add_option(MYSQL_pass        "admin"          "Database username password")
-add_option(MYSQL_db          "oai_db"         "Database name")
-add_option(TRANSPORT_option  "#No_TCP"        "No_TCP or No_SCTP or comment string, FreeDiameter config option")
-add_option(TRANSPORT_PREFER_TCP_option  "#Prefer_TCP"   "Prefer_TCP or comment string, FreeDiameter config option")
-add_option(AppServThreads    2                "FreeDiameter AppServThreads config option")
-add_option(OPERATOR_key      "11111111111111111111111111111111" "LTE operator clear text key (hex bytes)")
-add_option(REMOTE_PEER_WHITELIST "*.${REALM}" "Remote peer whitlist (separeted by spaces), for freediameter acl.conf config file")
+IF( NOT DEFINED REALM )
+  string(FIND ${HSS_FQDN} "." pos)
+  math(EXPR pos1 "${pos}+1")
+  string(SUBSTRING ${HSS_FQDN} ${pos1} -1 realm_string)
+  message("REALM extracted from HSS FQDN is ${realm_string}")
+  set(REALM             ${realm_string}    CACHE STRING  "HSS realm")
+ENDIF( NOT DEFINED REALM )
+set(MYSQL_server      "127.0.0.1"      CACHE STRING  "Database server IP address")
+set(MYSQL_admin       root             CACHE STRING  "Database admin login")
+set(MYSQL_admin_pass  linux            CACHE STRING  "Database admin password")
+set(MYSQL_user        hssadmin         CACHE STRING  "Database username login")
+set(MYSQL_pass        admin            CACHE STRING  "Database username password")
+set(MYSQL_db          oai_db           CACHE STRING  "Database name")
+set(TRANSPORT_option  "#No_TCP"        CACHE STRING  "No_TCP or No_SCTP or comment string, FreeDiameter config option")
+set(TRANSPORT_PREFER_TCP_option  "#Prefer_TCP"   CACHE STRING  "Prefer_TCP or comment string, FreeDiameter config option")
+set(AppServThreads    2                CACHE STRING  "FreeDiameter AppServThreads config option")
+set(OPERATOR_key      "11111111111111111111111111111111" CACHE STRING  "LTE operator clear text key (hex bytes)")
+set(REMOTE_PEER_WHITELIST "*.${REALM}" CACHE STRING  "Remote peer whitelist (separated by spaces), for freediameter acl.conf config file")
 IF( FD_SERVER_IP_BIND_LIST )
-    set(ListenOn          "ListenOn=\"${FD_SERVER_IP_BIND_LIST}\"" "//FreeDiameter server IP bind addresses list")
+    set(ListenOn          "ListenOn = \"${FD_SERVER_IP_BIND_LIST}\"" CACHE STRING  "FreeDiameter server IP bind addresses list")
 ELSE( FD_SERVER_IP_BIND_LIST )
-    set(ListenOn          "#ListenOn=\"\"" "//FreeDiameter server IP bind addresses list")
+    set(ListenOn          "#ListenOn = \"\"" CACHE STRING  "FreeDiameter server IP bind addresses list")
 ENDIF( FD_SERVER_IP_BIND_LIST )
 
 IF( HSS_CONNECT_TO_MME )
-  add_option(ConnectPeer        "ConnectPeer"     "HSS connect to MME")
-  add_option(DIAMETER_PORT      "#Port = 3868"    "Diameter bind port")
-  add_option(DIAMETER_SEC_PORT  "#SecPort = 3869"    "Diameter bind sec port")
+  set(ConnectPeer        "ConnectPeer"     CACHE STRING  "HSS connect to MME")
+  set(DIAMETER_PORT      "#Port = 3868"    CACHE STRING  "Diameter bind port")
+  set(DIAMETER_SEC_PORT  "#SecPort = 3869" CACHE STRING  "Diameter bind sec port")
 ELSE( HSS_CONNECT_TO_MME )
-  add_option(ConnectPeer        "#ConnectPeer"    "HSS act as a server")
-  add_option(DIAMETER_PORT      "Port = 3868"     "Diameter bind port")
-  add_option(DIAMETER_SEC_PORT  "SecPort = 3869"     "Diameter bind sec port")
+  set(ConnectPeer        "#ConnectPeer"    CACHE STRING  "HSS act as a server")
+  set(DIAMETER_PORT      "Port = 3868"     CACHE STRING  "Diameter bind port")
+  set(DIAMETER_SEC_PORT  "SecPort = 3869"  CACHE STRING  "Diameter bind sec port")
 ENDIF( HSS_CONNECT_TO_MME )
-configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/hss_fd.conf.in  
-  ${CMAKE_CURRENT_BINARY_DIR}/hss_fd.conf)
-configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/hss.conf.in  
-  ${CMAKE_CURRENT_BINARY_DIR}/hss.conf)
-configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/acl.conf.in  
-  ${CMAKE_CURRENT_BINARY_DIR}/acl.conf)
-                
 
-install (TARGETS openair-hss 
-  DESTINATION ${OPENAIR_TARGETS}/bin)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hss_fd.conf.in ${CMAKE_CURRENT_BINARY_DIR}/hss_fd.conf)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hss.conf.in    ${CMAKE_CURRENT_BINARY_DIR}/hss.conf)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/acl.conf.in    ${CMAKE_CURRENT_BINARY_DIR}/acl.conf)
+
+execute_process(COMMAND sudo ${OPENAIR_CMAKE_SCRIPTS}/check_hss_s6a_certificate ${FREEDIAMETER_PATH}/.. ${HSS_FQDN} WORKING_DIRECTORY ${OPENAIR_CMAKE_SCRIPTS} TIMEOUT 3)
+
+# This does not overwrite database if it exist
+execute_process(COMMAND ${OPENAIR_CMAKE_SCRIPTS}/create_hss_database
+                ${MYSQL_admin} ${MYSQL_admin_pass} ${MYSQL_user} ${MYSQL_pass} ${MYSQL_db}
+                 WORKING_DIRECTORY ${OPENAIR_CMAKE_SCRIPTS} 
+                 ERROR_VARIABLE ERROR_DB
+                 TIMEOUT 5)
+
+IF( ERROR_DB )
+  MESSAGE( SEND_ERROR "Database setup failed: ${ERROR_DB}" )
+ENDIF( ERROR_DB )
+                
+install (TARGETS openair-hss DESTINATION ${OPENAIR_TARGETS}/bin)
 
diff --git a/cmake_targets/hss_build/hss_fd.conf.in b/cmake_targets/hss_build/hss_fd.conf.in
index 43fc8f5e4b6f168961981852962bf636e743710d..5d59919c35f2ca5f3addd8e28c277826e1545c0a 100644
--- a/cmake_targets/hss_build/hss_fd.conf.in
+++ b/cmake_targets/hss_build/hss_fd.conf.in
@@ -103,4 +103,4 @@ LoadExtension = "dict_s6a.fdx";
 # For only accepting incoming connections, see the acl_wl.fx extension.
 
 #ConnectPeer = "ubuntu.localdomain" { ConnectTo = "127.0.0.1"; No_TLS; };
-@ConnectPeer@ = "@MME_FQDN@"  { ConnectTo = "@MME_IP@"; No_IPv6; No_TLS ; port = 3870; };
\ No newline at end of file
+@ConnectPeer@ = "@MME_FQDN@"  { ConnectTo = "@MME_IP@"; Realm = "@REALM@"; No_IPv6; No_TLS ; port = 3870; };
\ No newline at end of file
diff --git a/cmake_targets/tools/MODULES/FindFreeDiameter.cmake b/cmake_targets/tools/MODULES/FindFreeDiameter.cmake
index 6351ff2ce36fe054a9ff9bacc538379f9b56d654..62517c052870baa0680a8dfe285d1d3856b1e6fa 100644
--- a/cmake_targets/tools/MODULES/FindFreeDiameter.cmake
+++ b/cmake_targets/tools/MODULES/FindFreeDiameter.cmake
@@ -67,6 +67,7 @@ IF(FREEDIAMETER_FOUND)
       MESSAGE(STATUS "freeDiameter version found ${FREEDIAMETER_VERSION}")
     ENDIF(FD_PROJECT_VERSION_MAJOR GREATER 0)
   ENDIF( FREEDIAMETER_INCLUDE_DIR )
+  GET_FILENAME_COMPONENT(FREEDIAMETER_PATH ${FREEDIAMETER_LIBRARY} PATH)
   IF( NOT( "${FREEDIAMETER_VERSION_TEST_FOR}" STREQUAL "${FREEDIAMETER_LIBRARIES}" ))
     INCLUDE (CheckLibraryExists) 
     MESSAGE(STATUS "Checking freeDiameter patched for S6A")
@@ -75,7 +76,7 @@ IF(FREEDIAMETER_FOUND)
     UNSET(DICT_S6A_FOUND)
     UNSET(DICT_S6A_FOUND CACHE)
 
-    GET_FILENAME_COMPONENT(FREEDIAMETER_PATH ${FREEDIAMETER_LIBRARY} PATH)
+
     FIND_FILE(DICT_S6A_FOUND NAMES dict_s6a.fdx PATHS ${FREEDIAMETER_PATH} ${FREEDIAMETER_PATH}/freeDiameter)
     IF(DICT_S6A_FOUND)
         SET( FREEDIAMETER_HSS_S6A_ENABLED TRUE CACHE INTERNAL "dict_s6a.fdx Found")
diff --git a/cmake_targets/tools/build_epc b/cmake_targets/tools/build_epc
index 45b6bbf0e3e78ff04556125ed394e7a0561e2cb9..5eb6b3ee960db9d74ad16c678d94a0235fd17db0 100755
--- a/cmake_targets/tools/build_epc
+++ b/cmake_targets/tools/build_epc
@@ -207,16 +207,16 @@ function main()
       echo "Cleaning EPC"
     fi
     rm -Rf build 2>&1
-    rm -Rf $OPENAIR_TARGETS/CMAKE/EPC/MME_GW/build  2>&1
-    rm -f /usr/local/etc/freeDiameter/mme*    2>&1
-    rm -f /usr/local/etc/freeDiameter/epc*    2>&1
-    rm -f /usr/etc/freeDiameter/mme*    2>&1
-    rm -f /usr/etc/freeDiameter/epc*    2>&1
-    rm -f $OPENAIR_DIR/targets/bin/xt_GTPU*.ko    2>&1
-    (cd $OPENAIRCN_DIR/GTPV1-U/GTPUAH && make clean)
-    (cd $OPENAIRCN_DIR/GTPV1-U/GTPURH && make clean)
-    rm -f $OPENAIRCN_DIR/GTPV1-U/GTPUAH/Bin/* 2>&1
-    rm -f /lib/xtables/libxt_GTPU*.so             2>&1
+    $SUDO rm -Rf $OPENAIR_TARGETS/CMAKE/EPC/MME_GW/build  2>&1
+    $SUDO rm -f /usr/local/etc/freeDiameter/mme*    2>&1
+    $SUDO rm -f /usr/local/etc/freeDiameter/epc*    2>&1
+    $SUDO rm -f /usr/etc/freeDiameter/mme*    2>&1
+    $SUDO rm -f /usr/etc/freeDiameter/epc*    2>&1
+    $SUDO rm -f $OPENAIR_DIR/targets/bin/xt_GTPU*.ko    2>&1
+    ($SUDO cd $OPENAIRCN_DIR/GTPV1-U/GTPUAH && make clean)
+    ($SUDO cd $OPENAIRCN_DIR/GTPV1-U/GTPURH && make clean)
+    $SUDO rm -f $OPENAIRCN_DIR/GTPV1-U/GTPUAH/Bin/* 2>&1
+    $SUDO rm -f /lib/xtables/libxt_GTPU*.so             2>&1
     mkdir -m 777 -p -v build
   fi
   
diff --git a/cmake_targets/tools/run_epc b/cmake_targets/tools/run_epc
index 720b57e920e5085babb4946ff7c6dc2e05a3602a..37e2df8282e631c4e78bdb5d1092b81bd673a842 100755
--- a/cmake_targets/tools/run_epc
+++ b/cmake_targets/tools/run_epc
@@ -113,7 +113,6 @@ function main()
     esac
   done
 
-  check_for_root_rights
   set_openair_env 
   cecho "OPENAIR_DIR    = $OPENAIR_DIR" $green
 
diff --git a/cmake_targets/tools/s6a.conf.in b/cmake_targets/tools/s6a.conf.in
index 000544ad7538d9544ffb18de0b792606b56214b3..6b357b71fc9214113b2adb9c3a74e4be90f012e2 100644
--- a/cmake_targets/tools/s6a.conf.in
+++ b/cmake_targets/tools/s6a.conf.in
@@ -5,9 +5,9 @@ Identity = "@MME_FQDN@";
 Realm = "@REALM@";
 
 # TLS configuration (see previous section)
-TLS_Cred = "${FREEDIAMETER_PATH}/../etc/freeDiameter/mme.cert.pem",
-           "${FREEDIAMETER_PATH}/../etc/freeDiameter/mme.key.pem";
-TLS_CA   = "${FREEDIAMETER_PATH}/../etc/freeDiameter/mme.cacert.pem";
+TLS_Cred = "@FREEDIAMETER_PATH@/../etc/freeDiameter/mme.cert.pem",
+           "@FREEDIAMETER_PATH@/../etc/freeDiameter/mme.key.pem";
+TLS_CA   = "@FREEDIAMETER_PATH@/../etc/freeDiameter/mme.cacert.pem";
 
 # Disable use of TCP protocol (only listen and connect in SCTP)
 # Default : TCP enabled