From 58b62709f3d47719427e9ff101d8e48880ff9dce Mon Sep 17 00:00:00 2001
From: Lionel Gauthier <lionel.gauthier@eurecom.fr>
Date: Tue, 14 Jan 2014 09:54:15 +0000
Subject: [PATCH] Commit for updates to RAL (802.21, MIH)

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4867 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 common/utils/Makefile.inc              |   5 +-
 openair1/PHY/CODING/defs.h             |   5 +-
 openair1/PHY/defs.h                    |  22 +++
 openair1/SCHED/phy_procedures_lte_ue.c | 217 ++++++++++++++++++++++++-
 openair2/COMMON/phy_messages_def.h     |   7 +-
 openair2/COMMON/phy_messages_types.h   |  24 +--
 openair2/COMMON/ral_messages_def.h     |   4 +-
 openair2/COMMON/ral_messages_types.h   |  10 +-
 openair2/RRC/LITE/defs.h               |   1 +
 openair2/RRC/LITE/rrc_UE.c             | 146 ++++++++++++++++-
 openair2/RRC/LITE/rrc_UE_ral.c         |   1 +
 openair2/RRC/LITE/rrc_UE_ral.h         |   1 -
 openair2/RRC/LITE/rrc_eNB.c            |   1 +
 openair2/UTIL/LISTS/list.h             |   1 +
 openair2/UTIL/LISTS/list2.c            |   8 +
 targets/COMMON/create_tasks.c          |  16 ++
 targets/SIMU/USER/oaisim.c             |  34 ++--
 targets/SIMU/USER/oaisim_config.c      |  22 ++-
 targets/SIMU/USER/oaisim_functions.c   |  47 ++----
 targets/SIMU/USER/oaisim_functions.h   |   2 -
 targets/TEST/OAI/case01.py             |   2 +-
 21 files changed, 486 insertions(+), 90 deletions(-)

diff --git a/common/utils/Makefile.inc b/common/utils/Makefile.inc
index 606077c259..4701a6f542 100644
--- a/common/utils/Makefile.inc
+++ b/common/utils/Makefile.inc
@@ -13,9 +13,8 @@ HASHTABLE_DIR = $(COMMON_UTILS_DIR)/collection/hashtable
 HASHTABLE_OBJS =  $(HASHTABLE_DIR)/hashtable.o
 HASHTABLE_OBJS += $(HASHTABLE_DIR)/obj_hashtable.o
 
-
-UTILS_OBJS = $(ITTI_OBJS) $(HASHTABLE_OBJS)
+UTILS_OBJS = $(ITTI_OBJS) $(HASHTABLE_OBJS) 
 
 UTILS_incl = 				\
-	-I$(COMMON_UTILS_DIR) 	\
+    -I$(COMMON_UTILS_DIR)   \
 	-I$(ITTI_DIR)
diff --git a/openair1/PHY/CODING/defs.h b/openair1/PHY/CODING/defs.h
index 81acb24d28..1ddc73822e 100644
--- a/openair1/PHY/CODING/defs.h
+++ b/openair1/PHY/CODING/defs.h
@@ -373,12 +373,13 @@ run in segments with final trace back after last segment.
 @param traceback flag to indicate that traceback should be performed*/
 void phy_viterbi_dot11_sse2(int8_t *y,uint8_t *decoded_bytes,uint16_t n);
 
-/*!\fn void phy_viterbi_lte_sse2(int8_t *y, uint8_t *decoded_bytes, uint16_t n)
+/*!\fn void phy_viterbi_lte_sse2(s8 *y, u8 *decoded_bytes, u16 n)
 \brief This routine performs a SIMD optmized Viterbi decoder for the LTE 64-state tail-biting convolutional code.
 @param y Pointer to soft input (coded on 8-bits but should be limited to 4-bit precision to avoid overflow)
 @param decoded_bytes Pointer to decoded output
 @param n Length of input/trellis depth in bits*/
-void phy_viterbi_lte_sse2(int8_t *y,uint8_t *decoded_bytes,uint16_t n);
+//void phy_viterbi_lte_sse2(int8_t *y,uint8_t *decoded_bytes,uint16_t n);
+void phy_viterbi_lte_sse2(s8 *y,u8 *decoded_bytes,u16 n);
 
 /*!\fn void phy_generate_viterbi_tables(void)
 \brief This routine initializes metric tables for the optimized Viterbi decoder.
diff --git a/openair1/PHY/defs.h b/openair1/PHY/defs.h
index fc0cfdf34f..8761013248 100755
--- a/openair1/PHY/defs.h
+++ b/openair1/PHY/defs.h
@@ -51,6 +51,11 @@
 # define msg mexPrintf
 #else
 # ifdef OPENAIR2
+#   if defined(ENABLE_RAL)
+#     include "collection/hashtable/hashtable.h"
+#     include "COMMON/ral_messages_types.h"
+#     include "UTIL/queue.h"
+#   endif
 #   include "log.h"
 #   define msg(aRGS...) LOG_D(PHY, ##aRGS)
 # else
@@ -162,6 +167,16 @@ enum transmission_access_mode{
   CBA_ACCESS
 };
 
+#if defined(ENABLE_RAL)
+  typedef struct ral_threshold_phy_s {
+      SLIST_ENTRY(ral_threshold_phy_s) ral_thresholds;
+      ral_threshold_t                  threshold;
+      ral_th_action_t                  th_action;
+      ral_link_param_type_t            link_param_type;
+      long                             timer_id;
+  }ral_threshold_phy_t;
+#endif
+
 /// Top-level PHY Data Structure for eNB 
 typedef struct {
   /// Module ID indicator for this instance
@@ -320,6 +335,7 @@ typedef enum {
   max_gain=0,med_gain,byp_gain
 } rx_gain_t;
 
+
 /// Top-level PHY Data Structure for UE 
 typedef struct
 {
@@ -491,6 +507,12 @@ typedef struct
   time_stats_t dlsch_tc_ext_stats;
   time_stats_t dlsch_tc_intl1_stats;
   time_stats_t dlsch_tc_intl2_stats;
+
+#if defined(ENABLE_RAL)
+  hash_table_t    *ral_thresholds_timed;
+  SLIST_HEAD(ral_thresholds_gen_poll_s, ral_threshold_phy_t) ral_thresholds_gen_polled[RAL_LINK_PARAM_GEN_MAX];
+  SLIST_HEAD(ral_thresholds_lte_poll_s, ral_threshold_phy_t) ral_thresholds_lte_polled[RAL_LINK_PARAM_LTE_MAX];
+#endif
 } PHY_VARS_UE;
 
 /// Top-level PHY Data Structure for RN
diff --git a/openair1/SCHED/phy_procedures_lte_ue.c b/openair1/SCHED/phy_procedures_lte_ue.c
index 89f95a906a..8f0a94163b 100755
--- a/openair1/SCHED/phy_procedures_lte_ue.c
+++ b/openair1/SCHED/phy_procedures_lte_ue.c
@@ -85,6 +85,9 @@ fifo_dump_emos_UE emos_dump_UE;
 
 #if defined(ENABLE_ITTI)
 # include "intertask_interface.h"
+#   if defined(ENABLE_RAL)
+#     include "timer.h"
+#   endif
 #endif
 
 #ifndef OPENAIR2
@@ -3166,7 +3169,91 @@ int phy_procedures_RN_UE_RX(u8 last_slot, u8 next_slot, relaying_type_t r_type)
   }
   return do_proc;
 }
-#endif   
+#endif
+
+
+#if defined(ENABLE_ITTI)
+#   if defined(ENABLE_RAL)
+
+void phy_UE_lte_measurement_thresholds_test_and_report(instance_t instanceP, ral_threshold_phy_t* threshold_phy_pP, uint16_t valP) {
+    MessageDef *message_p = NULL;
+
+    if (
+       ((threshold_phy_pP->threshold.threshold_val >  valP) && (threshold_phy_pP->threshold.threshold_xdir == MIH_C_ABOVE_THRESHOLD)) ||
+       ((threshold_phy_pP->threshold.threshold_val <  valP) && (threshold_phy_pP->threshold.threshold_xdir == MIH_C_BELOW_THRESHOLD))
+       ) {
+        message_p = itti_alloc_new_message(TASK_PHY_UE , PHY_MEAS_REPORT_IND);
+        memset(&PHY_MEAS_REPORT_IND(message_p), 0, sizeof(PHY_MEAS_REPORT_IND(message_p)));
+
+        memcpy(&PHY_MEAS_REPORT_IND (message_p).threshold,
+                &threshold_phy_pP->threshold,
+                sizeof(PHY_MEAS_REPORT_IND (message_p).threshold));
+
+        memcpy(&PHY_MEAS_REPORT_IND (message_p).link_param_type,
+                &threshold_phy_pP->link_param_type,
+                sizeof(PHY_MEAS_REPORT_IND (message_p).link_param_type));
+        itti_send_msg_to_task(TASK_RRC_UE, instanceP, message_p);
+    }
+}
+
+void phy_UE_lte_check_measurement_thresholds(instance_t instanceP, ral_threshold_phy_t* threshold_phy_pP) {
+    switch (threshold_phy_pP->link_param_type.choice) {
+
+        case RAL_LINK_PARAM_TYPE_CHOICE_GEN:
+            switch (threshold_phy_pP->link_param_type._union.link_param_gen) {
+                case RAL_LINK_PARAM_GEN_DATA_RATE:
+                    phy_UE_lte_measurement_thresholds_test_and_report(instanceP, threshold_phy_pP, 0);
+                    break;
+                case RAL_LINK_PARAM_GEN_SIGNAL_STRENGTH:
+                    phy_UE_lte_measurement_thresholds_test_and_report(instanceP, threshold_phy_pP, 0);
+                    break;
+                case RAL_LINK_PARAM_GEN_SINR:
+                    phy_UE_lte_measurement_thresholds_test_and_report(instanceP, threshold_phy_pP, 0);
+                    break;
+                case RAL_LINK_PARAM_GEN_THROUGHPUT:
+                    break;
+                case RAL_LINK_PARAM_GEN_PACKET_ERROR_RATE:
+                    break;
+                default:;
+            }
+            break;
+
+        case RAL_LINK_PARAM_TYPE_CHOICE_LTE:
+            switch (threshold_phy_pP->link_param_type._union.link_param_gen) {
+                case RAL_LINK_PARAM_LTE_UE_RSRP:
+                    break;
+                case RAL_LINK_PARAM_LTE_UE_RSRQ:
+                    break;
+                case RAL_LINK_PARAM_LTE_UE_CQI:
+                    break;
+                case RAL_LINK_PARAM_LTE_AVAILABLE_BW:
+                    break;
+                case RAL_LINK_PARAM_LTE_PACKET_DELAY:
+                    break;
+                case RAL_LINK_PARAM_LTE_PACKET_LOSS_RATE:
+                    break;
+                case RAL_LINK_PARAM_LTE_L2_BUFFER_STATUS:
+                    break;
+                case RAL_LINK_PARAM_LTE_MOBILE_NODE_CAPABILITIES:
+                    break;
+                case RAL_LINK_PARAM_LTE_EMBMS_CAPABILITY:
+                    break;
+                case RAL_LINK_PARAM_LTE_JUMBO_FEASIBILITY:
+                    break;
+                case RAL_LINK_PARAM_LTE_JUMBO_SETUP_STATUS:
+                    break;
+                case RAL_LINK_PARAM_LTE_NUM_ACTIVE_EMBMS_RECEIVERS_PER_FLOW:
+                    break;
+                default:;
+            }
+            break;
+
+        default:;
+    }
+}
+#   endif
+#endif
+
  void phy_procedures_UE_lte(u8 last_slot, u8 next_slot, PHY_VARS_UE *phy_vars_ue,u8 eNB_id,u8 abstraction_flag,runmode_t mode, 
 			    relaying_type_t r_type, PHY_VARS_RN *phy_vars_rn) {
 #if defined(ENABLE_ITTI)
@@ -3211,10 +3298,136 @@ int phy_procedures_RN_UE_RX(u8 last_slot, u8 next_slot, relaying_type_t r_type)
 
       switch (ITTI_MSG_ID(msg_p)) {
         case PHY_FIND_CELL_REQ:
-          LOG_I(PHY, "[UE %d] Received %s from %s\n", Mod_id, msg_name);
+          LOG_I(PHY, "[UE %d] Received %s\n", Mod_id, msg_name);
 
           /* TODO process the message */
+#   if defined(ENABLE_RAL)
+          {
+              MessageDef *message_p;
+
+              message_p = itti_alloc_new_message(TASK_PHY_UE , PHY_FIND_CELL_IND);
+              memset(&PHY_FIND_CELL_IND(message_p), 0, sizeof(PHY_FIND_CELL_IND(message_p)));
+              PHY_FIND_CELL_IND (message_p).transaction_id   = PHY_FIND_CELL_REQ(msg_p).transaction_id;
+              PHY_FIND_CELL_IND (message_p).cell_nb          = 1;
+              PHY_FIND_CELL_IND (message_p).cells[0].earfcn  = 1;
+              PHY_FIND_CELL_IND (message_p).cells[0].cell_id = 06;
+              PHY_FIND_CELL_IND (message_p).cells[0].rsrp    = 39;
+              PHY_FIND_CELL_IND (message_p).cells[0].rsrq    = 39;
+
+              itti_send_msg_to_task(TASK_RRC_UE, instance, message_p);
+
+          }
+#   endif
+          break;
+
+#   if defined(ENABLE_RAL)
+        case TIMER_HAS_EXPIRED:
+            // check if it is a measurement timer
+        {
+            hashtable_rc_t       hashtable_rc;
+
+            hashtable_rc = hashtable_is_key_exists(PHY_vars_UE_g[Mod_id]->ral_thresholds_timed, (uint64_t)(TIMER_HAS_EXPIRED(msg_p).timer_id));
+            if (hashtable_rc == HASH_TABLE_OK) {
+                phy_UE_lte_check_measurement_thresholds(instance, (ral_threshold_phy_t*)TIMER_HAS_EXPIRED(msg_p).arg);
+            }
+        }
+            break;
+
+
+        case PHY_MEAS_THRESHOLD_REQ:
+#warning "TO DO LIST OF THRESHOLDS"
+          LOG_I(PHY, "[UE %d] Received %s\n", Mod_id, msg_name);
+          {
+              ral_transaction_id_t transaction_id;
+              ral_threshold_phy_t* threshold_phy_p  = NULL;
+              int                  index, res;
+              long                 timer_id;
+              hashtable_rc_t       hashtable_rc;
+
+
+              transaction_id = PHY_MEAS_THRESHOLD_REQ(msg_p).transaction_id;
+              switch (PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.th_action) {
+
+                  case RAL_TH_ACTION_CANCEL_THRESHOLD:
+                      break;
+
+                  case RAL_TH_ACTION_SET_NORMAL_THRESHOLD:
+                  case RAL_TH_ACTION_SET_ONE_SHOT_THRESHOLD:
+                      for (index = 0; index < PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.num_thresholds; index++) {
+                          threshold_phy_p                  = calloc(1, sizeof(ral_threshold_phy_t));
+                          threshold_phy_p->th_action       = PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.th_action;
+                          memcpy(&threshold_phy_p->link_param_type,
+                                  &PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type,
+                                  sizeof(threshold_phy_p->link_param_type));
+
+                          memcpy(&threshold_phy_p->threshold,
+                                  &PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.thresholds[index],
+                                  sizeof(ral_threshold_t));
+
+                          switch (PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.union_choice) {
+
+                              case RAL_LINK_CFG_PARAM_CHOICE_TIMER_NULL:
+                                  switch (PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type.choice) {
+                                      case RAL_LINK_PARAM_TYPE_CHOICE_GEN:
+                                          SLIST_INSERT_HEAD(
+                                              &PHY_vars_UE_g[Mod_id]->ral_thresholds_gen_polled[PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type._union.link_param_gen],
+                                              threshold_phy_p,
+                                              ral_thresholds);
+                                          break;
+
+                                      case RAL_LINK_PARAM_TYPE_CHOICE_LTE:
+                                          SLIST_INSERT_HEAD(
+                                              &PHY_vars_UE_g[Mod_id]->ral_thresholds_lte_polled[PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type._union.link_param_gen],
+                                              threshold_phy_p,
+                                              ral_thresholds);
+                                          break;
+
+                                      default:
+                                          LOG_E(PHY, "[UE %d] BAD PARAMETER cfg_param.link_param_type.choice %d in %s\n",
+                                                  Mod_id, PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.link_param_type.choice, msg_name);
+                                  }
+                                  break;
+
+                              case RAL_LINK_CFG_PARAM_CHOICE_TIMER:
+                                  res = timer_setup(
+                                      (uint32_t)(PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param._union.timer_interval/1000),//uint32_t      interval_sec,
+                                      (uint32_t)(PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param._union.timer_interval%1000),//uint32_t      interval_us,
+                                      TASK_PHY_UE,
+                                      instance,
+                                      TIMER_PERIODIC,
+                                      threshold_phy_p,
+                                      &timer_id);
+
+                                  if (res == 0) {
+                                      hashtable_rc = hashtable_insert(PHY_vars_UE_g[Mod_id]->ral_thresholds_timed, (uint64_t )timer_id, (void*)threshold_phy_p);
+                                      if (hashtable_rc == HASH_TABLE_OK) {
+                                          threshold_phy_p->timer_id = timer_id;
+                                      } else {
+                                          LOG_E(PHY, "[UE %d]  %s: Error in hashtable. Could not configure threshold index %d \n",
+                                                  Mod_id, msg_name, index);
+                                      }
+
+                                  } else {
+                                      LOG_E(PHY, "[UE %d]  %s: Could not configure threshold index %d because of timer initialization failure\n",
+                                              Mod_id, msg_name, index);
+                                  }
+                                  break;
+
+                              default: // already checked in RRC, should not happen here
+                                  LOG_E(PHY, "[UE %d] BAD PARAMETER cfg_param.union_choice %d in %s\n",
+                                           Mod_id, PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.union_choice, msg_name);
+                          }
+                      }
+                      break;
+
+                  default:
+                      LOG_E(PHY, "[UE %d] BAD PARAMETER th_action value %d in %s\n",
+                              Mod_id, PHY_MEAS_THRESHOLD_REQ(msg_p).cfg_param.th_action, msg_name);
+              }
+
+          }
           break;
+#   endif
 
         default:
           LOG_E(PHY, "[UE %d] Received unexpected message %s\n", Mod_id, msg_name);
diff --git a/openair2/COMMON/phy_messages_def.h b/openair2/COMMON/phy_messages_def.h
index 9ebb659d68..6b1203f71e 100644
--- a/openair2/COMMON/phy_messages_def.h
+++ b/openair2/COMMON/phy_messages_def.h
@@ -11,11 +11,8 @@ MESSAGE_DEF(PHY_DEACTIVATE_REQ,      MESSAGE_PRIORITY_MED_PLUS, PhyDeactivateReq
 
 MESSAGE_DEF(PHY_FIND_CELL_REQ,       MESSAGE_PRIORITY_MED_PLUS, PhyFindCellReq,       phy_find_cell_req)
 MESSAGE_DEF(PHY_FIND_NEXT_CELL_REQ,  MESSAGE_PRIORITY_MED_PLUS, PhyFindNextCellReq,   phy_find_next_cell_req)
-#ifdef ENABLE_RAL
-MESSAGE_DEF(PHY_MEAS_THRESHOLD_REQ,  MESSAGE_PRIORITY_MED_PLUS, PhyMeasThreshodReq,   phy_meas_threshold_req)
-#endif
+MESSAGE_DEF(PHY_MEAS_THRESHOLD_REQ,  MESSAGE_PRIORITY_MED_PLUS, PhyMeasThresholdReq,  phy_meas_threshold_req)
 // UE: PHY -> RRC messages
 MESSAGE_DEF(PHY_FIND_CELL_IND,       MESSAGE_PRIORITY_MED_PLUS, PhyFindCellInd,       phy_find_cell_ind)
-#ifdef ENABLE_RAL
 MESSAGE_DEF(PHY_MEAS_THRESHOLD_CONF, MESSAGE_PRIORITY_MED_PLUS, PhyMeasThresholdConf, phy_meas_threshold_conf)
-#endif
+MESSAGE_DEF(PHY_MEAS_REPORT_IND,     MESSAGE_PRIORITY_MED_PLUS, PhyMeasReportInd,     phy_meas_report_ind)
diff --git a/openair2/COMMON/phy_messages_types.h b/openair2/COMMON/phy_messages_types.h
index 04664ff96f..a079b8877b 100644
--- a/openair2/COMMON/phy_messages_types.h
+++ b/openair2/COMMON/phy_messages_types.h
@@ -8,9 +8,7 @@
 #ifndef PHY_MESSAGES_TYPES_H_
 #define PHY_MESSAGES_TYPES_H_
 
-#ifdef ENABLE_RAL
 #include "ral_messages_types.h"
-#endif
 //-------------------------------------------------------------------------------------------//
 // Defines to access message fields.
 #define PHY_DEACTIVATE_REQ(mSGpTR)          (mSGpTR)->ittiMsg.phy_deactivate_req
@@ -20,10 +18,9 @@
 
 #define PHY_FIND_CELL_IND(mSGpTR)           (mSGpTR)->ittiMsg.phy_find_cell_ind
 
-#ifdef ENABLE_RAL
 #define PHY_MEAS_THRESHOLD_REQ(mSGpTR)      (mSGpTR)->ittiMsg.phy_meas_threshold_req
 #define PHY_MEAS_THRESHOLD_CONF(mSGpTR)     (mSGpTR)->ittiMsg.phy_meas_threshold_conf
-#endif
+#define PHY_MEAS_REPORT_IND(mSGpTR)         (mSGpTR)->ittiMsg.phy_meas_report_ind
 //-------------------------------------------------------------------------------------------//
 #define MAX_REPORTED_CELL   10
 
@@ -52,6 +49,9 @@ typedef struct PhyDeactivateReq_s {
 } PhyDeactivateReq;
 
 typedef struct PhyFindCellReq_s {
+//#   if defined(ENABLE_RAL)
+    ral_transaction_id_t  transaction_id;
+//#   endif
     Earfcn earfcn_start;
     Earfcn earfcn_end;
 } PhyFindCellReq;
@@ -60,25 +60,29 @@ typedef struct PhyFindNextCellReq_s {
 } PhyFindNextCellReq;
 
 
-#ifdef ENABLE_RAL
-typedef struct PhyMeasThreshodReq_s {
+typedef struct PhyMeasThresholdReq_s {
     ral_transaction_id_t      transaction_id;
     ral_link_cfg_param_t      cfg_param;
-} PhyMeasThreshodReq;
-#endif
+} PhyMeasThresholdReq;
+
+typedef struct PhyMeasReportInd_s {
+    ral_threshold_t            threshold;
+    ral_link_param_type_t      link_param_type;
+} PhyMeasReportInd;
 
 // UE: PHY -> RRC messages
 typedef struct PhyFindCellInd_s {
+//#   if defined(ENABLE_RAL)
+    ral_transaction_id_t  transaction_id;
+//#   endif
    uint8_t      cell_nb;
    CellInfo     cells[MAX_REPORTED_CELL];
 } PhyFindCellInd;
 
-#ifdef ENABLE_RAL
 typedef struct PhyMeasThresholdConf_s {
     ral_transaction_id_t     transaction_id;
     ral_status_t             status;
     uint8_t                  num_link_cfg_params;
     ral_link_cfg_status_t    cfg_status[RAL_MAX_LINK_CFG_PARAMS];
 }PhyMeasThresholdConf;
-#endif
 #endif /* PHY_MESSAGES_TYPES_H_ */
diff --git a/openair2/COMMON/ral_messages_def.h b/openair2/COMMON/ral_messages_def.h
index 16a6cd1563..0387d961f0 100755
--- a/openair2/COMMON/ral_messages_def.h
+++ b/openair2/COMMON/ral_messages_def.h
@@ -4,9 +4,9 @@ MESSAGE_DEF(RRC_RAL_SYSTEM_INFORMATION_IND,            MESSAGE_PRIORITY_MED, rrc
 MESSAGE_DEF(RRC_RAL_SCAN_REQ,                          MESSAGE_PRIORITY_MED, rrc_ral_scan_req_t,                          rrc_ral_scan_req)
 MESSAGE_DEF(RRC_RAL_SCAN_CONF,                         MESSAGE_PRIORITY_MED, rrc_ral_scan_conf_t,                         rrc_ral_scan_conf)
 
-MESSAGE_DEF(RRC_RAL_CONFIGURE_THRESHOLD_REQ,           MESSAGE_PRIORITY_MAX, rrc_ral_configure_threshold_req_t,           rrc_ral_configure_threshold_req)
+MESSAGE_DEF(RRC_RAL_CONFIGURE_THRESHOLD_REQ,           MESSAGE_PRIORITY_MED, rrc_ral_configure_threshold_req_t,           rrc_ral_configure_threshold_req)
 MESSAGE_DEF(RRC_RAL_CONFIGURE_THRESHOLD_CONF,          MESSAGE_PRIORITY_MED, rrc_ral_configure_threshold_conf_t,          rrc_ral_configure_threshold_conf)
-MESSAGE_DEF(RRC_RAL_MEASUREMENT_REPORT_IND,            MESSAGE_PRIORITY_MAX, rrc_ral_measurement_report_ind_t,            rrc_ral_measurement_report_ind)
+MESSAGE_DEF(RRC_RAL_MEASUREMENT_REPORT_IND,            MESSAGE_PRIORITY_MED, rrc_ral_measurement_report_ind_t,            rrc_ral_measurement_report_ind)
 
 MESSAGE_DEF(RRC_RAL_CONNECTION_ESTABLISHMENT_REQ,      MESSAGE_PRIORITY_MED, rrc_ral_connection_establishment_req_t,      rrc_ral_connection_establishment_req)
 MESSAGE_DEF(RRC_RAL_CONNECTION_ESTABLISHMENT_CONF,     MESSAGE_PRIORITY_MED, rrc_ral_connection_establishment_conf_t,     rrc_ral_connection_establishment_conf)
diff --git a/openair2/COMMON/ral_messages_types.h b/openair2/COMMON/ral_messages_types.h
index cc548a6d88..00c2748d81 100755
--- a/openair2/COMMON/ral_messages_types.h
+++ b/openair2/COMMON/ral_messages_types.h
@@ -37,6 +37,9 @@ LINK COMMANDS:
 #define RRC_RAL_SYSTEM_CONFIGURATION_IND(mSGpTR)          (mSGpTR)->ittiMsg.rrc_ral_system_configuration_ind
 #define RRC_RAL_SYSTEM_INFORMATION_IND(mSGpTR)            (mSGpTR)->ittiMsg.rrc_ral_system_information_ind
 
+#define RRC_RAL_SCAN_REQ(mSGpTR)                          (mSGpTR)->ittiMsg.rrc_ral_scan_req
+#define RRC_RAL_SCAN_CONF(mSGpTR)                         (mSGpTR)->ittiMsg.rrc_ral_scan_conf
+
 #define RRC_RAL_CONFIGURE_THRESHOLD_REQ(mSGpTR)           (mSGpTR)->ittiMsg.rrc_ral_configure_threshold_req
 #define RRC_RAL_CONFIGURE_THRESHOLD_CONF(mSGpTR)          (mSGpTR)->ittiMsg.rrc_ral_configure_threshold_conf
 #define RRC_RAL_MEASUREMENT_REPORT_IND(mSGpTR)            (mSGpTR)->ittiMsg.rrc_ral_measurement_report_ind
@@ -124,7 +127,7 @@ typedef struct rrc_ral_scan_conf_s {
     ral_transaction_id_t transaction_id;
 #define RAL_MAX_LINK_SCAN_RESP 16
     uint8_t                  num_scan_resp;
-    ral_link_scan_resp_t     ink_scan_resp[RAL_MAX_LINK_SCAN_RESP];
+    ral_link_scan_resp_t     link_scan_resp[RAL_MAX_LINK_SCAN_RESP];
 }rrc_ral_scan_conf_t;
 
 typedef struct rrc_ral_connection_establishment_req_s{
@@ -182,6 +185,7 @@ typedef MIH_C_LINK_PARAM_GEN_T                                 ral_link_param_ge
 #define RAL_LINK_PARAM_GEN_SINR                                MIH_C_LINK_PARAM_GEN_SINR
 #define RAL_LINK_PARAM_GEN_THROUGHPUT                          MIH_C_LINK_PARAM_GEN_THROUGHPUT
 #define RAL_LINK_PARAM_GEN_PACKET_ERROR_RATE                   MIH_C_LINK_PARAM_GEN_PACKET_ERROR_RATE
+#define RAL_LINK_PARAM_GEN_MAX                                 RAL_LINK_PARAM_GEN_PACKET_ERROR_RATE
 
 typedef MIH_C_LINK_PARAM_QOS_T                                 ral_link_param_qos_t;
 #define RAL_LINK_PARAM_QOS_MAX_NUM_DIF_COS_SUPPORTED            MIH_C_LINK_PARAM_QOS_MAX_NUM_DIF_COS_SUPPORTED
@@ -190,6 +194,7 @@ typedef MIH_C_LINK_PARAM_QOS_T                                 ral_link_param_qo
 #define RAL_LINK_PARAM_QOS_MAX_PACKET_TRANSFER_DELAY_ALL_COS    MIH_C_LINK_PARAM_QOS_MAX_PACKET_TRANSFER_DELAY_ALL_COS
 #define RAL_LINK_PARAM_QOS_STD_DEVIATION_PACKET_TRANSFER_DELAY  MIH_C_LINK_PARAM_QOS_STD_DEVIATION_PACKET_TRANSFER_DELAY
 #define RAL_LINK_PARAM_QOS_PACKET_LOSS_RATE_ALL_COS_FRAME_RATIO MIH_C_LINK_PARAM_QOS_PACKET_LOSS_RATE_ALL_COS_FRAME_RATIO
+#define RAL_LINK_PARAM_QOS_MAX                                  RAL_LINK_PARAM_QOS_PACKET_LOSS_RATE_ALL_COS_FRAME_RATIO
 
 typedef MIH_C_LINK_PARAM_LTE_T                                 ral_link_param_lte_t;
 #define RAL_LINK_PARAM_LTE_UE_RSRP                             MIH_C_LINK_PARAM_LTE_UE_RSRP
@@ -204,6 +209,7 @@ typedef MIH_C_LINK_PARAM_LTE_T                                 ral_link_param_lt
 #define RAL_LINK_PARAM_LTE_JUMBO_FEASIBILITY                   MIH_C_LINK_PARAM_LTE_JUMBO_FEASIBILITY
 #define RAL_LINK_PARAM_LTE_JUMBO_SETUP_STATUS                  MIH_C_LINK_PARAM_LTE_JUMBO_SETUP_STATUS
 #define RAL_LINK_PARAM_LTE_NUM_ACTIVE_EMBMS_RECEIVERS_PER_FLOW MIH_C_LINK_PARAM_LTE_NUM_ACTIVE_EMBMS_RECEIVERS_PER_FLOW
+#define RAL_LINK_PARAM_LTE_MAX                                 RAL_LINK_PARAM_LTE_NUM_ACTIVE_EMBMS_RECEIVERS_PER_FLOW
 
 #define RAL_LINK_PARAM_TYPE_CHOICE_GEN       MIH_C_LINK_PARAM_TYPE_CHOICE_GEN
 #define RAL_LINK_PARAM_TYPE_CHOICE_QOS       MIH_C_LINK_PARAM_TYPE_CHOICE_QOS
@@ -268,6 +274,8 @@ typedef struct rrc_ral_configure_threshold_conf_s {
 }rrc_ral_configure_threshold_conf_t;
 
 typedef struct rrc_ral_measurement_report_ind_s{
+    ral_threshold_t            threshold;
+    ral_link_param_type_t      link_param_type;
 }rrc_ral_measurement_report_ind_t;
 
 
diff --git a/openair2/RRC/LITE/defs.h b/openair2/RRC/LITE/defs.h
index d86bcbdf93..0aa81ebd6d 100644
--- a/openair2/RRC/LITE/defs.h
+++ b/openair2/RRC/LITE/defs.h
@@ -428,6 +428,7 @@ typedef struct UE_RRC_INST_s {
   float                           rsrq_db_filtered[7];
 #if defined(ENABLE_RAL)
   obj_hash_table_t               *ral_meas_thresholds;
+  ral_transaction_id_t            scan_transaction_id;
 #endif
 #if defined(ENABLE_SECURITY)
   /* KeNB as computed from parameters within USIM card */
diff --git a/openair2/RRC/LITE/rrc_UE.c b/openair2/RRC/LITE/rrc_UE.c
index cf9182251d..820ac58a00 100644
--- a/openair2/RRC/LITE/rrc_UE.c
+++ b/openair2/RRC/LITE/rrc_UE.c
@@ -1373,7 +1373,7 @@ void rrc_ue_process_rrcConnectionReconfiguration(u8 Mod_id, u32 frame,
                 memcpy (&message_ral_p->ittiMsg, (void *) &connection_reestablishment_ind, sizeof(rrc_ral_connection_reestablishment_ind_t));
                 //#warning "Mod_id ? for instance ? => YES"
                 LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_IND to mRAL\n");
-                itti_send_msg_to_task (TASK_RAL_UE, Mod_id, message_ral_p);
+                itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
             }
 #endif
 #endif
@@ -1676,7 +1676,7 @@ void  rrc_ue_decode_dcch(u8 Mod_id,u32 frame,u8 Srb_id, u8 *Buffer,u8 eNB_index)
                 memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ho_ind, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
                 //#warning "Mod_id ? for instance ? => YES"
                 LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_HO_IND to mRAL\n");
-                itti_send_msg_to_task (TASK_RAL_UE, Mod_id, message_ral_p);
+                itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
             }
 #endif
 #endif
@@ -1714,7 +1714,7 @@ void  rrc_ue_decode_dcch(u8 Mod_id,u32 frame,u8 Srb_id, u8 *Buffer,u8 eNB_index)
                 memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ind, sizeof(rrc_ral_connection_reconfiguration_ind_t));
                 //#warning "Mod_id ? for instance ? => YES"
                 LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_IND to mRAL\n");
-                itti_send_msg_to_task (TASK_RAL_UE, Mod_id, message_ral_p);
+                itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
             }
 #endif
 #endif
@@ -2241,7 +2241,7 @@ int decode_SI(u8 Mod_id,u32 frame,u8 eNB_index,u8 si_window) {
               ral_si_ind.link_data_rate = 0;
               memcpy (&message_ral_p->ittiMsg, (void *) &ral_si_ind, sizeof(rrc_ral_system_information_ind_t));
 #warning "Mod_id ? for instance ?"
-              itti_send_msg_to_task (TASK_RAL_UE, Mod_id, message_ral_p);
+              itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
           }
 #endif
       }
@@ -2889,20 +2889,154 @@ void *rrc_ue_task(void *args_p) {
       }
 # endif
 
-#ifdef ENABLE_RAL
+# if defined(ENABLE_RAL)
       case RRC_RAL_SCAN_REQ:
-          LOG_I(RRC, "[UE %d] Received %s\n", Mod_id, msg_name);
+          LOG_I(RRC, "[UE %d] Received %s: state %d\n", Mod_id, msg_name);
+
+          switch (rrc_get_state(Mod_id)) {
+              case RRC_STATE_INACTIVE:
+              {
+                  /* Need to first activate lower layers */
+                  MessageDef *message_p;
+
+                  message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);
+
+                  itti_send_msg_to_task(TASK_L2L1, instance, message_p);
+
+                  rrc_set_state (Mod_id, RRC_STATE_IDLE);
+                  /* Fall through to next case */
+              }
+
+              case RRC_STATE_IDLE:
+              {
+                  if (rrc_get_sub_state(Mod_id) != RRC_SUB_STATE_IDLE_SEARCHING) {
+                      /* Ask to layer 1 to find a cell matching the criterion */
+                      MessageDef *message_p;
+
+                      message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
+
+                      rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
+
+                      PHY_FIND_CELL_REQ (message_p).transaction_id = RRC_RAL_SCAN_REQ (msg_p).transaction_id;
+                      PHY_FIND_CELL_REQ (message_p).earfcn_start   = 1;
+                      PHY_FIND_CELL_REQ (message_p).earfcn_end     = 1; //44
+
+                      itti_send_msg_to_task(TASK_PHY_UE, instance, message_p);
+                  }
+                  break;
+              }
+
+              case RRC_STATE_CONNECTED:
+                  /* should not happen */
+                  LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", Mod_id, msg_name, rrc_get_state(Mod_id));
+                  break;
+
+              default:
+                  LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", Mod_id, rrc_get_state(Mod_id));
+                  break;
+          }
           break;
 
+      case PHY_FIND_CELL_IND:
+          LOG_I(RRC, "[UE %d] Received %s: state %d\n", Mod_id, msg_name, rrc_get_state(Mod_id));
+          switch (rrc_get_state(Mod_id)) {
+              case RRC_STATE_IDLE:
+                  switch (rrc_get_sub_state(Mod_id)) {
+                      case RRC_SUB_STATE_IDLE_SEARCHING:
+                      {
+                          MessageDef *message_p;
+                          int         i;
+
+                          message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_SCAN_CONF);
+
+                          RRC_RAL_SCAN_CONF (message_p).transaction_id = PHY_FIND_CELL_IND(msg_p).transaction_id;
+                          RRC_RAL_SCAN_CONF (message_p).num_scan_resp  = PHY_FIND_CELL_IND(msg_p).cell_nb;
+                          for (i = 0 ; i < PHY_FIND_CELL_IND(msg_p).cell_nb; i++) {
+                              // TO DO
+                              memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].link_addr,  0, sizeof(ral_link_addr_t));
+                              // TO DO
+                              memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].network_id, 0, sizeof(ral_network_id_t));
+
+                              RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength.choice     = RAL_SIG_STRENGTH_CHOICE_DBM;
+                              RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength._union.dbm = PHY_FIND_CELL_IND(msg_p).cells[i].rsrp;
+                          }
+
+                          rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE);
+
+                          itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
+                          break;
+                      }
+
+                      default:
+                          LOG_C(RRC, "[UE %d] Invalid RRC state %d substate %d\n",
+                                  Mod_id,
+                                  rrc_get_state(Mod_id),
+                                  rrc_get_sub_state(Mod_id));
+                  }
+                  break;
+
+              case RRC_STATE_INACTIVE:
+              case RRC_STATE_CONNECTED:
+                  /* should not happen */
+                  LOG_E(RRC, "[UE %d] indication %s in RRC state %d\n", Mod_id, msg_name, rrc_get_state(Mod_id));
+                  break;
+
+              default:
+                  LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", Mod_id, rrc_get_state(Mod_id));
+                  break;
+          }
+          break;
+
+      case PHY_MEAS_REPORT_IND:
+      {
+          MessageDef *message_p;
+          message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_MEASUREMENT_REPORT_IND);
+
+          memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold,
+                  &PHY_MEAS_REPORT_IND(msg_p).threshold,
+                  sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold));
+
+          memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param_type,
+                  &PHY_MEAS_REPORT_IND(msg_p).link_param_type,
+                  sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param_type));
+
+          itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
+          break;
+      }
+
       case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
           rrc_ue_ral_handle_configure_threshold_request(Mod_id, msg_p);
           break;
 
       case RRC_RAL_CONNECTION_ESTABLISHMENT_REQ:
           LOG_I(RRC, "[UE %d] Received %s\n", Mod_id, msg_name);
+          switch (rrc_get_state(Mod_id)) {
+              case RRC_STATE_IDLE:
+              {
+                  if (rrc_get_sub_state(Mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE)
+                  {
+                      rrc_ue_generate_RRCConnectionRequest(Mod_id, 0 /* TODO put frame number ! */, 0);
+                      LOG_I(RRC, "not sending connection request\n");
+
+                      rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
+                  }
+                  break;
+              }
+
+              case RRC_STATE_INACTIVE:
+              case RRC_STATE_CONNECTED:
+                  /* should not happen */
+                  LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", Mod_id, msg_name, rrc_get_state(Mod_id));
+                  break;
+
+              default:
+                  LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", Mod_id, rrc_get_state(Mod_id));
+                  break;
+          }
           break;
 
       case RRC_RAL_CONNECTION_RELEASE_REQ:
+          Mod_id = 0; /* TODO force Mod_id to first UE, NAS UE not virtualized yet */
           LOG_I(RRC, "[UE %d] Received %s\n", Mod_id, msg_name);
           break;
 #endif
diff --git a/openair2/RRC/LITE/rrc_UE_ral.c b/openair2/RRC/LITE/rrc_UE_ral.c
index ff0fe53914..1b09f970e9 100755
--- a/openair2/RRC/LITE/rrc_UE_ral.c
+++ b/openair2/RRC/LITE/rrc_UE_ral.c
@@ -233,3 +233,4 @@ int rrc_ue_ral_handle_configure_threshold_request(unsigned int mod_idP, MessageD
     return 0;
 }
 
+
diff --git a/openair2/RRC/LITE/rrc_UE_ral.h b/openair2/RRC/LITE/rrc_UE_ral.h
index 90554aa58f..2af797e146 100755
--- a/openair2/RRC/LITE/rrc_UE_ral.h
+++ b/openair2/RRC/LITE/rrc_UE_ral.h
@@ -70,5 +70,4 @@
 private_rrc_ue_ral(  int rrc_ue_ral_delete_all_thresholds_type        (unsigned int mod_idP, ral_link_param_type_t *param_type_pP);)
 private_rrc_ue_ral(  int rrc_ue_ral_delete_threshold                  (unsigned int mod_idP, ral_link_param_type_t *param_type_pP, ral_threshold_t *threshold_pP);)
 protected_rrc_ue_ral(int rrc_ue_ral_handle_configure_threshold_request(unsigned int mod_idP, MessageDef *msg_pP);)
-
 #endif
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index d9a9d222dc..e6909fac78 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -360,6 +360,7 @@ static void init_MCCH (u8 Mod_id) {
                                                                                 &eNB_rrc_inst[Mod_id].mcch,
                                                                                 &eNB_rrc_inst[Mod_id].mcch_message);
 
+
       LOG_I(RRC,"mcch message pointer %p for sync area %d \n", eNB_rrc_inst[Mod_id].MCCH_MESSAGE[sync_area],sync_area);
       LOG_D (RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", Mod_id,sync_area);
       LOG_D (RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %d\n", Mod_id,
diff --git a/openair2/UTIL/LISTS/list.h b/openair2/UTIL/LISTS/list.h
index ba16e034b6..4af916953e 100755
--- a/openair2/UTIL/LISTS/list.h
+++ b/openair2/UTIL/LISTS/list.h
@@ -60,6 +60,7 @@ public_list( void         list_display (list_t* );)
 public_list2( void         list2_init           (list2_t*, char*);)
 public_list2( void         list2_free           (list2_t* );)
 public_list2( mem_block_t* list2_get_head       (list2_t*);)
+public_list2( mem_block_t* list2_get_tail       (list2_t*);)
 public_list2( mem_block_t* list2_remove_element (mem_block_t* , list2_t* );)
 public_list2( mem_block_t* list2_remove_head    (list2_t* );)
 public_list2( mem_block_t* list2_remove_tail    (list2_t* );)
diff --git a/openair2/UTIL/LISTS/list2.c b/openair2/UTIL/LISTS/list2.c
index 418d902a3b..47bb92265b 100644
--- a/openair2/UTIL/LISTS/list2.c
+++ b/openair2/UTIL/LISTS/list2.c
@@ -96,6 +96,14 @@ list2_get_head (list2_t * listP)
   return listP->head;
 }
 
+//-----------------------------------------------------------------------------
+mem_block_t *
+list2_get_tail (list2_t * listP)
+{
+//-----------------------------------------------------------------------------
+  return listP->tail;
+}
+
 //-----------------------------------------------------------------------------
 /*
  *  remove an element from head of a list
diff --git a/targets/COMMON/create_tasks.c b/targets/COMMON/create_tasks.c
index fef2c00d54..d656363756 100644
--- a/targets/COMMON/create_tasks.c
+++ b/targets/COMMON/create_tasks.c
@@ -39,6 +39,10 @@
 #     include "s1ap_eNB.h"
 #     include "nas_ue_task.h"
 #   endif
+#   if defined(ENABLE_RAL)
+#     include "lteRALue.h"
+#     include "lteRALenb.h"
+#   endif
 #   include "RRC/LITE/defs.h"
 # endif
 # include "enb_app.h"
@@ -83,6 +87,12 @@ int create_tasks(uint32_t enb_nb, uint32_t ue_nb)
                 LOG_E(EMU, "Create task for RRC eNB failed\n");
                 return -1;
             }
+#   if defined(ENABLE_RAL)
+            if (itti_create_task (TASK_RAL_ENB, eRAL_task, NULL) < 0) {
+                LOG_E(EMU, "Create task for RAL eNB failed\n");
+                return -1;
+            }
+#   endif
         }
 
         if (ue_nb > 0)
@@ -92,6 +102,12 @@ int create_tasks(uint32_t enb_nb, uint32_t ue_nb)
                 LOG_E(EMU, "Create task for RRC UE failed\n");
                 return -1;
             }
+#   if defined(ENABLE_RAL)
+            if (itti_create_task (TASK_RAL_UE, mRAL_task, NULL) < 0) {
+                LOG_E(EMU, "Create task for RAL UE failed\n");
+                return -1;
+            }
+#   endif
         }
     }
 # endif
diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c
index ed2db3340f..05e59c2b73 100644
--- a/targets/SIMU/USER/oaisim.c
+++ b/targets/SIMU/USER/oaisim.c
@@ -472,8 +472,9 @@ void *l2l1_task(void *args_p) {
   int           result;
 
   itti_mark_task_ready (TASK_L2L1);
+  LOG_I(EMU, "TASK_L2L1 is READY\n");
 
-  if (NB_eNB_INST > 0) {
+  if (oai_emulation.info.nb_enb_local > 0) {
     /* Wait for the initialize message */
     do {
       if (message_p != NULL) {
@@ -533,6 +534,7 @@ void *l2l1_task(void *args_p) {
             LOG_I(EMU, "Received %s\n", ITTI_MSG_NAME(message_p));
             break;
 
+
           default:
             LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
             break;
@@ -674,29 +676,29 @@ void *l2l1_task(void *args_p) {
 
         if ((next_slot % 2) == 0)
           clear_UE_transport_info (oai_emulation.info.nb_ue_local);
-
         for (UE_id = oai_emulation.info.first_ue_local;
-            (UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local)); UE_id++) {
+	     (UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local)); UE_id++) {
           if (oai_emulation.info.cli_start_ue[UE_id] != 0) {
 #if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
-            {
+	    
 #else
-            if (frame >= (UE_id * 20)) { // activate UE only after 20*UE_id frames so that different UEs turn on separately
+	    if (frame >= (UE_id * 20))  // activate UE only after 20*UE_id frames so that different UEs turn on separately
 #endif
-              LOG_D(EMU, "PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n", UE_id, frame, slot, next_slot >> 1, last_slot>>1);
-
+	      {
+	      LOG_D(EMU, "PHY procedures UE %d for frame %d, slot %d (subframe TX %d, RX %d)\n", UE_id, frame, slot, next_slot >> 1, last_slot>>1);
+	      
               if (PHY_vars_UE_g[UE_id]->UE_mode[0] != NOT_SYNCHED) {
                 if (frame > 0) {
                   PHY_vars_UE_g[UE_id]->frame = frame;
-
+		  
 #ifdef OPENAIR2
                   //Application
                   update_otg_UE (UE_id, oai_emulation.info.time_ms);
-
+		  
                   //Access layer
                   pdcp_run (frame, 0, UE_id, 0);
 #endif
-
+		  
                   phy_procedures_UE_lte (last_slot, next_slot, PHY_vars_UE_g[UE_id], 0, abstraction_flag, normal_txrx,
                                          no_relay, NULL);
                   ue_data[UE_id]->tx_power_dBm = PHY_vars_UE_g[UE_id]->tx_power_dBm;
@@ -711,7 +713,7 @@ void *l2l1_task(void *args_p) {
                 }
                 if ((frame > 0) && (last_slot == (LTE_SLOTS_PER_FRAME - 2))) {
                   initial_sync (PHY_vars_UE_g[UE_id], normal_txrx);
-
+		  
                   /*
                    write_output("dlchan00.m","dlch00",&(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),(6*(PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)),1,1);
                    if (PHY_vars_UE_g[0]->lte_frame_parms.nb_antennas_rx>1)
@@ -739,8 +741,8 @@ void *l2l1_task(void *args_p) {
               }
 #endif
             }
-          }
-        }
+	    }
+	  }
 #ifdef Rel10
         for (RN_id=oai_emulation.info.first_rn_local;
             RN_id<oai_emulation.info.first_rn_local+oai_emulation.info.nb_rn_local;
@@ -1078,13 +1080,15 @@ int main(int argc, char **argv) {
 
 #if defined(ENABLE_ITTI)
   // Handle signals until all tasks are terminated
-  if (create_tasks(NB_eNB_INST, NB_UE_INST) >= 0) {
+  if (create_tasks(oai_emulation.info.nb_enb_local, oai_emulation.info.nb_ue_local) >= 0) {
     itti_wait_tasks_end();
   } else {
     exit(-1); // need a softer mode
   }
 #else
-  eNB_app_task(NULL); // do nothing for the moment
+  if (oai_emulation.info.nb_enb_local > 0) {
+      eNB_app_task(NULL); // do nothing for the moment
+  }
   l2l1_task (NULL);
 #endif
 
diff --git a/targets/SIMU/USER/oaisim_config.c b/targets/SIMU/USER/oaisim_config.c
index 2145479bf1..b0887abd23 100644
--- a/targets/SIMU/USER/oaisim_config.c
+++ b/targets/SIMU/USER/oaisim_config.c
@@ -458,34 +458,40 @@ int olg_config() {
   set_comp_log(OCG,  LOG_EMERG, 0x15,1);
   set_comp_log(OCM,  LOG_EMERG, 0x15,1);
   set_comp_log(OTG,  LOG_EMERG, 0x15,1);
-  set_comp_log(MAC,  LOG_EMERG, 0x15,1);
+  set_comp_log(MAC,  LOG_DEBUG, 0x15,1);
   set_comp_log(OMG,  LOG_EMERG, 0x15,1);
   set_comp_log(OPT,  LOG_EMERG, 0x15,1);
   set_comp_log(PDCP, LOG_TRACE, LOG_MED,1);
   set_comp_log(RLC,  LOG_TRACE, LOG_MED,1);
   set_comp_log(RRC,  LOG_TRACE, LOG_MED,1);
+#if defined(ENABLE_RAL)
+  set_comp_log(RAL_ENB, LOG_TRACE, LOG_MED,1);
+  set_comp_log(RAL_UE,  LOG_TRACE, LOG_MED,1);
+  set_log(RAL_ENB,  LOG_DEBUG, 1);
+  set_log(RAL_UE,  LOG_DEBUG, 1);
+#endif
 
   //set_log(OCG,  LOG_DEBUG, 1);
   //set_log(EMU,  LOG_INFO,  20);
-  //set_log(MAC,  LOG_DEBUG, 1);
-  set_log(RLC,  LOG_TRACE, 1);  
+  set_log(MAC,  LOG_DEBUG, 1);
+  set_log(RLC,  LOG_TRACE, 1);
   //set_log(PHY,  LOG_DEBUG, 1);
-  set_log(PDCP, LOG_TRACE, 1);  
+  set_log(PDCP, LOG_TRACE, 1);
   set_log(RRC,  LOG_DEBUG, 1);  
   //set_log(OCM,  LOG_INFO, 20);
   //set_log(OTG,  LOG_INFO, 1);
-/*  set_comp_log(OCG,  LOG_ERR, 0x15,1);
+  set_comp_log(OCG,  LOG_ERR, 0x15,1);
   set_comp_log(EMU,  LOG_ERR,  0x15,20);
-  set_comp_log(MAC,  LOG_ERR, 0x15,1);  
+  set_comp_log(MAC,  LOG_DEBUG, 0x15,1);  
   set_comp_log(RLC,  LOG_INFO, 0x15,1);  
-  set_comp_log(PHY,  LOG_ERR, 0x15, 1);  
+  set_comp_log(PHY,  LOG_DEBUG, 0x15, 1);  
   set_comp_log(PDCP, LOG_DEBUG, 0x15,1);  
   set_comp_log(RRC,  LOG_DEBUG, 0x15,1);  
   set_comp_log(OCM,  LOG_ERR, 0x15,20);  
   set_comp_log(OTG,  LOG_ERR, 0x15,1);  
   set_comp_log(OMG,  LOG_ERR, 0x15,1);  
   set_comp_log(OPT,  LOG_ERR, 0x15,1);  
-  */
+  
   // set_comp_log(MAC, LOG_TRACE, LOG_FULL,1);
   return 1; 
 }
diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c
index b673a35e94..e11e41d220 100644
--- a/targets/SIMU/USER/oaisim_functions.c
+++ b/targets/SIMU/USER/oaisim_functions.c
@@ -555,8 +555,8 @@ void check_and_adjust_params() {
     NB_eNB_INST+=NB_RN_INST;
     NB_UE_INST+=NB_RN_INST;
   }
-  LOG_I(EMU,"Total number of UE %d (local %d, remote %d, relay %d) mobility %s \n", 
-	NB_UE_INST,oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote, 
+  LOG_I(EMU,"Total number of UE %d (first local %d , num local %d, remote %d, relay %d) mobility %s \n",
+	NB_UE_INST,oai_emulation.info.first_ue_local, oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote,
 	NB_RN_INST,
 	oai_emulation.topology_config.mobility.UE_mobility.UE_mobility_type.selected_option);
   
@@ -620,7 +620,9 @@ void init_seed(u8 set_seed) {
 
 void init_openair1() {
   s32 UE_id, eNB_id;
-
+#if defined(ENABLE_RAL)
+  int list_index;
+#endif
   // change the nb_connected_eNB
   init_lte_vars (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.tdd_config_S,oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag,nb_antennas_rx, oai_emulation.info.eMBMS_active_state);
 
@@ -672,6 +674,16 @@ void init_openair1() {
     PHY_vars_UE_g[UE_id]->current_dlsch_cqi[0] = 10;
 
     LOG_I(EMU, "UE %d mode is initialized to %d\n", UE_id, PHY_vars_UE_g[UE_id]->UE_mode[0] );
+#if defined(ENABLE_RAL)
+    PHY_vars_UE_g[UE_id]->ral_thresholds_timed = hashtable_create (64, NULL, NULL);
+    for (list_index = 0; list_index < RAL_LINK_PARAM_GEN_MAX; list_index++) {
+        SLIST_INIT(&PHY_vars_UE_g[UE_id]->ral_thresholds_gen_polled[list_index]);
+    }
+    for (list_index = 0; list_index < RAL_LINK_PARAM_LTE_MAX; list_index++) {
+        SLIST_INIT(&PHY_vars_UE_g[UE_id]->ral_thresholds_lte_polled[list_index]);
+    }
+#endif
+
   }
 }
 
@@ -695,38 +707,9 @@ void init_openair2() {
 
   mac_xface->macphy_exit = exit_fun;
 
-#ifdef ENABLE_RAL
-  init_802_21_link_saps();
-#endif
-#endif
-}
-
-void init_802_21_link_saps() {
-#ifdef ENABLE_RAL
-#ifdef OPENAIR2
-#if defined(ENABLE_ITTI)
-  if (NB_eNB_INST > 0) {
-      if (itti_create_task (TASK_RAL_ENB, eRAL_task, NULL) < 0) {
-          LOG_E(EMU, "Create task failed");
-          LOG_D(EMU, "Initializing RAL eNB task interface: FAILED\n");
-          exit (-1);
-      }
-  }
-
-  if (NB_UE_INST > 0) {
-      if (itti_create_task (TASK_RAL_UE, mRAL_task, NULL) < 0) {
-          LOG_E(EMU, "Create task failed");
-          LOG_D(EMU, "Initializing RAL UE task interface: FAILED\n");
-          exit (-1);
-      }
-  }
-  sleep(15);
-#endif
-#endif
 #endif
 }
 
-
 void init_ocm() {
   s32 UE_id, eNB_id;
   /* Added for PHY abstraction */
diff --git a/targets/SIMU/USER/oaisim_functions.h b/targets/SIMU/USER/oaisim_functions.h
index 560dc44cef..f12b64d590 100644
--- a/targets/SIMU/USER/oaisim_functions.h
+++ b/targets/SIMU/USER/oaisim_functions.h
@@ -20,8 +20,6 @@ void init_openair1();
 
 void init_openair2();
 
-void init_802_21_link_saps();
-
 void init_ocm();
 
 void init_otg_pdcp_buffer();
diff --git a/targets/TEST/OAI/case01.py b/targets/TEST/OAI/case01.py
index 09663761f0..ad76c960ff 100644
--- a/targets/TEST/OAI/case01.py
+++ b/targets/TEST/OAI/case01.py
@@ -249,7 +249,7 @@ def execute(oai, user, pw, logfile,logdir):
     try:
         test = '15'
         name = 'Compile oai.rel10.itti.ral.make' 
-        conf = 'make DISABLE_XER_PRINT=1 ENABLE_ITTI=1 Rel10=1'
+        conf = 'make DISABLE_XER_PRINT=1 NAS=1 OAI_NW_DRIVER_TYPE_ETHERNET=1 ENABLE_ITTI=1 USER_MODE=1 OPENAIR2=1 ENABLE_RAL=1 MIH_C_MEDIEVAL_EXTENSIONS=1 Rel10=1'
         trace = logdir + '/log_' + case + test + '.txt;'
         tee = ' 2>&1 | tee ' + trace
         diag = 'check the compilation errors for ITTI Rel10'
-- 
GitLab