diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab
index 92975e883478d6b368b161ea21be9b2516a69617..5fa46ddcc0e2064720e4fbaa2a5ec4ec142028f0 100644
--- a/ci-scripts/Jenkinsfile-gitlab
+++ b/ci-scripts/Jenkinsfile-gitlab
@@ -33,15 +33,18 @@ def sendSocialMediaMessage(pipeChannel, pipeColor, pipeMessage) {
 def doRedHatBuild = false
 def doFlexranCtrlTest = false
 
+// Location of the executor node
+def nodeExecutor = params.nodeExecutor
+
 pipeline {
     agent {
-        label 'bellatrix'
+        label nodeExecutor
     }
     options {
         disableConcurrentBuilds()
         timestamps()
         gitLabConnection('OAI GitLab')
-        gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build phy-sim", "Build eNb-ethernet", "Build UE-ethernet", "Analysis with cppcheck", "Test phy-sim", "Test basic-sim", "Test L2-sim", "Test-FDD-Band7", "Test-TDD-Band40", "Test-IF4p5-FDD-Band7", "Test-IF4p5-TDD-Band40"])
+        gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build phy-sim", "Build eNb-ethernet", "Build UE-ethernet", "Analysis with cppcheck", "Test phy-sim", "Test basic-sim", "Test L2-sim", "Test-Mono-FDD-Band7", "Test-Mono-TDD-Band40", "Test-IF4p5-FDD-Band7", "Test-IF4p5-TDD-Band40", "Test-Mono-FDD-Band13"])
         ansiColor('xterm')
     }
 
@@ -393,7 +396,7 @@ pipeline {
                     steps {
                         script {
                             if ("MERGE".equals(env.gitlabActionType)) {
-                                gitlabCommitStatus(name: "Test-FDD-Band7") {
+                                gitlabCommitStatus(name: "Test-Mono-FDD-Band7") {
                                     build job: 'eNB-CI-FDD-Band7-B210',
                                        parameters: [
                                            string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
@@ -404,7 +407,7 @@ pipeline {
                                        ]
                                 }
                             } else {
-                                gitlabCommitStatus(name: "Test-FDD-Band7") {
+                                gitlabCommitStatus(name: "Test-Mono-FDD-Band7") {
                                     build job: 'eNB-CI-FDD-Band7-B210',
                                        parameters: [
                                            string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
@@ -444,7 +447,7 @@ pipeline {
                     steps {
                         script {
                             if ("MERGE".equals(env.gitlabActionType)) {
-                                gitlabCommitStatus(name: "Test-TDD-Band40") {
+                                gitlabCommitStatus(name: "Test-Mono-TDD-Band40") {
                                     build job: 'eNB-CI-TDD-Band40-B210',
                                        parameters: [
                                            string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
@@ -455,7 +458,7 @@ pipeline {
                                        ]
                                 }
                             } else {
-                                gitlabCommitStatus(name: "Test-TDD-Band40") {
+                                gitlabCommitStatus(name: "Test-Mono-TDD-Band40") {
                                     build job: 'eNB-CI-TDD-Band40-B210',
                                        parameters: [
                                            string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
@@ -593,6 +596,57 @@ pipeline {
                         }
                     }
                 }
+                stage ("Test MONOLITHIC - FDD - Band 13 - B210") {
+                    steps {
+                        script {
+                            if ("MERGE".equals(env.gitlabActionType)) {
+                                gitlabCommitStatus(name: "Test-Mono-FDD-Band13") {
+                                    build job: 'eNB-CI-MONO-FDD-Band13-B210',
+                                       parameters: [
+                                           string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
+                                           string(name: 'eNB_Branch', value: String.valueOf(env.gitlabSourceBranch)),
+                                           string(name: 'eNB_CommitID', value: String.valueOf(env.gitlabMergeRequestLastCommit)),
+                                           booleanParam(name: 'eNB_mergeRequest', value: true),
+                                           string(name: 'eNB_TargetBranch', value: String.valueOf(env.gitlabTargetBranch))
+                                       ]
+                                }
+                            } else {
+                                gitlabCommitStatus(name: "Test-Mono-FDD-Band13") {
+                                    build job: 'eNB-CI-MONO-FDD-Band13-B210',
+                                       parameters: [
+                                           string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
+                                           string(name: 'eNB_Branch', value: String.valueOf(GIT_BRANCH)),
+                                           string(name: 'eNB_CommitID', value: String.valueOf(GIT_COMMIT)),
+                                           booleanParam(name: 'eNB_mergeRequest', value: false)
+                                       ]
+                                }
+                            }
+                        }
+                    }
+                    post {
+                        // In case of any non-success, we are retrieving the HTML report of the last completed
+                        // slave job.
+                        // The only drop-back is that we may retrieve the HTML report of a previous build
+                        always {
+                            script {
+                                if (!fileExists('test_results-eNB-CI-MONO-FDD-Band13-B210.html')) {
+                                    copyArtifacts(projectName: 'eNB-CI-MONO-FDD-Band13-B210',
+                                                  filter: 'test_results*.html',
+                                                  selector: lastCompleted())
+                                    if (fileExists('test_results-eNB-CI-MONO-FDD-Band13-B210.html')) {
+                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-MONO-FDD-Band13-B210.html"
+                                        archiveArtifacts artifacts: 'test_results-eNB-CI-MONO-FDD-Band13-B210.html'
+                                    }
+                                }
+                            }
+                        }
+                        failure {
+                            script {
+                                currentBuild.result = 'FAILURE'
+                            }
+                        }
+                    }
+                }
             }
             post {
                 always {
diff --git a/ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf b/ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf
index e3d3402c1c64bd95503f5ad712f91c1772457da7..f69c5a420f71a81652a6f08ba0d92f256b6cfcf9 100644
--- a/ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf
+++ b/ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf
@@ -13,9 +13,9 @@ eNBs =
     eNB_name  =  "eNB_Eurecom_LTEBox";
 
     // Tracking area code, 0x0000 and 0xfffe are reserved values
-    tracking_area_code  =  "1";
+    tracking_area_code  = 1;
 
-    plmn_list = ( { mcc = 208; mnc = 93; mnc_length = 2;} );
+    plmn_list = ( { mcc = 208; mnc = 92; mnc_length = 2;} );
 
     tr_s_preference     = "local_mac"
 
@@ -48,10 +48,10 @@ eNBs =
       prach_zero_correlation                    = 1;
       prach_freq_offset                         = 1;
       pucch_delta_shift                         = 1;
-      pucch_nRB_CQI                             = 1;
+      pucch_nRB_CQI                             = 0;
       pucch_nCS_AN                              = 0;    
-      pucch_n1_AN                               = 32;
-      pdsch_referenceSignalPower                = -27;
+      pucch_n1_AN                               = 0;
+      pdsch_referenceSignalPower                = -24;
       pdsch_p_b                                 = 0;
       pusch_n_SB                                = 1;
       pusch_enable64QAM                         = "DISABLE";
@@ -190,7 +190,7 @@ eNBs =
           prach_freq_offset                         = 1;
 
           #PDSCH Config Common          
-          pdsch_referenceSignalPower                = -27
+          pdsch_referenceSignalPower                = -24
           pdsch_p_b                                 = 0;
 
 
@@ -208,7 +208,7 @@ eNBs =
           pucch_delta_shift                         = 1;
           pucch_nRB_CQI                             = 0;
           pucch_nCS_AN                              = 0;
-          pucch_n1_AN                               = 32;
+          pucch_n1_AN                               = 0;
 
           pusch_p0_Nominal                          = -96;
           pusch_alpha                               = "AL1";
@@ -262,7 +262,7 @@ eNBs =
           n1PUCCH_AN_InfoList_r13 = 
           (
               {
-                  pucch_info_value = 0;
+                  pucch_info_value = 33;
               }
           );
           
@@ -360,6 +360,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
@@ -406,6 +411,7 @@ L1s = (
       {
       num_cc = 1;
       tr_n_preference = "local_mac";
+      prach_dtx_threshold = 200;
       }  
 );
 
@@ -417,12 +423,31 @@ RUs = (
         att_tx         = 0
         att_rx         = 0;
         bands          = [13];
-        max_pdschReferenceSignalPower = -27;
-        max_rxgain                    = 125;
+        max_pdschReferenceSignalPower = -24;
+        max_rxgain                    = 110;
         eNB_instances  = [0];
     }
 );  
 
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+NETWORK_CONTROLLER :
+{
+    FLEXRAN_ENABLED        = "no";
+    FLEXRAN_INTERFACE_NAME = "lo";
+    FLEXRAN_IPV4_ADDRESS   = "127.0.0.1";
+    FLEXRAN_PORT           = 2210;
+    FLEXRAN_CACHE          = "/mnt/oai_agent_cache";
+    FLEXRAN_AWAIT_RECONF   = "no";
+};
+
 log_config :
      {
        global_log_level                      ="info";
diff --git a/ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf b/ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf
index b6028a81524f3a745485680a9660c5632d09278e..1fc31147547a3e7aa7a0ecd7c1630025a2c434d1 100644
--- a/ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf b/ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf
index 10cbd04e9a0fbe7b3bb0202de805734ea499dcb3..2ef30ea4c2024e5f4783e99a292b6cf3dd842842 100644
--- a/ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf b/ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf
index c79dbf1ac04921d47f955a79725053cc026c6030..fbbade22f384d38ae6114c3b43d2f1d9e04f2ee0 100644
--- a/ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf b/ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf
index 2c2ca635a6d7035261f1b65a1ce30add15caae08..c119e2f1c039f7d5cf4d755dd4bee195f9735e71 100644
--- a/ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf
@@ -178,6 +178,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf b/ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf
index 4dd8c1ee22d9dd88003bf5b74dfd859f606a2a7e..a0d3ba6d06190d5392e211a0c3c7ef2380223ec3 100644
--- a/ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf
@@ -178,6 +178,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf b/ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf
index cae47b152c2129a67b5f090fc1c352035b7e0048..87beafad6bc07fe080ff6b172272434ebafb86b4 100644
--- a/ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf
@@ -178,6 +178,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/enb.band7.tm2.25PRB.usrpb210.conf b/ci-scripts/conf_files/enb.band7.tm2.25PRB.usrpb210.conf
index 4e5510b0d429b94e3c1645c3fce137be2e600210..5097a4f1457c56b71da4c20e7b6165f3c5ad899b 100644
--- a/ci-scripts/conf_files/enb.band7.tm2.25PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/enb.band7.tm2.25PRB.usrpb210.conf
@@ -181,6 +181,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/lte-fdd-basic-sim.conf b/ci-scripts/conf_files/lte-fdd-basic-sim.conf
index 594e3299db2a7862d60e778833a810cb0ec6924b..22bb6608e0182280be32305b97b6511f2b1ac231 100644
--- a/ci-scripts/conf_files/lte-fdd-basic-sim.conf
+++ b/ci-scripts/conf_files/lte-fdd-basic-sim.conf
@@ -178,6 +178,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
 
diff --git a/ci-scripts/conf_files/lte-tdd-basic-sim.conf b/ci-scripts/conf_files/lte-tdd-basic-sim.conf
index da330d2379576389ea3dede669c12a8486a6e89b..a376f45453a94f2cdcbd283ed1f6b88f24d49c84 100644
--- a/ci-scripts/conf_files/lte-tdd-basic-sim.conf
+++ b/ci-scripts/conf_files/lte-tdd-basic-sim.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf b/ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf
index 285b7eaf9f54a4f3f0f6b636936b5eaaa7efb48b..d39f1e062064742373b0886fb071fb370246220d 100644
--- a/ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf
+++ b/ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf
@@ -144,6 +144,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf b/ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf
index 62e7fb48a445d0b508bf1cdcc7ff78caf0afad3d..0ae17356de40bd59002d4c66af947e24ed16bc3d 100644
--- a/ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf
+++ b/ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf
@@ -144,6 +144,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf b/ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf
index f99b701b8e1aa4770aed9ace72ad23b103a408a7..c58f05c82f5ca41c25adf6811d838a7c321b49b6 100644
--- a/ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf
+++ b/ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf
@@ -144,6 +144,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf b/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf
index 6c80a4f7cf0d14817d3e911192e395993ab8d69c..393588064b574e6363189c47794f0a6f705c0490 100644
--- a/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf
@@ -181,6 +181,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf b/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf
index f4be50810c431a608f7b5732c3337201d2140f70..7c2ab85186073b54d854bb7f49935ace48b0d51f 100644
--- a/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf
@@ -181,6 +181,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf b/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf
index 48c8370b4b25399b465d6be0e787e6c669d00eaf..77019a466e4156303ceca92b727551fd13c7e0ba 100644
--- a/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf
+++ b/ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf
@@ -181,6 +181,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf b/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
index c2a86f079e983672a2fcf8949e211d6862d00b94..40fba82f9c2c1910d7ff5284e0a38a7680a23266 100644
--- a/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
+++ b/ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf
@@ -179,6 +179,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "ens3";
diff --git a/ci-scripts/main.py b/ci-scripts/main.py
index 6fa3ae2f246b483a6f3d7a7c293626904de1e962..5b1dfd89018a6cba19cdb4d73cd75bec06741922 100644
--- a/ci-scripts/main.py
+++ b/ci-scripts/main.py
@@ -100,6 +100,8 @@ class SSHConnection():
 		self.Initialize_eNB_args = ''
 		self.eNBLogFile = ''
 		self.eNB_instance = ''
+		self.eNBOptions = ''
+		self.rruOptions = ''
 		self.ping_args = ''
 		self.ping_packetloss_threshold = ''
 		self.iperf_args = ''
@@ -123,6 +125,7 @@ class SSHConnection():
 		self.eNBOsVersion = ''
 		self.eNBKernelVersion = ''
 		self.eNBUhdVersion = ''
+		self.eNBUsrpBoard = ''
 		self.eNBCpuNb = ''
 		self.eNBCpuModel = ''
 		self.eNBCpuMHz = ''
@@ -408,14 +411,10 @@ class SSHConnection():
 				self.command('echo $USER; nohup sudo tshark -f "host ' + self.eNBIPAddress +'" -i ' + eth_interface + ' -w /tmp/enb_' + self.testCase_id + '_s1log.pcap > /tmp/tshark.log 2>&1 &', self.EPCUserName, 5)
 			self.close()
 		self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword)
-		self.command('echo ' + self.eNBPassword + ' | sudo -S uhd_find_devices', '\$', 5)
-		result = re.search('type: b200', str(self.ssh.before))
-		if result is not None:
-			logging.debug('Found a B2xx device --> resetting it')
-			self.command('echo ' + self.eNBPassword + ' | sudo -S sudo b2xx_fx3_utils --reset-device', '\$', 5)
 		self.command('cd ' + self.eNBSourceCodePath, '\$', 5)
 		# Initialize_eNB_args usually start with -O and followed by the location in repository
 		full_config_file = self.Initialize_eNB_args.replace('-O ','')
+		extra_options = ''
 		extIdx = full_config_file.find('.conf')
 		if (extIdx > 0):
 			extra_options = full_config_file[extIdx + 5:]
@@ -436,6 +435,16 @@ class SSHConnection():
 		result = re.search('rru', str(config_file))
 		if result is not None:
 			rruCheck = True
+		# do not reset board twice in IF4.5 case
+		result = re.search('rru|enb', str(config_file))
+		if result is not None:
+			self.command('echo ' + self.eNBPassword + ' | sudo -S uhd_find_devices', '\$', 5)
+			result = re.search('type: b200', str(self.ssh.before))
+			if result is not None:
+				logging.debug('Found a B2xx device --> resetting it')
+				self.command('echo ' + self.eNBPassword + ' | sudo -S sudo b2xx_fx3_utils --reset-device', '\$', 5)
+				# Reloading FGPA bin firmware
+				self.command('echo ' + self.eNBPassword + ' | sudo -S uhd_find_devices', '\$', 5)
 		# Make a copy and adapt to EPC / eNB IP addresses
 		self.command('cp ' + full_config_file + ' ' + ci_full_config_file, '\$', 5)
 		self.command('sed -i -e \'s/CI_MME_IP_ADDR/' + self.EPCIPAddress + '/\' ' + ci_full_config_file, '\$', 2);
@@ -449,6 +458,8 @@ class SSHConnection():
 		self.command('echo ' + self.eNBPassword + ' | sudo -S -E daemon --inherit --unsafe --name=enb' + str(self.eNB_instance) + '_daemon --chdir=' + self.eNBSourceCodePath + '/cmake_targets -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '.log ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5)
 		if not rruCheck:
 			self.eNBLogFile = 'enb_' + self.testCase_id + '.log'
+			if extra_options != '':
+				self.eNBOptions = extra_options
 		time.sleep(6)
 		doLoop = True
 		loopCounter = 10
@@ -487,6 +498,8 @@ class SSHConnection():
 					time.sleep(6)
 				else:
 					doLoop = False
+					if rruCheck and extra_options != '':
+						self.rruOptions = extra_options
 					self.CreateHtmlTestRow('-O ' + config_file + extra_options, 'OK', ALL_PROCESSES_OK)
 					logging.debug('\u001B[1m Initialize eNB Completed\u001B[0m')
 
@@ -609,21 +622,150 @@ class SSHConnection():
 		time.sleep(4)
 		# We should check if we register
 		count = 0
-		while count < 3:
+		attach_cnt = 0
+		attach_status = False
+		while count < 5:
 			self.command('AT+CEREG?', 'OK', 5)
-			result = re.search('CEREG: 2,(?P<state>[0-9\-]+)', str(self.ssh.before))
+			result = re.search('CEREG: 2,(?P<state>[0-9\-]+),', str(self.ssh.before))
 			if result is not None:
 				mDataConnectionState = int(result.group('state'))
 				if mDataConnectionState is not None:
-					logging.debug('+CEREG: 2,' + str(mDataConnectionState))
+					if mDataConnectionState == 1:
+						count = 10
+						attach_status = True
+						result = re.search('CEREG: 2,1,"(?P<networky>[0-9A-Z]+)","(?P<networkz>[0-9A-Z]+)"', str(self.ssh.before))
+						if result is not None:
+							networky = result.group('networky')
+							networkz = result.group('networkz')
+							logging.debug('\u001B[1m CAT-M module attached to eNB (' + str(networky) + '/' + str(networkz) + ')\u001B[0m')
+						else:
+							logging.debug('\u001B[1m CAT-M module attached to eNB\u001B[0m')
+					else:
+						logging.debug('+CEREG: 2,' + str(mDataConnectionState))
+						attach_cnt = attach_cnt + 1
 			else:
 				logging.debug(str(self.ssh.before))
+				attach_cnt = attach_cnt + 1
 			count = count + 1
 			time.sleep(1)
+		if attach_status:
+			self.command('AT+CESQ', 'OK', 5)
+			result = re.search('CESQ: 99,99,255,255,(?P<rsrq>[0-9]+),(?P<rsrp>[0-9]+)', str(self.ssh.before))
+			if result is not None:
+				nRSRQ = int(result.group('rsrq'))
+				nRSRP = int(result.group('rsrp'))
+				if (nRSRQ is not None) and (nRSRP is not None):
+					logging.debug('    RSRQ = ' + str(-20+(nRSRQ/2)) + ' dB')
+					logging.debug('    RSRP = ' + str(-140+nRSRP) + ' dBm')
 		self.close()
 		self.picocom_closure = False
-		self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK)
+		html_queue = SimpleQueue()
 		self.checkDevTTYisUnlocked()
+		if attach_status:
+			html_cell = '<pre style="background-color:white">CAT-M module\nAttachment Completed in ' + str(attach_cnt+4) + ' seconds'
+			if (nRSRQ is not None) and (nRSRP is not None):
+				html_cell += '\n   RSRQ = ' + str(-20+(nRSRQ/2)) + ' dB'
+				html_cell += '\n   RSRP = ' + str(-140+nRSRP) + ' dBm</pre>'
+			else:
+				html_cell += '</pre>'
+			html_queue.put(html_cell)
+			self.CreateHtmlTestRowQueue('N/A', 'OK', 1, html_queue)
+		else:
+			html_cell = '<pre style="background-color:white">CAT-M module\nAttachment Failed</pre>'
+			html_queue.put(html_cell)
+			self.CreateHtmlTestRowQueue('N/A', 'KO', 1, html_queue)
+
+	def PingCatM(self):
+		if self.EPCIPAddress == '' or self.EPCUserName == '' or self.EPCPassword == '' or self.EPCSourceCodePath == '':
+			Usage()
+			sys.exit('Insufficient Parameter')
+		initialize_eNB_flag = False
+		pStatus = self.CheckProcessExist(initialize_eNB_flag)
+		if (pStatus < 0):
+			self.CreateHtmlTestRow(self.ping_args, 'KO', pStatus)
+			self.CreateHtmlTabFooter(False)
+			sys.exit(1)
+		try:
+			statusQueue = SimpleQueue()
+			lock = Lock()
+			self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
+			self.command('cd ' + self.EPCSourceCodePath, '\$', 5)
+			self.command('cd scripts', '\$', 5)
+			if re.match('OAI', self.EPCType, re.IGNORECASE):
+				logging.debug('Using the OAI EPC HSS: not implemented yet')
+				self.CreateHtmlTestRow(self.ping_args, 'KO', pStatus)
+				self.CreateHtmlTabFooter(False)
+				sys.exit(1)
+			else:
+				self.command('egrep --color=never "Allocated ipv4 addr" /opt/ltebox/var/log/xGwLog.0', '\$', 5)
+				result = re.search('Allocated ipv4 addr: (?P<ipaddr>[0-9\.]+) from Pool', str(self.ssh.before))
+				if result is not None:
+					moduleIPAddr = result.group('ipaddr')
+				else:
+					return
+			ping_time = re.findall("-c (\d+)",str(self.ping_args))
+			device_id = 'catm'
+			ping_status = self.command('stdbuf -o0 ping ' + self.ping_args + ' ' + str(moduleIPAddr) + ' 2>&1 | stdbuf -o0 tee -a ping_' + self.testCase_id + '_' + device_id + '.log', '\$', int(ping_time[0])*1.5)
+			# TIMEOUT CASE
+			if ping_status < 0:
+				message = 'Ping with UE (' + str(moduleIPAddr) + ') crashed due to TIMEOUT!'
+				logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m')
+				self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message)
+				return
+			result = re.search(', (?P<packetloss>[0-9\.]+)% packet loss, time [0-9\.]+ms', str(self.ssh.before))
+			if result is None:
+				message = 'Packet Loss Not Found!'
+				logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m')
+				self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message)
+				return
+			packetloss = result.group('packetloss')
+			if float(packetloss) == 100:
+				message = 'Packet Loss is 100%'
+				logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m')
+				self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message)
+				return
+			result = re.search('rtt min\/avg\/max\/mdev = (?P<rtt_min>[0-9\.]+)\/(?P<rtt_avg>[0-9\.]+)\/(?P<rtt_max>[0-9\.]+)\/[0-9\.]+ ms', str(self.ssh.before))
+			if result is None:
+				message = 'Ping RTT_Min RTT_Avg RTT_Max Not Found!'
+				logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m')
+				self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message)
+				return
+			rtt_min = result.group('rtt_min')
+			rtt_avg = result.group('rtt_avg')
+			rtt_max = result.group('rtt_max')
+			pal_msg = 'Packet Loss : ' + packetloss + '%'
+			min_msg = 'RTT(Min)    : ' + rtt_min + ' ms'
+			avg_msg = 'RTT(Avg)    : ' + rtt_avg + ' ms'
+			max_msg = 'RTT(Max)    : ' + rtt_max + ' ms'
+			lock.acquire()
+			logging.debug('\u001B[1;37;44m ping result (' + moduleIPAddr + ') \u001B[0m')
+			logging.debug('\u001B[1;34m    ' + pal_msg + '\u001B[0m')
+			logging.debug('\u001B[1;34m    ' + min_msg + '\u001B[0m')
+			logging.debug('\u001B[1;34m    ' + avg_msg + '\u001B[0m')
+			logging.debug('\u001B[1;34m    ' + max_msg + '\u001B[0m')
+			qMsg = pal_msg + '\n' + min_msg + '\n' + avg_msg + '\n' + max_msg
+			packetLossOK = True
+			if packetloss is not None:
+				if float(packetloss) > float(self.ping_packetloss_threshold):
+					qMsg += '\nPacket Loss too high'
+					logging.debug('\u001B[1;37;41m Packet Loss too high \u001B[0m')
+					packetLossOK = False
+				elif float(packetloss) > 0:
+					qMsg += '\nPacket Loss is not 0%'
+					logging.debug('\u001B[1;30;43m Packet Loss is not 0% \u001B[0m')
+			lock.release()
+			self.close()
+			html_cell = '<pre style="background-color:white">CAT-M module\nIP Address  : ' + moduleIPAddr + '\n' + qMsg + '</pre>'
+			statusQueue.put(html_cell)
+			if (packetLossOK):
+				self.CreateHtmlTestRowQueue(self.ping_args, 'OK', 1, statusQueue)
+			else:
+				self.CreateHtmlTestRowQueue(self.ping_args, 'KO', 1, statusQueue)
+				self.AutoTerminateUEandeNB()
+				self.CreateHtmlTabFooter(False)
+				sys.exit(1)
+		except:
+			os.kill(os.getppid(),signal.SIGUSR1)
 
 	def AttachUE_common(self, device_id, statusQueue, lock):
 		try:
@@ -1620,7 +1762,18 @@ class SSHConnection():
 		uciStatMsgCount = 0
 		pdcpFailure = 0
 		ulschFailure = 0
+		self.htmleNBFailureMsg = ''
 		for line in enb_log_file.readlines():
+			if self.rruOptions != '':
+				res1 = re.search('max_rxgain (?P<requested_option>[0-9]+)', self.rruOptions)
+				res2 = re.search('max_rxgain (?P<applied_option>[0-9]+)',  str(line))
+				if res1 is not None and res2 is not None:
+					requested_option = int(res1.group('requested_option'))
+					applied_option = int(res2.group('applied_option'))
+					if requested_option == applied_option:
+						self.htmleNBFailureMsg += '<span class="glyphicon glyphicon-ok-circle"></span> Command line option(s) correctly applied <span class="glyphicon glyphicon-arrow-right"></span> ' + self.rruOptions + '\n\n'
+					else:
+						self.htmleNBFailureMsg += '<span class="glyphicon glyphicon-ban-circle"></span> Command line option(s) NOT applied <span class="glyphicon glyphicon-arrow-right"></span> ' + self.rruOptions + '\n\n'
 			result = re.search('[Ss]egmentation [Ff]ault', str(line))
 			if result is not None:
 				foundSegFault = True
@@ -1676,7 +1829,6 @@ class SSHConnection():
 			if result is not None:
 				rachCanceledProcedure += 1
 		enb_log_file.close()
-		self.htmleNBFailureMsg = ''
 		if uciStatMsgCount > 0:
 			statMsg = 'eNB showed ' + str(uciStatMsgCount) + ' "uci->stat" message(s)'
 			logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m')
@@ -1974,6 +2126,7 @@ class SSHConnection():
 			self.eNBOsVersion = 'Ubuntu 16.04.5 LTS'
 			self.eNBKernelVersion = '4.15.0-45-generic'
 			self.eNBUhdVersion = '3.13.0.1-0'
+			self.eNBUsrpBoard = 'B210'
 			self.eNBCpuNb = '4'
 			self.eNBCpuModel = 'Intel(R) Core(TM) i5-6200U'
 			self.eNBCpuMHz = '2399.996 MHz'
@@ -1997,6 +2150,11 @@ class SSHConnection():
 		if result is not None:
 			self.eNBUhdVersion = result.group('uhd_version')
 			logging.debug('UHD Version is: ' + self.eNBUhdVersion)
+		self.command('echo ' + self.eNBPassword + ' | sudo -S uhd_find_devices', '\$', 5)
+		result = re.search('product: (?P<usrp_board>[0-9A-Za-z]+)\\\\r\\\\n', str(self.ssh.before))
+		if result is not None:
+			self.eNBUsrpBoard = result.group('usrp_board')
+			logging.debug('USRP Board  is: ' + self.eNBUsrpBoard)
 		self.command('lscpu', '\$', 5)
 		result = re.search('CPU\(s\): *(?P<nb_cpus>[0-9]+).*Model name: *(?P<model>[a-zA-Z0-9\-\_\.\ \(\)]+).*CPU MHz: *(?P<cpu_mhz>[0-9\.]+)', str(self.ssh.before))
 		if result is not None:
@@ -2174,7 +2332,7 @@ class SSHConnection():
 			self.htmlFile.write('  <p></p>\n')
 			self.htmlFile.write('  <table class="table table-condensed">\n')
 			self.htmlFile.write('      <tr>\n')
-			self.htmlFile.write('        <th colspan=6>eNB Server Characteristics</th>\n')
+			self.htmlFile.write('        <th colspan=8>eNB Server Characteristics</th>\n')
 			self.htmlFile.write('      </tr>\n')
 			self.htmlFile.write('      <tr>\n')
 			self.htmlFile.write('        <td>OS Version</td>\n')
@@ -2183,6 +2341,8 @@ class SSHConnection():
 			self.htmlFile.write('        <td><span class="label label-default">' + self.eNBKernelVersion + '</span></td>\n')
 			self.htmlFile.write('        <td>UHD Version</td>\n')
 			self.htmlFile.write('        <td><span class="label label-default">' + self.eNBUhdVersion + '</span></td>\n')
+			self.htmlFile.write('        <td>USRP Board</td>\n')
+			self.htmlFile.write('        <td><span class="label label-default">' + self.eNBUsrpBoard + '</span></td>\n')
 			self.htmlFile.write('      </tr>\n')
 			self.htmlFile.write('      <tr>\n')
 			self.htmlFile.write('        <td>Nb CPUs</td>\n')
@@ -2191,13 +2351,15 @@ class SSHConnection():
 			self.htmlFile.write('        <td><span class="label label-default">' + self.eNBCpuModel + '</span></td>\n')
 			self.htmlFile.write('        <td>CPU Frequency</td>\n')
 			self.htmlFile.write('        <td><span class="label label-default">' + self.eNBCpuMHz + '</span></td>\n')
+			self.htmlFile.write('        <td></td>\n')
+			self.htmlFile.write('        <td></td>\n')
 			self.htmlFile.write('      </tr>\n')
 			self.htmlFile.write('      <tr>\n')
-			self.htmlFile.write('        <th colspan=4 bgcolor = "#33CCFF">Final Status</th>\n')
+			self.htmlFile.write('        <th colspan=5 bgcolor = "#33CCFF">Final Status</th>\n')
 			if passStatus:
-				self.htmlFile.write('        <th colspan=2 bgcolor="green"><font color="white">PASS <span class="glyphicon glyphicon-ok"></span></font></th>\n')
+				self.htmlFile.write('        <th colspan=3 bgcolor="green"><font color="white">PASS <span class="glyphicon glyphicon-ok"></span></font></th>\n')
 			else:
-				self.htmlFile.write('        <th colspan=2 bgcolor="red"><font color="white">FAIL <span class="glyphicon glyphicon-remove"></span> </font></th>\n')
+				self.htmlFile.write('        <th colspan=3 bgcolor="red"><font color="white">FAIL <span class="glyphicon glyphicon-remove"></span> </font></th>\n')
 			self.htmlFile.write('      </tr>\n')
 			self.htmlFile.write('  </table>\n')
 			self.htmlFile.write('  <p></p>\n')
@@ -2331,7 +2493,7 @@ def Usage():
 	print('------------------------------------------------------------')
 
 def CheckClassValidity(action,id):
-	if action != 'Build_eNB' and action != 'Initialize_eNB' and action != 'Terminate_eNB' and action != 'Initialize_UE' and action != 'Terminate_UE' and action != 'Attach_UE' and action != 'Detach_UE' and action != 'Ping' and action != 'Iperf' and action != 'Reboot_UE' and action != 'Initialize_HSS' and action != 'Terminate_HSS' and action != 'Initialize_MME' and action != 'Terminate_MME' and action != 'Initialize_SPGW' and action != 'Terminate_SPGW'  and action != 'Initialize_CatM_module' and action != 'Terminate_CatM_module' and action != 'Attach_CatM_module' and action != 'Detach_CatM_module' and action != 'IdleSleep':
+	if action != 'Build_eNB' and action != 'Initialize_eNB' and action != 'Terminate_eNB' and action != 'Initialize_UE' and action != 'Terminate_UE' and action != 'Attach_UE' and action != 'Detach_UE' and action != 'Ping' and action != 'Iperf' and action != 'Reboot_UE' and action != 'Initialize_HSS' and action != 'Terminate_HSS' and action != 'Initialize_MME' and action != 'Terminate_MME' and action != 'Initialize_SPGW' and action != 'Terminate_SPGW'  and action != 'Initialize_CatM_module' and action != 'Terminate_CatM_module' and action != 'Attach_CatM_module' and action != 'Detach_CatM_module' and action != 'Ping_CatM_module' and action != 'IdleSleep':
 		logging.debug('ERROR: test-case ' + id + ' has wrong class ' + action)
 		return False
 	return True
@@ -2358,7 +2520,7 @@ def GetParametersFromXML(action):
 		else:
 			SSH.nbMaxUEtoAttach = int(nbMaxUEtoAttach)
 
-	if action == 'Ping':
+	if action == 'Ping' or action == 'Ping_CatM_module':
 		SSH.ping_args = test.findtext('ping_args')
 		SSH.ping_packetloss_threshold = test.findtext('ping_packetloss_threshold')
 
@@ -2656,6 +2818,8 @@ elif re.match('^TesteNB$', mode, re.IGNORECASE):
 				SSH.AttachCatM()
 			elif action == 'Detach_CatM_module':
 				SSH.TerminateCatM()
+			elif action == 'Ping_CatM_module':
+				SSH.PingCatM()
 			elif action == 'Ping':
 				SSH.Ping()
 			elif action == 'Iperf':
diff --git a/ci-scripts/xml_files/enb_usrp210_band13_build.xml b/ci-scripts/xml_files/enb_usrp210_band13_build.xml
new file mode 100644
index 0000000000000000000000000000000000000000..24283a52d0b38508ab7c148e664c1fb26b7020bb
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band13_build.xml
@@ -0,0 +1,55 @@
+<!--
+
+ Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The OpenAirInterface Software Alliance licenses this file to You under
+ the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ except in compliance with the License.
+ You may obtain a copy of the License at
+
+      http://www.openairinterface.org/?page_id=698
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ For more information about the OpenAirInterface (OAI) Software Alliance:
+      contact@openairinterface.org
+
+-->
+<testCaseList>
+	<htmlTabRef>build-tab</htmlTabRef>
+	<htmlTabName>Build</htmlTabName>
+	<htmlTabIcon>wrench</htmlTabIcon>
+	<TestCaseRequestedList>
+ 010101
+ 050101 060101 070101
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+	<testCase id="010101">
+		<class>Build_eNB</class>
+		<desc>Build eNB (USRP)</desc>
+		<Build_eNB_args>-w USRP -c --eNB</Build_eNB_args>
+	</testCase>
+
+        <testCase id="050101">
+		<class>Initialize_HSS</class>
+		<desc>Initialize HSS</desc>
+        </testCase>
+
+	<testCase id="060101">
+		<class>Initialize_MME</class>
+		<desc>Initialize MME</desc>
+	</testCase>
+
+	<testCase id="070101">
+		<class>Initialize_SPGW</class>
+		<desc>Initialize SPGW</desc>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrp210_band13_epc_closure.xml b/ci-scripts/xml_files/enb_usrp210_band13_epc_closure.xml
new file mode 100644
index 0000000000000000000000000000000000000000..07fb6951f8e99a35cabd2ee4e48232d2bd035f41
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band13_epc_closure.xml
@@ -0,0 +1,47 @@
+<!--
+
+ Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The OpenAirInterface Software Alliance licenses this file to You under
+ the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ except in compliance with the License.
+ You may obtain a copy of the License at
+
+      http://www.openairinterface.org/?page_id=698
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ For more information about the OpenAirInterface (OAI) Software Alliance:
+      contact@openairinterface.org
+
+-->
+<testCaseList>
+	<htmlTabRef>epc-closure</htmlTabRef>
+	<htmlTabName>EPC-Closure</htmlTabName>
+	<htmlTabIcon>log-out</htmlTabIcon>
+	<TestCaseRequestedList>
+ 050201 060201 070201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList></TestCaseExclusionList>
+
+	<testCase id="050201">
+		<class>Terminate_HSS</class>
+		<desc>Terminate HSS</desc>
+	</testCase>
+
+	<testCase id="060201">
+		<class>Terminate_MME</class>
+		<desc>Terminate MME</desc>
+	</testCase>
+
+	<testCase id="070201">
+		<class>Terminate_SPGW</class>
+		<desc>Terminate SPGW</desc>
+	</testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/enb_usrp210_band13_test_10mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band13_test_10mhz_tm1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..ad543403d6cf1de3189110c69841d48d33ee50a6
--- /dev/null
+++ b/ci-scripts/xml_files/enb_usrp210_band13_test_10mhz_tm1.xml
@@ -0,0 +1,78 @@
+<!--
+
+ Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The OpenAirInterface Software Alliance licenses this file to You under
+ the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ except in compliance with the License.
+ You may obtain a copy of the License at
+
+      http://www.openairinterface.org/?page_id=698
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ For more information about the OpenAirInterface (OAI) Software Alliance:
+      contact@openairinterface.org
+
+-->
+<testCaseList>
+	<htmlTabRef>test-10-tm1</htmlTabRef>
+	<htmlTabName>Test-10MHz-TM1</htmlTabName>
+	<htmlTabIcon>tasks</htmlTabIcon>
+	<TestCaseRequestedList>
+ 040102
+ 030121 000001 040302 000001 040502 000001 040402 040202 000001 030201
+	</TestCaseRequestedList>
+	<TestCaseExclusionList>
+	</TestCaseExclusionList>
+
+        <testCase id="000001">
+                <class>IdleSleep</class>
+                <desc>Waiting for a moment...</desc>
+                <idle_sleep_time_in_sec>15</idle_sleep_time_in_sec>
+        </testCase>
+
+	<testCase id="030121">
+		<class>Initialize_eNB</class>
+		<desc>Initialize eNB (FDD/Band13/10MHz)</desc>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf</Initialize_eNB_args>
+	</testCase>
+
+	<testCase id="030201">
+		<class>Terminate_eNB</class>
+		<desc>Terminate eNB</desc>
+	</testCase>
+
+        <testCase id="040102">
+                <class>Initialize_CatM_module</class>
+                <desc>Initialize CAT-M Module</desc>
+        </testCase>
+
+        <testCase id="040202">
+                <class>Terminate_CatM_module</class>
+                <desc>Terminate CAT-M Module</desc>
+        </testCase>
+
+        <testCase id="040302">
+                <class>Attach_CatM_module</class>
+                <desc>Attach CAT-M Module</desc>
+        </testCase>
+
+        <testCase id="040402">
+                <class>Detach_CatM_module</class>
+                <desc>Detach CAT-M Module</desc>
+        </testCase>
+
+        <testCase id="040502">
+                <class>Ping_CatM_module</class>
+                <desc>ping (10MHz - 20 sec)</desc>
+                <ping_args>-c 20</ping_args>
+                <ping_packetloss_threshold>5</ping_packetloss_threshold>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
index 3a877ea3c3fe02b8652391c5fcd21be4177f9675..d3b456187629429c2945c7f5fb42e71914f30d31 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
@@ -34,7 +34,7 @@
 	<testCase id="030104">
 		<class>Initialize_eNB</class>
 		<desc>Initialize RRU (TDD/Band40)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf --RUs.[0].max_rxgain 125</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 	
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
index 6bc37db17a1f1e7d0540bdb8454a9e0aed8dc770..7ff1493d1c97cd314bceac1aaf8535b2a5c90262 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
@@ -34,7 +34,7 @@
 	<testCase id="030114">
 		<class>Initialize_eNB</class>
 		<desc>Initialize RRU (TDD/Band40)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf --RUs.[0].max_rxgain 120</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 	
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
index b0501e9875fea9822335db9a0e8d07a01dda97ba..1db56d10d2deaba848477f13d30a57515d261252 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
@@ -34,7 +34,7 @@
 	<testCase id="030101">
 		<class>Initialize_eNB</class>
 		<desc>Initialize RRU (FDD/Band7)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf --RUs.[0].max_rxgain 125</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
index 88fb30b840caaf8f5fe686b19b59b6d55e045227..d60427c988b98ca8424edfc7ec446fa5242ad71f 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
@@ -34,7 +34,7 @@
 	<testCase id="030111">
 		<class>Initialize_eNB</class>
 		<desc>Initialize RRU (FDD/Band7)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf --RUs.[0].max_rxgain 120</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 
diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index 3f2041089fa9cff825952499f8cc70d27ad38fc7..95fc2cc1506e0861ebf7f8120fd8c4e762455230 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -471,6 +471,7 @@ add_library(X2AP_ENB
   ${X2AP_DIR}/x2ap_eNB_management_procedures.c
   ${X2AP_DIR}/x2ap_eNB_generate_messages.c
   ${X2AP_DIR}/x2ap_ids.c
+  ${X2AP_DIR}/x2ap_timers.c
  )
 add_dependencies(X2AP_ENB rrc_flag x2_flag)
 
diff --git a/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.10MHz.conf b/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.10MHz.conf
index 398b76388898bd51b8814bd036ade8d45520a6cd..d99ca88807d0fb16a714f3092aad74e9172e6129 100644
--- a/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.10MHz.conf
+++ b/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.10MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth6";
diff --git a/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.20MHz.conf b/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.20MHz.conf
index 46b648473742a635aba7181cae46388b6d090372..86c54a82f710a602d371c6377719e3237f6a248d 100644
--- a/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.20MHz.conf
+++ b/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.20MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth6";
diff --git a/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.5MHz.conf b/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.5MHz.conf
index 93b82773e6461939d1dc6e9cb74e49e428fc2c18..dad0ab5a2301dcef69e43366bdf150a548760195 100644
--- a/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.5MHz.conf
+++ b/cmake_targets/autotests/v2/config/enb.band38.tm1.usrpb210.tdd.5MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth6";
diff --git a/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.10MHz.conf b/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.10MHz.conf
index b412b00e523074bbe34f547c76d2978572fdb451..369b6184fd8f46460fbe26ff74a0ba2927f284d6 100644
--- a/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.10MHz.conf
+++ b/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.10MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.20MHz.conf b/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.20MHz.conf
index f0d688903a6894508928af20ac76002badb57798..14ae99c80ca81be2c5dc5df9e25009e8a03fd122 100644
--- a/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.20MHz.conf
+++ b/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.20MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.5MHz.conf b/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.5MHz.conf
index 929c91fffbdb6c1a2b4a00db9208c760f23bf8b6..9302ac7c5828ea2cafe367336a0df1be19008919 100644
--- a/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.5MHz.conf
+++ b/cmake_targets/autotests/v2/config/enb.band7.tm1.usrpb210.fdd.5MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.10MHz.conf b/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.10MHz.conf
index 98358eb269bd7305c7a94c28e3278ae4f49a3e29..0ae9e659b41f300942f7b466ba739b690038c45c 100644
--- a/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.10MHz.conf
+++ b/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.10MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.20MHz.conf b/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.20MHz.conf
index bc31e051e57db834520b1bc29ccf60fac7ce97d7..1d22c19ec872f758658d7706f106f6a8590b0864 100644
--- a/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.20MHz.conf
+++ b/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.20MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.5MHz.conf b/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.5MHz.conf
index 2cfc227e67aeef229152a853908bbb9648da88be..3f35175ff49af72a4fa64ab8f37d45ea42f342be 100644
--- a/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.5MHz.conf
+++ b/cmake_targets/autotests/v2/config/rcc.band7.tm1.if4p5.5MHz.conf
@@ -141,6 +141,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.10MHz.udp.usrpb210.conf b/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.10MHz.udp.usrpb210.conf
index 9b135a94982c8214a6bfc17270d04c4e1b815cab..0a6a8cccc69087e49bc70f8043bd7e8e91e6a3c1 100644
--- a/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.10MHz.udp.usrpb210.conf
+++ b/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.10MHz.udp.usrpb210.conf
@@ -143,6 +143,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth3";
diff --git a/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.20MHz.udp.usrpb210.conf b/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.20MHz.udp.usrpb210.conf
index 9f84057299cd8ce552598399e85d52edd45c142e..7ffdd063a659fa8c7be540b7dc35498de93a036c 100644
--- a/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.20MHz.udp.usrpb210.conf
+++ b/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.20MHz.udp.usrpb210.conf
@@ -143,6 +143,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth3";
diff --git a/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.5MHz.udp.usrpb210.conf b/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.5MHz.udp.usrpb210.conf
index 7197e93322e56c63a6b77abd0a4256bdc6fdaeee..409fa49910153f92fbde234666dcbe5a293c95c9 100644
--- a/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.5MHz.udp.usrpb210.conf
+++ b/cmake_targets/autotests/v2/config/rru.band7.tm1.if4p5.5MHz.udp.usrpb210.conf
@@ -143,6 +143,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth3";
diff --git a/configuration/bladeRF/enb-band7-5mhz.conf b/configuration/bladeRF/enb-band7-5mhz.conf
index 6e07b8d9499e8cfb2ca60f0d3da91d3dbb92348a..127c8654227d8e3a40b410fa7ea246bbbe440210 100644
--- a/configuration/bladeRF/enb-band7-5mhz.conf
+++ b/configuration/bladeRF/enb-band7-5mhz.conf
@@ -181,6 +181,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES : 
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth1";
diff --git a/doc/FEATURE_SET.md b/doc/FEATURE_SET.md
index 29163fd83208a670cb466769430d9257990181e1..3dd3605fb3cfe327d83a329a2981496028ed2faf 100644
--- a/doc/FEATURE_SET.md
+++ b/doc/FEATURE_SET.md
@@ -127,6 +127,9 @@ The X2AP layer is based on **3GPP 36.423** v14.6.0 and implements the following
  - X2 Setup Failure
  - Handover Request 
  - Handover Request Acknowledge
+ - UE Context Release
+ - X2 timers (t_reloc_prep, tx2_reloc_overall)
+ - Handover Cancel
 
 ## eNB Advanced Features ##
 
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c b/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
index cb50b7b5d3fcc5495baf34481e1bfdf8aa9df8d7..27807028439b2c8f04269d8366644f1cfb7876c8 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
@@ -86,7 +86,7 @@ int32_t lte_ul_channel_estimation(PHY_VARS_eNB *eNB,
   int32_t temp_in_ifft_0[2048*2] __attribute__((aligned(32)));
 
 
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (eNB->ulsch[UE_id]->ue_type > 0) harq_pid = 0;
   else
 #endif
diff --git a/openair1/PHY/LTE_TRANSPORT/dci.c b/openair1/PHY/LTE_TRANSPORT/dci.c
index edd063a09093639533fcc5bb9640bb757723b51c..b4b253a297648df6e0dbaa4ae91a358f7e4f9575 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci.c
@@ -71,28 +71,24 @@ void dci_encoding(uint8_t *a,
   uint8_t w[3*3*(MAX_DCI_SIZE_BITS+16)];
 #ifdef DEBUG_DCI_ENCODING
   int32_t i;
-#endif
-  // encode dci
-#ifdef DEBUG_DCI_ENCODING
   printf("Doing DCI encoding for %d bits, e %p, rnti %x, E %d\n",A,e,rnti,E);
 #endif
+  // encode dci
   memset((void *)d,LTE_NULL,96);
   ccodelte_encode(A,2,a,d+96,rnti);
 #ifdef DEBUG_DCI_ENCODING
 
   for (i=0; i<16+A; i++)
     printf("%d : (%d,%d,%d)\n",i,*(d+96+(3*i)),*(d+97+(3*i)),*(d+98+(3*i)));
-
-#endif
-#ifdef DEBUG_DCI_ENCODING
   printf("Doing DCI interleaving for %d coded bits, e %p\n",D*3,e);
 #endif
+
   RCC = sub_block_interleaving_cc(D,d+96,w);
 
-  //#ifdef DEBUG_DCI_ENCODING
+#ifdef DEBUG_DCI_ENCODING
   if (E>1000) printf("Doing DCI rate matching for %d channel bits, RCC %d, e %p\n",E,RCC,e);
+#endif
 
-  //#endif
   lte_rate_matching_cc(RCC,E,w,e);
 }
 
diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index 36cc48b14467c213548e9ae8a2ee0a0289946c88..fc05aa649124f94fa9609649b3b9bc0b20b74c10 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -300,7 +300,8 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t
   dlsch0 = eNB->dlsch[UE_id][0];
   dlsch1 = eNB->dlsch[UE_id][1];
 
-    
+  dlsch0->ue_type = 0;
+  dlsch1->ue_type = 0; 
   beamforming_mode                          = eNB->transmission_mode[(uint8_t)UE_id]<7?0:eNB->transmission_mode[(uint8_t)UE_id];
   dlsch0_harq                               = dlsch0->harq_processes[rel8->harq_process];
   dlsch0_harq->codeword                     = 0;
@@ -527,7 +528,7 @@ void fill_dci_and_dlsch(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_proc_t
 
     dlsch0->harq_mask |= (1 << rel8->harq_process);
 
-    if (rel8->rnti_type == 1) LOG_I(PHY,"DCI 1A: round %d, mcs %d, rballoc %x, rv %d, rnti %x, harq process %d\n",dlsch0_harq->round,rel8->mcs_1,rel8->resource_block_coding,rel8->redundancy_version_1,rel8->rnti,rel8->harq_process);
+    if (rel8->rnti_type == 1) LOG_D(PHY,"DCI 1A: round %d, mcs %d, rballoc %x, rv %d, rnti %x, harq process %d\n",dlsch0_harq->round,rel8->mcs_1,rel8->resource_block_coding,rel8->redundancy_version_1,rel8->rnti,rel8->harq_process);
 
     break;
   case NFAPI_DL_DCI_FORMAT_1:
@@ -1559,7 +1560,6 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dc
 
   case 10:                     // Format 6-1A
     dci_alloc->format = format6_1A;
-    dlsch0->active = 1;
     switch (fp->N_RB_DL) {
 
     case 25:
@@ -1594,7 +1594,7 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dc
       ((DCI6_1A_10MHz_t *) dci_pdu)->harq_ack_off = rel13->harq_resource_offset;
       ((DCI6_1A_10MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
 
-      LOG_I(PHY,"Frame %d, Subframe %d : Programming Format 6-1A DCI, type %d, hopping %d, narrowband %d, rballoc %x, mcs %d, rep %d, harq_pid %d, ndi %d, rv %d, TPC %d, srs_req %d, harq_ack_off %d, dci_rep r%d => %x\n",
+      LOG_D(PHY,"Frame %d, Subframe %d : Programming Format 6-1A DCI, type %d, hopping %d, narrowband %d, rballoc %x, mcs %d, rep %d, harq_pid %d, ndi %d, rv %d, TPC %d, srs_req %d, harq_ack_off %d, dci_rep r%d => %x\n",
 	    frame,subframe,
 	    ((DCI6_1A_10MHz_t *) dci_pdu)->type,
 	    ((DCI6_1A_10MHz_t *) dci_pdu)->hopping,
@@ -1630,7 +1630,6 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dc
     break;
   case 11:                     // Format 6-1B
     dci_alloc->format = format6_1B;
-    dlsch0->active = 1;
     switch (fp->N_RB_DL) {
 
     case 25:
@@ -1670,7 +1669,6 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dc
     }
   case 12:                     // Format 6-2
     dci_alloc->format = format6_2;
-    dlsch0->active = 1;
     switch (fp->N_RB_DL) {
     case 25:
       dci_alloc->dci_length = sizeof_DCI6_2_5MHz_t;
@@ -1719,12 +1717,14 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dc
   }
   AssertFatal (rel13->harq_process < 8, "ERROR: Format 6_1A: harq_pid=%d >= 8\n", rel13->harq_process);
 
+  dlsch0->ue_type = rel13->ce_mode;
+
   dlsch0_harq = dlsch0->harq_processes[rel13->harq_process];
   dlsch0_harq->codeword = 0;
 
   // printf("DCI: Setting subframe_tx for subframe %d\n",subframe);
   dlsch0->subframe_tx[(subframe + 2) % 10] = 1;
-  LOG_I(PHY,"PDSCH : resource_block_coding %x\n",rel13->resource_block_coding);
+  LOG_D(PHY,"PDSCH : resource_block_coding %x\n",rel13->resource_block_coding);
 
   conv_eMTC_rballoc (rel13->resource_block_coding, 
 		     fp->N_RB_DL, 
@@ -1768,7 +1768,7 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dc
       dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][1];
     else if (rel13->tpc == 1)  //N1A_PRB=3, get TBS from table using mcs and nb_rb=3
       dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][2];      
-    LOG_I(PHY,"TBS = %d(%d)\n",dlsch0_harq->TBS,dlsch0_harq->mcs);
+    LOG_D(PHY,"TBS = %d(%d)\n",dlsch0_harq->TBS,dlsch0_harq->mcs);
   }
   dlsch0->active = 1;
   dlsch0->harq_mask |= (1 << rel13->harq_process);
@@ -1776,11 +1776,11 @@ void fill_mdci_and_dlsch(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,mDCI_ALLOC_t *dc
   dlsch0_harq->frame    = (subframe >= 8) ? ((frame + 1) & 1023) : frame;
   dlsch0_harq->subframe = (subframe + 2) % 10;
 
-  LOG_I(PHY,"Setting DLSCH harq_ids[%d] to %d\n",dlsch0_harq->subframe,dlsch0->harq_ids[frame%2][dlsch0_harq->subframe]);
-  dlsch0->harq_ids[frame%2][dlsch0_harq->subframe] = rel13->harq_process;
+  LOG_D(PHY,"Setting DLSCH UEid %d harq_ids[%d] from %d to %d\n",UE_id,dlsch0_harq->subframe,dlsch0->harq_ids[frame%2][dlsch0_harq->subframe],rel13->harq_process);
+  dlsch0->harq_ids[dlsch0_harq->frame%2][dlsch0_harq->subframe] = rel13->harq_process;
   dlsch0_harq->pdsch_start = rel13->start_symbol;
 
-  LOG_I(PHY,"Setting DLSCH harq %d round %d to active for %d.%d\n",rel13->harq_process,dlsch0_harq->round,dlsch0_harq->frame,dlsch0_harq->subframe);
+  LOG_D(PHY,"Setting DLSCH harq %d round %d to active for %d.%d\n",rel13->harq_process,dlsch0_harq->round,dlsch0_harq->frame,dlsch0_harq->subframe);
 
   dlsch0->rnti = rel13->rnti;
 
@@ -2011,6 +2011,7 @@ void fill_ulsch(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_ulsch_pdu *ulsch_pdu
   ulsch->harq_mask |= 1 << harq_pid;
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  LOG_D(PHY,"Filling ULSCH : ue_type %d, harq_pid %d\n",ulsch->ue_type,harq_pid);
   ulsch->ue_type = ulsch_pdu->ulsch_pdu_rel13.ue_type;
   AssertFatal(harq_pid ==0 || ulsch->ue_type == NOCE, "Harq PID is not zero for BL/CE UE\n");
 
@@ -2236,7 +2237,7 @@ void fill_mpdcch_dci0 (PHY_VARS_eNB * eNB, L1_rxtx_proc_t * proc, mDCI_ALLOC_t *
       ((DCI6_0A_10MHz_t *) dci_pdu)->csi_req = cqi_req;
       ((DCI6_0A_10MHz_t *) dci_pdu)->srs_req = rel13->srs_request;
       ((DCI6_0A_10MHz_t *) dci_pdu)->dci_rep = rel13->dci_subframe_repetition_number;
-      LOG_I(PHY,"Frame %d, Subframe %d : Programming Format 6-0A DCI, type %d, hopping %d, narrowband %d, rballoc %x, mcs %d, rep %d, harq_pid %d, ndi %d, rv %d, TPC %d, csi_req %d, srs_req %d, dci_rep r%d => %x\n",
+      LOG_D(PHY,"Frame %d, Subframe %d : Programming Format 6-0A DCI, type %d, hopping %d, narrowband %d, rballoc %x, mcs %d, rep %d, harq_pid %d, ndi %d, rv %d, TPC %d, csi_req %d, srs_req %d, dci_rep r%d => %x\n",
 	    proc->frame_tx,proc->subframe_tx,
 	    ((DCI6_0A_10MHz_t *) dci_pdu)->type,
 	    ((DCI6_0A_10MHz_t *) dci_pdu)->hopping,
diff --git a/openair1/PHY/LTE_TRANSPORT/edci.c b/openair1/PHY/LTE_TRANSPORT/edci.c
index 41016bdb6574b29234f0bac622bdb60fd3c30861..f1b5c356c7b57fae6f155f51d2dd6100b95f3181 100644
--- a/openair1/PHY/LTE_TRANSPORT/edci.c
+++ b/openair1/PHY/LTE_TRANSPORT/edci.c
@@ -84,7 +84,7 @@ void mpdcch_scrambling(LTE_DL_FRAME_PARMS * frame_parms, mDCI_ALLOC_t * mdci, ui
 
   // rule for BL/CE UEs from Section 6.8.B2 in 36.211
   x2 = ((((j0 + j) * Nacc) % 10) << 9) + mdci->dmrs_scrambling_init;
-  LOG_I(PHY,"MPDCCH cinit = %x (mdci->dmrs_scrambling_init = %d), scrambling %d encoded DCI bits\n",
+  LOG_D(PHY,"MPDCCH cinit = %x (mdci->dmrs_scrambling_init = %d), scrambling %d encoded DCI bits\n",
 	x2,mdci->dmrs_scrambling_init,length);
   for (n = 0; n < length; n++) {
     if ((n & 0x1f) == 0) {
@@ -109,7 +109,7 @@ void init_mpdcch5ss1tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB * eNB)
 {
   int             l, k, kmod, re=0;
 
-  LOG_I(PHY, "Inititalizing mpdcchss15tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
+  LOG_D(PHY, "Inititalizing mpdcchss15tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
 
   for (l = 1; l < 14; l++) {
     for (k = 0; k < 72; k++) {
@@ -117,7 +117,6 @@ void init_mpdcch5ss1tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB * eNB)
       if (((l != 5) && (l != 6) && (l != 12) && (l != 13)) || (kmod == 2) || (kmod == 3) || (kmod == 4) || (kmod == 7) || (kmod == 8) || (kmod == 9)) {
 	mpdcch5ss1tab[re] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
 	re++;
-	printf("l %d, k %d (kmod %d) => re %d\n", l, k, kmod, re);
       } else if ((kmod == 0) || (kmod == 5) || (kmod == 10)) {
 	mpdcch5ss1tab[re++] = (l * eNB->frame_parms.ofdm_symbol_size) + k;
       }
@@ -139,7 +138,7 @@ void init_mpdcch5ss2tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB * eNB)
   int nushift = eNB->frame_parms.Nid_cell % 6;
   int nushiftp3 = (eNB->frame_parms.Nid_cell+3) % 6;
   // NOTE : THIS IS FOR TM1 ONLY FOR NOW!!!!!!!
-  LOG_I(PHY, "Inititalizing mpdcch5ss2tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
+  LOG_D(PHY, "Inititalizing mpdcch5ss2tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
   for (l = 2; l < 14; l++) {
     for (k = 0; k < 72; k++) {
       kmod = k % 12;
@@ -168,7 +167,7 @@ void init_mpdcch5ss3tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB * eNB)
 {
   int             l, k, kmod, re=0;
 
-  LOG_I(PHY, "Inititalizing mpdcch5ss3tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
+  LOG_D(PHY, "Inititalizing mpdcch5ss3tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
   for (l = 3; l < 14; l++) {
     for (k = 0; k < 72; k++) {
       kmod = k % 12;
@@ -194,7 +193,7 @@ void init_mpdcch3ss1tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB * eNB)
 {
   int             l, k, kmod, re=0;
 
-  LOG_I(PHY, "Inititalizing mpdcch3ss1tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
+  LOG_D(PHY, "Inititalizing mpdcch3ss1tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
   for (l = 1, re = 0; l < 14; l++) {
     for (k = 0; k < 48; k++) {
       kmod = k % 12;
@@ -218,7 +217,7 @@ void init_mpdcch2ss1tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB * eNB)
 {
   int             l, k, kmod, re=0;
 
-  LOG_I(PHY, "Inititalizing mpdcch2ss1tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
+  LOG_D(PHY, "Inititalizing mpdcch2ss1tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
   for (l = 1, re = 0; l < 14; l++) {
     for (k = 0; k < 24; k++) {
       kmod = k % 12;
@@ -288,7 +287,7 @@ void generate_mdci_top(PHY_VARS_eNB * eNB, int frame, int subframe, int16_t amp,
   int wp[2][4] = {{1,1,1,1},{1,-1,1,-1}};
   int *w;
 
-  LOG_I(PHY, "generate_mdci_top: num_dci %d\n", mpdcch->num_dci);
+  LOG_D(PHY, "generate_mdci_top: num_dci %d\n", mpdcch->num_dci);
 
   for (i = 0; i < mpdcch->num_dci; i++) {
     mdci = &mpdcch->mdci_alloc[i];
@@ -320,7 +319,7 @@ void generate_mdci_top(PHY_VARS_eNB * eNB, int frame, int subframe, int16_t amp,
     } else
       AssertFatal(1 == 0, "Illegal combination start_symbol %d, a_index %d\n", mdci->start_symbol, a_index);
 
-    LOG_I(PHY, "mdci %d, length %d: rnti %x, L %d, prb_pairs %d, ce_mode %d, transmission type %s, i0 %d, ss %d ,coded_bits %d\n", 
+    LOG_D(PHY, "mdci %d, length %d: rnti %x, L %d, prb_pairs %d, ce_mode %d, transmission type %s, i0 %d, ss %d ,coded_bits %d\n", 
 	  i, mdci->dci_length,mdci->rnti, 
 	  mdci->L, mdci->number_of_prb_pairs, 
 	  mdci->ce_mode, 
@@ -422,7 +421,7 @@ void generate_mdci_top(PHY_VARS_eNB * eNB, int frame, int subframe, int16_t amp,
     uint32_t        b = ((mdci->dmrs_scrambling_init << 1) + 1) << 16;
     x2 = a * b;
     x2 = x2 + 2;
-    LOG_I(PHY, "mpdcch_dmrs cinit %x (a=%d,b=%d,i0=%d,j0=%d)\n", x2,a,b,i0,j0);
+    LOG_D(PHY, "mpdcch_dmrs cinit %x (a=%d,b=%d,i0=%d,j0=%d)\n", x2,a,b,i0,j0);
 
     // add MPDCCH pilots
     int             reset = 1;
diff --git a/openair1/PHY/LTE_TRANSPORT/print_stats.c b/openair1/PHY/LTE_TRANSPORT/print_stats.c
index 005287935e88d932d144014d7fb8a78e9bc75f35..e86b7ff37692f7663a8311a43a1897166e465fcc 100644
--- a/openair1/PHY/LTE_TRANSPORT/print_stats.c
+++ b/openair1/PHY/LTE_TRANSPORT/print_stats.c
@@ -507,7 +507,7 @@ int dump_ue_stats(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,char* buffer, int length
       len += sprintf(&buffer[len], "[UE PROC] DLSCH Total %d, Error %d, FER %d\n",ue->dlsch_received[0],ue->dlsch_errors[0],ue->dlsch_fer[0]);
       len += sprintf(&buffer[len], "[UE PROC] DLSCH (SI) Total %d, Error %d\n",ue->dlsch_SI_received[0],ue->dlsch_SI_errors[0]);
       len += sprintf(&buffer[len], "[UE PROC] DLSCH (RA) Total %d, Error %d\n",ue->dlsch_ra_received[0],ue->dlsch_ra_errors[0]);
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
       int i=0;
 
       //len += sprintf(&buffer[len], "[UE PROC] MCH  Total %d\n", ue->dlsch_mch_received[0]);
diff --git a/openair1/PHY/LTE_TRANSPORT/pucch.c b/openair1/PHY/LTE_TRANSPORT/pucch.c
index ac12ee44272985f0da947383c6b8ce8ec58efe90..f9eee10b2a02470321e85a8597971f0300f6ba50 100644
--- a/openair1/PHY/LTE_TRANSPORT/pucch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pucch.c
@@ -719,7 +719,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 		  int     frame,
 		  uint8_t subframe,
 		  uint8_t pucch1_thres
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
 		  ,uint8_t br_flag
 #endif
 		  )
@@ -978,7 +978,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
   m = (n1_pucch < thres) ? NRB2 : (((n1_pucch-thres)/(12*c/deltaPUCCH_Shift))+NRB2+((deltaPUCCH_Shift*Ncs1_div_deltaPUCCH_Shift)>>3)+rem);
 
 #ifdef DEBUG_PUCCH_RX
-  printf("[eNB] PUCCH: m %d\n",m);
+  printf("[eNB] PUCCH: m %d, thres %d, NRB2 %d\n",m,thres,NRB2);
 #endif
   nsymb = N_UL_symb<<1;
 
@@ -989,7 +989,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 
     //for (j=0,l=0;l<(nsymb-1);l++) {
     for (j=0,l=0; l<nsymb; l++) {
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
       if (br_flag > 0 ) {
         if ((m&1) == 0)
           re_offset = (m*6) + frame_parms->first_carrier_offset;
@@ -1227,7 +1227,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 
     stat_max/=(12);  //normalize to energy per symbol and RE
 #ifdef DEBUG_PUCCH_RX
-    printf("[eNB] PUCCH fmt1a/b:  stat_max : %d, phase_max : %d\n",stat_max,phase_max);
+    LOG_I(PHY,"[eNB] PUCCH fmt1a/b:  stat_max : %d (%d : sigma2 %d), phase_max : %d\n",stat_max,dB_fixed(stat_max),sigma2_dB,phase_max);
 #endif
 
     stat_re=0;
@@ -1368,7 +1368,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 
       LOG_D(PHY,"PUCCH 1a/b: subframe %d : stat %d,%d (pos %d)\n",subframe,stat_re,stat_im,
 	    (subframe<<10) + (eNB->pucch1ab_stats_cnt[UE_id][subframe]));
-      LOG_D(PHY,"PUCCH 1a/b: subframe %d : sigma2_dB %d, stat_max %d, pucch1_thres %d\n",subframe,sigma2_dB,dB_fixed(stat_max),pucch1_thres);
+      LOG_D(PHY,"In pucch.c PUCCH 1a/b: ACK subframe %d : sigma2_dB %d, stat_max %d, pucch1_thres %d\n",subframe,sigma2_dB,dB_fixed(stat_max),pucch1_thres);
       
       eNB->pucch1ab_stats[UE_id][(subframe<<11) + 2*(eNB->pucch1ab_stats_cnt[UE_id][subframe])] = (stat_re);
       eNB->pucch1ab_stats[UE_id][(subframe<<11) + 1+2*(eNB->pucch1ab_stats_cnt[UE_id][subframe])] = (stat_im);
@@ -1385,8 +1385,9 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 #if defined(USRP_REC_PLAY)
       LOG_D(PHY,"PUCCH 1a/b: NAK subframe %d : sigma2_dB %d, stat_max %d, pucch1_thres %d\n",subframe,sigma2_dB,dB_fixed(stat_max),pucch1_thres);
 #else
-      LOG_D(PHY,"PUCCH 1a/b: subframe %d : sigma2_dB %d, stat_max %d, pucch1_thres %d\n",subframe,sigma2_dB,dB_fixed(stat_max),pucch1_thres);
-#endif      
+      LOG_D(PHY,"In pucch.c PUCCH 1a/b: NAK subframe %d : sigma2_dB %d, stat_max %d, pucch1_thres %d\n",subframe,sigma2_dB,dB_fixed(stat_max),pucch1_thres);
+#endif
+
       *payload = 4;  // DTX
       ((int16_t*)&eNB->pucch1ab_stats[UE_id][(subframe<<10) + (eNB->pucch1ab_stats_cnt[UE_id][subframe])])[0] = (int16_t)(stat_re);
       ((int16_t*)&eNB->pucch1ab_stats[UE_id][(subframe<<10) + (eNB->pucch1ab_stats_cnt[UE_id][subframe])])[1] = (int16_t)(stat_im);
diff --git a/openair1/PHY/LTE_TRANSPORT/transport_eNB.h b/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
index ddf3594880ed147933d1a3e49a1968f3ab5f045b..35e7beeeab65307fff6cf0669309650e579355dd 100644
--- a/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
+++ b/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
@@ -153,6 +153,8 @@ typedef struct {
 #else
   uint8_t active;
 #endif
+  /// indicator of UE type (0 = LTE, 1,2 = Cat-M)
+  int ue_type;
   /// HARQ process mask, indicates which processes are currently active
   uint16_t harq_mask;
   /// Indicator of TX activation per subframe.  Used during PUCCH detection for ACK/NAK.
diff --git a/openair1/PHY/LTE_TRANSPORT/transport_proto.h b/openair1/PHY/LTE_TRANSPORT/transport_proto.h
index f4919c6403c9bd34d6badc9c793049b4f4485ba7..41dff9c5c01cb9b1cd7776a349ce062928534a12 100644
--- a/openair1/PHY/LTE_TRANSPORT/transport_proto.h
+++ b/openair1/PHY/LTE_TRANSPORT/transport_proto.h
@@ -553,7 +553,11 @@ uint32_t rx_pucch(PHY_VARS_eNB *phy_vars_eNB,
                   uint8_t *payload,
                   int     frame,
                   uint8_t subframe,
-                  uint8_t pucch1_thres);
+                  uint8_t pucch1_thres
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
+                  ,int     br_flag                  
+#endif
+                  );
 
 
 /*!
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
index 041679f649d1bfa541e6d6bbed15be9ffd25ff13..b0d71e683003e941463c7a4ed646cce31f0e5205 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
@@ -738,7 +738,8 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
   int subframe = proc->subframe_rx;
   LTE_UL_eNB_HARQ_t *ulsch_harq;
 
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+  LOG_D(PHY,"ue_type %d\n",ulsch->ue_type);
   if (ulsch->ue_type>0)     harq_pid = 0;
   else
 #endif
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
index 8fab8cd0df8285d539f57fc5efa88f2e8221e66b..da213c39199b6e748de919d8aa4d41a605cdd3db 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c
@@ -1127,7 +1127,7 @@ void rx_ulsch(PHY_VARS_eNB *eNB,
   int16_t *llrp;
   int subframe = proc->subframe_rx;
 
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (ulsch[UE_id]->ue_type > 0) harq_pid =0;
   else
 #endif
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h b/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h
index dc841075b4e72459e2068ac062d18397ec88cd6f..2dfc886f5078766200a37f82f4e5c6f3cfc9b8c9 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h
+++ b/openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h
@@ -1361,7 +1361,7 @@ void init_ul_hopping(LTE_DL_FRAME_PARMS *frame_parms);
   @param nB nB from 36.304 (0=4T,1=2T,2=T,3=T/2,4=T/4,5=T/8,6=T/16,7=T/32*/
 int init_ue_paging_info(PHY_VARS_UE *ue, long defaultPagingCycle, long nB);
 
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 void init_mpdcch(PHY_VARS_eNB *eNB);
 #endif
 
diff --git a/openair1/PHY/defs_eNB.h b/openair1/PHY/defs_eNB.h
index 4de830507504591dcf11cdad49d1ffde86272286..271d54fdce5c9eaa20a3376611f5089af4f06018 100644
--- a/openair1/PHY/defs_eNB.h
+++ b/openair1/PHY/defs_eNB.h
@@ -967,6 +967,22 @@ typedef struct PHY_VARS_eNB_s {
   /// mbsfn reference symbols
   uint32_t         lte_gold_mbsfn_table[10][3][42];
 
+  // PRACH energy detection parameters
+  /// Detection threshold for LTE PRACH
+  int              prach_DTX_threshold;
+  /// Detection threshold for LTE-M PRACH per CE-level
+  int              prach_DTX_threshold_emtc[4];
+  /// counter to average prach energh over first 100 prach opportunities
+  int              prach_energy_counter;
+  // PUCCH1 energy detection parameters
+  int              pucch1_DTX_threshold;
+  // PUCCH1 energy detection parameters for eMTC per CE-level
+  int              pucch1_DTX_threshold_emtc[4];
+  // PUCCH1a/b energy detection parameters
+  int              pucch1ab_DTX_threshold;
+  // PUCCH1a/b energy detection parameters for eMTC per CE-level
+  int              pucch1ab_DTX_threshold_emtc[4];
+
   uint32_t X_u[64][839];
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint32_t X_u_br[4][64][839];
@@ -1003,8 +1019,7 @@ typedef struct PHY_VARS_eNB_s {
 
   /// if ==0 enables phy only test mode
   int mac_enabled;
-  /// counter to average prach energh over first 100 prach opportunities
-  int prach_energy_counter;
+
 
   // PDSCH Varaibles
   PDSCH_CONFIG_DEDICATED pdsch_config_dedicated[NUMBER_OF_UE_MAX];
diff --git a/openair1/SCHED/fapi_l1.c b/openair1/SCHED/fapi_l1.c
index a057b243b9898f8d579ee2c49f2d72b9c163c576..094f9722533968f5ebedb56f7a0520b44d87c0de 100644
--- a/openair1/SCHED/fapi_l1.c
+++ b/openair1/SCHED/fapi_l1.c
@@ -397,10 +397,12 @@ void handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,int frame,int subframe,L1_rxtx_pro
     }
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    dlsch0_harq->pdsch_start = eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols;
-#else
-    dlsch0_harq->pdsch_start = rel10->pdsch_start;
+    if (rel13->ue_type>0)
+      dlsch0_harq->pdsch_start = rel10->pdsch_start;
+    else
 #endif
+      dlsch0_harq->pdsch_start = eNB->pdcch_vars[proc->subframe_tx & 1].num_pdcch_symbols;
+
     if (dlsch0_harq->round==0) {  //get pointer to SDU if this a new SDU
       AssertFatal(sdu!=NULL,"NFAPI: frame %d, subframe %d: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d : sdu is null for pdu_index %d\n",
                   proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid,
@@ -704,9 +706,12 @@ void handle_nfapi_ul_pdu(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc,
   // check if we have received a dci for this ue and ulsch descriptor is configured
 
   if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE) {
+    //if (UE_id == find_ulsch(ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE)<0)
+       //for (int i=0;i<16;i++) if (eNB->ulsch[i]->harq_mask>0) LOG_I(PHY,"rnti %x, mask %x\n",eNB->ulsch[i]->rnti,eNB->ulsch[i]->harq_mask >0); 
     AssertFatal((UE_id = find_ulsch(ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE))>=0,
                 "No existing UE ULSCH for rnti %x\n",rel8->rnti);
-    LOG_D(PHY,"Applying UL config for UE %d, rnti %x for frame %d, subframe %d, modulation %d, rvidx %d\n", UE_id,rel8->rnti,frame,subframe,rel8->modulation_type,rel8->redundancy_version);
+    LOG_D(PHY,"Applying UL config for UE %d, rnti %x for frame %d, subframe %d, modulation %d, rvidx %d, first_rb %d, nb_rb %d\n", UE_id,rel8->rnti,frame,subframe,rel8->modulation_type,rel8->redundancy_version,
+rel8->resource_block_start,rel8->number_of_resource_blocks);
 
     fill_ulsch(eNB,UE_id,&ul_config_pdu->ulsch_pdu,frame,subframe);
 
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index f7b433be9e070429ab0fc34d5c343bc3b73c9d0e..2dc16ef1101b17ed4257c1bc5731ae5091266c1c 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -334,7 +334,7 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,
   }
 
 
-  LOG_D(PHY,"Generating DLSCH/PDSCH pdu:%p pdsch_start:%d frame:%d subframe:%d nb_rb:%d rb_alloc:%d Qm:%d Nl:%d round:%d\n",
+  if (dlsch->rnti!=0xffff) LOG_D(PHY,"Generating DLSCH/PDSCH pdu:%p pdsch_start:%d frame:%d subframe:%d nb_rb:%d rb_alloc:%d Qm:%d Nl:%d round:%d\n",
 	dlsch_harq->pdu,dlsch_harq->pdsch_start,frame,subframe,dlsch_harq->nb_rb,dlsch_harq->rb_alloc[0],dlsch_harq->Qm,dlsch_harq->Nl,dlsch_harq->round);
   // 36-212 
   if (nfapi_mode == 0 || nfapi_mode == 1) { // monolthic OR PNF - do not need turbo encoding on VNF
@@ -534,7 +534,7 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     num_mdci = eNB->mpdcch_vars[subframe &1].num_dci;
     if (num_mdci > 0) {
-      LOG_I (PHY, "[eNB %" PRIu8 "] Frame %d, subframe %d: Calling generate_mdci_top (mpdcch) (num_dci %" PRIu8 ")\n", eNB->Mod_id, frame, subframe, num_mdci);
+      LOG_D (PHY, "[eNB %" PRIu8 "] Frame %d, subframe %d: Calling generate_mdci_top (mpdcch) (num_dci %" PRIu8 ")\n", eNB->Mod_id, frame, subframe, num_mdci);
       
       generate_mdci_top (eNB, frame, subframe, AMP, eNB->common_vars.txdataF);
       
@@ -566,12 +566,22 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
       harq_pid = dlsch0->harq_ids[frame%2][subframe];
       AssertFatal(harq_pid>=0,"harq_pid is negative\n");
       
-      if (harq_pid>=8)
-	{
-	  LOG_E(PHY,"harq_pid:%d corrupt must be 0-7 UE_id:%d frame:%d subframe:%d rnti:%x\n", harq_pid,UE_id,frame,subframe,dlsch0->rnti);
-	}
-      else
-	{
+      if (harq_pid>=8) {
+
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+        if (dlsch0->ue_type==0) 
+#endif
+	  LOG_E(PHY,"harq_pid:%d corrupt must be 0-7 UE_id:%d frame:%d subframe:%d rnti:%x [ %1d.%1d.%1d.%1d.%1d.%1d.%1d.%1d\n", harq_pid,UE_id,frame,subframe,dlsch0->rnti,
+                dlsch0->harq_ids[frame%2][0],
+                dlsch0->harq_ids[frame%2][1],
+                dlsch0->harq_ids[frame%2][2],
+                dlsch0->harq_ids[frame%2][3],
+                dlsch0->harq_ids[frame%2][4],
+                dlsch0->harq_ids[frame%2][5],
+                dlsch0->harq_ids[frame%2][6],
+                dlsch0->harq_ids[frame%2][7]);
+      } else
+      {
 	  // generate pdsch
 	  
 	  pdsch_procedures(eNB,
@@ -581,7 +591,7 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 			   dlsch1,
 			   &eNB->UE_stats[(uint32_t)UE_id],
 			   0);
-	}
+      }
       
       
     }
@@ -725,109 +735,77 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
       switch (uci->type) {
       case SR:
       case HARQ_SR:
-	
-	metric_SR = rx_pucch(eNB,
-			     uci->pucch_fmt,
-			     i,
-			     uci->n_pucch_1_0_sr[0],
-			     0, // n2_pucch
-			     uci->srs_active, // shortened format
-			     &SR_payload,
-			     frame,
-			     subframe,
-			     PUCCH1_THRES);
-	LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR is %d (uci.type %d SR n1pucch is %d)\n",
-	      eNB->Mod_id,
-	      uci->rnti,
-	      frame,
-	      subframe,
-	      SR_payload,
-	      uci->type,
-	      uci->n_pucch_1_0_sr[0]);
-	if (uci->type == SR) {
-	  if (SR_payload == 1) {
-	    fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
-	    break;
-	  }
-	  else {
-	    break;
-	  }
-	}
-      case HARQ:
-	if (fp->frame_type == FDD) {
-	  LOG_D(PHY,"Frame %d Subframe %d Demodulating PUCCH (UCI %d) for ACK/NAK (uci->pucch_fmt %d,uci->type %d.uci->frame %d, uci->subframe %d): n1_pucch0 %d SR_payload %d\n",
-		frame,subframe,i,
-		uci->pucch_fmt,uci->type,
-		uci->frame,uci->subframe,uci->n_pucch_1[0][0],
-		SR_payload);
-	  
-	  metric[0] = rx_pucch(eNB,
-			       uci->pucch_fmt,
-			       i,
-			       uci->n_pucch_1[0][0],
-			       0, //n2_pucch
-			       uci->srs_active, // shortened format
-			       pucch_b0b1[0],
-			       frame,
-			       subframe,
-			       PUCCH1a_THRES);
-	  
-	  
-	  /* cancel SR detection if reception on n1_pucch0 is better than on SR PUCCH resource index, otherwise send it up to MAC */
-	  if (uci->type==HARQ_SR && metric[0] > metric_SR) SR_payload = 0;
-	  else if (SR_payload == 1) fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
-	  
-	  if (uci->type==HARQ_SR && metric[0] <= metric_SR) {
-	    /* when transmitting ACK/NACK on SR PUCCH resource index, SR payload is always 1 */
-	    SR_payload = 1;
-	    
-	    metric[0]=rx_pucch(eNB,
+        {
+	  int pucch1_thres = (uci->ue_type == 0) ? eNB->pucch1_DTX_threshold : eNB->pucch1_DTX_threshold_emtc[0];
+	  metric_SR = rx_pucch(eNB,
 			       uci->pucch_fmt,
 			       i,
 			       uci->n_pucch_1_0_sr[0],
-			       0, //n2_pucch
+			       0, // n2_pucch
 			       uci->srs_active, // shortened format
-			       pucch_b0b1[0],
+			       &SR_payload,
 			       frame,
 			       subframe,
-			       PUCCH1a_THRES);
-	  }
-	  
-	  
-	  LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d pucch1a (FDD) payload %d (metric %d)\n",
+			       pucch1_thres
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
+			       ,uci->ue_type
+#endif
+			       );
+	  LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR is %d (uci.type %d SR n1pucch is %d)\n",
 		eNB->Mod_id,
 		uci->rnti,
-		frame,subframe,
-		pucch_b0b1[0][0],metric[0]);
-	  
-	  uci->stat = metric[0]; 	  
-	  fill_uci_harq_indication(eNB,uci,frame,subframe,pucch_b0b1[0],0,0xffff);
-	  
+		frame,
+		subframe,
+		SR_payload,
+		uci->type,
+		uci->n_pucch_1_0_sr[0]);
+	  if (uci->type == SR) {
+	    if (SR_payload == 1) {
+	      fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
+	      break;
+	    }
+	    else {
+	      break;
+	    }
+	  }
 	}
-	else { // frame_type == TDD
-	  LOG_D(PHY,"Frame %d Subframe %d Demodulating PUCCH (UCI %d) for ACK/NAK (uci->pucch_fmt %d,uci->type %d.uci->frame %d, uci->subframe %d): n1_pucch0 %d SR_payload %d\n",
-		frame,subframe,i,
-		uci->pucch_fmt,uci->type,
-		uci->frame,uci->subframe,uci->n_pucch_1[0][0],
-		SR_payload);
-#if 1
-	  metric[0] = rx_pucch(eNB,
-			       uci->pucch_fmt,
-			       i,
-			       uci->n_pucch_1[0][0],
-			       0, //n2_pucch
-			       uci->srs_active, // shortened format
-			       pucch_b0b1[0],
-			       frame,
-			       subframe,
-			       PUCCH1a_THRES);
-	  if (uci->type==HARQ_SR && metric[0] > metric_SR) SR_payload = 0;
-	  else if (SR_payload == 1) fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
-	  
-	  if (uci->type==HARQ_SR && metric[0] <= metric_SR) {
-	    SR_payload = 1;
+      case HARQ:
+	{
+	  int pucch1ab_thres = (uci->ue_type == 0) ? eNB->pucch1ab_DTX_threshold : eNB->pucch1ab_DTX_threshold_emtc[0];	  
+	  if (fp->frame_type == FDD) {
+	    LOG_D(PHY,"Frame %d Subframe %d Demodulating PUCCH (UCI %d) for ACK/NAK (uci->pucch_fmt %d,uci->type %d.uci->frame %d, uci->subframe %d): n1_pucch0 %d SR_payload %d\n",
+		  frame,subframe,i,
+		  uci->pucch_fmt,uci->type,
+		  uci->frame,uci->subframe,uci->n_pucch_1[0][0],
+		  SR_payload);
+	    
 	    metric[0] = rx_pucch(eNB,
-				 pucch_format1b,
+				 uci->pucch_fmt,
+				 i,
+				 uci->n_pucch_1[0][0],
+				 0, //n2_pucch
+				 uci->srs_active, // shortened format
+				 pucch_b0b1[0],
+				 frame,
+				 subframe,
+				 pucch1ab_thres
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
+				 ,uci->ue_type
+#endif
+				 );
+	    //dump_ulsch(eNB,frame,subframe,0,0); exit(-1);
+	    
+	    
+	    /* cancel SR detection if reception on n1_pucch0 is better than on SR PUCCH resource index, otherwise send it up to MAC */
+	    if (uci->type==HARQ_SR && metric[0] > metric_SR) SR_payload = 0;
+	    else if (SR_payload == 1) fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
+	    
+	    if (uci->type==HARQ_SR && metric[0] <= metric_SR) {
+	      /* when transmitting ACK/NACK on SR PUCCH resource index, SR payload is always 1 */
+	      SR_payload = 1;
+	      
+	      metric[0]=rx_pucch(eNB,
+				 uci->pucch_fmt,
 				 i,
 				 uci->n_pucch_1_0_sr[0],
 				 0, //n2_pucch
@@ -835,365 +813,427 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 				 pucch_b0b1[0],
 				 frame,
 				 subframe,
-				 PUCCH1a_THRES);
+				 pucch1ab_thres
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
+				 ,uci->ue_type
+#endif
+				 );
+	    }
+	    
+	    
+	    LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d pucch1a (FDD) payload %d (metric %d)\n",
+		  eNB->Mod_id,
+		  uci->rnti,
+		  frame,subframe,
+		  pucch_b0b1[0][0],metric[0]);
+	    
+	    uci->stat = metric[0]; 	  
+	    fill_uci_harq_indication(eNB,uci,frame,subframe,pucch_b0b1[0],0,0xffff);
+	    
 	  }
+	  else { // frame_type == TDD
+	    LOG_D(PHY,"Frame %d Subframe %d Demodulating PUCCH (UCI %d) for ACK/NAK (uci->pucch_fmt %d,uci->type %d.uci->frame %d, uci->subframe %d): n1_pucch0 %d SR_payload %d\n",
+		  frame,subframe,i,
+		  uci->pucch_fmt,uci->type,
+		  uci->frame,uci->subframe,uci->n_pucch_1[0][0],
+		  SR_payload);
+#if 1
+	    metric[0] = rx_pucch(eNB,
+				 uci->pucch_fmt,
+				 i,
+				 uci->n_pucch_1[0][0],
+				 0, //n2_pucch
+				 uci->srs_active, // shortened format
+				 pucch_b0b1[0],
+				 frame,
+				 subframe,
+				 pucch1ab_thres
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
+				 ,uci->ue_type
+#endif
+				 );
+	    
+	    if (uci->type==HARQ_SR && metric[0] > metric_SR) SR_payload = 0;
+	    else if (SR_payload == 1) fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
+	    
+	    if (uci->type==HARQ_SR && metric[0] <= metric_SR) {
+	      SR_payload = 1;
+	      metric[0] = rx_pucch(eNB,
+				   pucch_format1b,
+				   i,
+				   uci->n_pucch_1_0_sr[0],
+				   0, //n2_pucch
+				   uci->srs_active, // shortened format
+				   pucch_b0b1[0],
+				   frame,
+				   subframe,
+				   pucch1ab_thres
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) 
+				   ,uci->ue_type
+#endif
+				   );
+	      
+	    }
 #else
-	  // if SR was detected, use the n1_pucch from SR
-	  if (SR_payload==1) {
+	    // if SR was detected, use the n1_pucch from SR
+	    if (SR_payload==1) {
 #ifdef DEBUG_PHY_PROC
-	    LOG_D (PHY, "[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d with SR\n", eNB->Mod_id,
-		   eNB->dlsch[UE_id][0]->rnti, frame, subframe, n1_pucch0, n1_pucch1, n1_pucch2, n1_pucch3, format);
+	      LOG_D (PHY, "[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d with SR\n", eNB->Mod_id,
+		     eNB->dlsch[UE_id][0]->rnti, frame, subframe, n1_pucch0, n1_pucch1, n1_pucch2, n1_pucch3, format);
 #endif
-	    
-	    metric[0] = rx_pucch (eNB, pucch_format1b, i, uci->n_pucch_1_0_sr[0], 0,    //n2_pucch
-				  uci->srs_active,      // shortened format
-				  pucch_b0b1[0], frame, subframe, PUCCH1a_THRES
+	      
+	      metric[0] = rx_pucch (eNB, pucch_format1b, i, uci->n_pucch_1_0_sr[0], 0,    //n2_pucch
+				    uci->srs_active,      // shortened format
+				    pucch_b0b1[0], frame, subframe, 
+				    pucch1ab_thres
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				  ,uci->ue_type
+				    ,uci->ue_type
 #endif
-				  );
-	  } else {              //using assigned pucch resources
+				    );
+	    } else {              //using assigned pucch resources
 #ifdef DEBUG_PHY_PROC
-	    LOG_D (PHY, "[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK M=%d (%d,%d,%d,%d) format %d\n", eNB->Mod_id,
-		   eNB->dlsch[UE_id][0]->rnti,
-		   frame, subframe, uci->num_pucch_resources, uci->n_pucch_1[res][0], uci->n_pucch_1[res][1], uci->n_pucch_1[res][2], uci->n_pucch_1[res][3], uci->pucch_fmt);
+	      LOG_D (PHY, "[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK M=%d (%d,%d,%d,%d) format %d\n", eNB->Mod_id,
+		     eNB->dlsch[UE_id][0]->rnti,
+		     frame, subframe, uci->num_pucch_resources, uci->n_pucch_1[res][0], uci->n_pucch_1[res][1], uci->n_pucch_1[res][2], uci->n_pucch_1[res][3], uci->pucch_fmt);
 #endif
-	    for (res = 0; res < uci->num_pucch_resources; res++)
-	      metric[res] = rx_pucch (eNB, uci->pucch_fmt, i, uci->n_pucch_1[res][0], 0,        // n2_pucch
-				      uci->srs_active,  // shortened format
-				      pucch_b0b1[res], frame, subframe, PUCCH1a_THRES
+	      for (res = 0; res < uci->num_pucch_resources; res++)
+		metric[res] = rx_pucch (eNB, uci->pucch_fmt, i, uci->n_pucch_1[res][0], 0,        // n2_pucch
+					uci->srs_active,  // shortened format
+					pucch_b0b1[res], frame, subframe, 
+					pucch1ab_thres
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				      ,uci->ue_type
+					,uci->ue_type
 #endif		  
-				      );
-	    for (res=0;res<uci->num_pucch_resources;res++)
-	      metric[res] = rx_pucch(eNB,
-				     uci->pucch_fmt,
-				     i,
-				     uci->n_pucch_1[res][0],
-				     0, // n2_pucch
-				     uci->srs_active, // shortened format
-				     pucch_b0b1[res],
-				     frame,
-				     subframe,
-				     PUCCH1a_THRES,
+					);
+	      for (res=0;res<uci->num_pucch_resources;res++)
+		metric[res] = rx_pucch(eNB,
+				       uci->pucch_fmt,
+				       i,
+				       uci->n_pucch_1[res][0],
+				       0, // n2_pucch
+				       uci->srs_active, // shortened format
+				       pucch_b0b1[res],
+				       frame,
+				       subframe,
+				       pucch1ab_thres
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-				     ,uci->ue_type
+				       ,uci->ue_type
 #endif		  
-				     );
-	  }
+				       );
+	    }
 #ifdef DEBUG_PHY_PROC
-	  LOG_D(PHY,"RNTI %x type %d SR_payload %d  Frame %d Subframe %d  pucch_b0b1[0][0] %d pucch_b0b1[0][1] %d pucch_b0b1[1][0] %d pucch_b0b1[1][1] %d  \n",
-		uci->rnti,uci->type,SR_payload,frame,subframe,pucch_b0b1[0][0],pucch_b0b1[0][1],pucch_b0b1[1][0],pucch_b0b1[1][1]);
+	    LOG_D(PHY,"RNTI %x type %d SR_payload %d  Frame %d Subframe %d  pucch_b0b1[0][0] %d pucch_b0b1[0][1] %d pucch_b0b1[1][0] %d pucch_b0b1[1][1] %d  \n",
+		  uci->rnti,uci->type,SR_payload,frame,subframe,pucch_b0b1[0][0],pucch_b0b1[0][1],pucch_b0b1[1][0],pucch_b0b1[1][1]);
 #endif
 #endif
-	  if (SR_payload == 1) { // this implements Table 7.3.1 from 36.213
-	    if (pucch_b0b1[0][0] == 4) { // there isn't a likely transmission
-	      harq_ack[0] = 4; // DTX
-	    }
-	    else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1) { // 1/4/7 ACKs
-	      harq_ack[0] = 1;
-	    }
-	    else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] != 1) { // 2/5/8 ACKs
-	      harq_ack[0] = 2;
-	    }
-	    else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] == 1) { // 3/6/9 ACKs
-	      harq_ack[0] = 3;
-	    }
-	    else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1) { // 0 ACKs, or at least one DL assignment missed
-	      harq_ack[0] = 0;
-	    }
-	    uci->stat = metric[0];
-	    fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,2,0xffff); // special_bundling mode
-	  } 
-	  else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==2)){ // multiplexing + no SR, implement Table 10.1.3-5 (Rel14) for multiplexing with M=2
-	    if (pucch_b0b1[0][0] == 4 ||
-		pucch_b0b1[1][0] == 4) { // there isn't a likely transmission
-	      harq_ack[0] = 4; // DTX
-	      harq_ack[1] = 6; // NACK/DTX
-	    } 
-	    else {
-	      if (metric[1]>metric[0]) {
-		if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 1; // ACK
-		  tdd_multiplexing_mask = 0x3;
-		}
-		else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1){
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 1; // ACK
-		  tdd_multiplexing_mask = 0x2;
-		}
-		else {
-		  harq_ack[0] = 4; // DTX
-		  harq_ack[1] = 4; // DTX
-		}
+	    if (SR_payload == 1) { // this implements Table 7.3.1 from 36.213
+	      if (pucch_b0b1[0][0] == 4) { // there isn't a likely transmission
+		harq_ack[0] = 4; // DTX
+	      }
+	      else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1) { // 1/4/7 ACKs
+		harq_ack[0] = 1;
 	      }
+	      else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] != 1) { // 2/5/8 ACKs
+		harq_ack[0] = 2;
+	      }
+	      else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] == 1) { // 3/6/9 ACKs
+		harq_ack[0] = 3;
+	      }
+	      else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1) { // 0 ACKs, or at least one DL assignment missed
+		harq_ack[0] = 0;
+	      }
+	      uci->stat = metric[0];
+	      fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,2,0xffff); // special_bundling mode
+	    } 
+	    else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==2)){ // multiplexing + no SR, implement Table 10.1.3-5 (Rel14) for multiplexing with M=2
+	      if (pucch_b0b1[0][0] == 4 ||
+		  pucch_b0b1[1][0] == 4) { // there isn't a likely transmission
+		harq_ack[0] = 4; // DTX
+		harq_ack[1] = 6; // NACK/DTX
+	      } 
 	      else {
-		if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x1;
-		}
-		else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
-		  harq_ack[0] = 2; // NACK
-		  harq_ack[1] = 6; // NACK/DTX
+		if (metric[1]>metric[0]) {
+		  if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 1; // ACK
+		    tdd_multiplexing_mask = 0x3;
+		  }
+		  else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1){
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 1; // ACK
+		    tdd_multiplexing_mask = 0x2;
+		  }
+		  else {
+		    harq_ack[0] = 4; // DTX
+		    harq_ack[1] = 4; // DTX
+		  }
 		}
 		else {
-		  harq_ack[0] = 4; // DTX
-		  harq_ack[1] = 4; // DTX
+		  if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x1;
+		  }
+		  else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
+		    harq_ack[0] = 2; // NACK
+		    harq_ack[1] = 6; // NACK/DTX
+		  }
+		  else {
+		    harq_ack[0] = 4; // DTX
+		    harq_ack[1] = 4; // DTX
+		  }
 		}
 	      }
-	    }
-	    uci->stat = max(metric[0],metric[1]);
-	    fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
-	  } //else if ((uci->tdd_bundling == 0) && (res==2))
-	  else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==3)){ // multiplexing + no SR, implement Table 10.1.3-6 (Rel14) for multiplexing with M=3
-	    
-	    if (harq_ack[0] == 4 ||
-		harq_ack[1] == 4 ||
-		harq_ack[2] == 4) { // there isn't a likely transmission
-	      harq_ack[0] = 4; // DTX
-	      harq_ack[1] = 6; // NACK/DTX
-	      harq_ack[2] = 6; // NACK/DTX
-	      max_metric = 0;
-	    } 
-	    else {
-	      
-	      max_metric = max(metric[0],max(metric[1],metric[2]));
+	      uci->stat = max(metric[0],metric[1]);
+	      fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
+	    } //else if ((uci->tdd_bundling == 0) && (res==2))
+	    else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==3)){ // multiplexing + no SR, implement Table 10.1.3-6 (Rel14) for multiplexing with M=3
 	      
-	      if (metric[0]==max_metric) {
-		if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x1;
-		}
-		else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
-		  harq_ack[0] = 2; // NACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 6; // NACK/DTX
-		}
-		else {
-		  harq_ack[0] = 4; // DTX
-		  harq_ack[1] = 4; // DTX
-		  harq_ack[2] = 4; // DTX
-		}
-	      } // if (metric[0]==max_metric) {
-	      else if (metric[1]==max_metric) {
+	      if (harq_ack[0] == 4 ||
+		  harq_ack[1] == 4 ||
+		  harq_ack[2] == 4) { // there isn't a likely transmission
+		harq_ack[0] = 4; // DTX
+		harq_ack[1] = 6; // NACK/DTX
+		harq_ack[2] = 6; // NACK/DTX
+		max_metric = 0;
+	      } 
+	      else {
 		
-		if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x3;
-		}
-		else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x2;
-		}
+		max_metric = max(metric[0],max(metric[1],metric[2]));
+		
+		if (metric[0]==max_metric) {
+		  if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x1;
+		  }
+		  else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
+		    harq_ack[0] = 2; // NACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 6; // NACK/DTX
+		  }
+		  else {
+		    harq_ack[0] = 4; // DTX
+		    harq_ack[1] = 4; // DTX
+		    harq_ack[2] = 4; // DTX
+		  }
+		} // if (metric[0]==max_metric) {
+		else if (metric[1]==max_metric) {
+		  
+		  if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x3;
+		  }
+		  else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x2;
+		  }
+		  else {
+		    harq_ack[0] = 4; // DTX
+		    harq_ack[1] = 4; // DTX
+		    harq_ack[2] = 4; // DTX
+		  }
+		} // if (metric[1]==max_metric) {
 		else {
-		  harq_ack[0] = 4; // DTX
-		  harq_ack[1] = 4; // DTX
-		  harq_ack[2] = 4; // DTX
-		}
-	      } // if (metric[1]==max_metric) {
-	      else {
-		if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 1; // ACK
-		  tdd_multiplexing_mask = 0x7;
-		}
-		else if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] != 1 ) {
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 1; // ACK
-		  tdd_multiplexing_mask = 0x5;
-		}
-		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] == 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 1; // ACK
-		  tdd_multiplexing_mask = 0x6;
-		}
-		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] != 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 1; // ACK
-		  tdd_multiplexing_mask = 0x4;
+		  if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 1; // ACK
+		    tdd_multiplexing_mask = 0x7;
+		  }
+		  else if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] != 1 ) {
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 1; // ACK
+		    tdd_multiplexing_mask = 0x5;
+		  }
+		  else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] == 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 1; // ACK
+		    tdd_multiplexing_mask = 0x6;
+		  }
+		  else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] != 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 1; // ACK
+		    tdd_multiplexing_mask = 0x4;
+		  }
 		}
+		uci->stat = max_metric;
+		fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
 	      }
-	      uci->stat = max_metric;
-	      fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
-	    }
-	  } //else if ((uci->tdd_bundling == 0) && (res==3)) 
-	  else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==4)){ // multiplexing + no SR, implement Table 10.1.3-7 (Rel14) for multiplexing with M=4
-	    if (pucch_b0b1[0][0] == 4 ||
-		pucch_b0b1[1][0] == 4 ||
-		pucch_b0b1[2][0] == 4 ||
-		pucch_b0b1[3][0] == 4) { // there isn't a likely transmission
-	      harq_ack[0] = 4; // DTX
-	      harq_ack[1] = 6; // NACK/DTX
-	      harq_ack[2] = 6; // NACK/DTX
-	      harq_ack[3] = 6; // NACK/DTX
-	      max_metric = 0;
-	    } else {
-	      
-	      max_metric = max(metric[0],max(metric[1],max(metric[2],metric[3])));
-	      
-	      if (metric[0]==max_metric) {
-		if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] != 1){
-		  harq_ack[0] = 2; // NACK
-		  harq_ack[1] = 4; // DTX
-		  harq_ack[2] = 4; // DTX
-		  harq_ack[3] = 4; // DTX
-		}
-		else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 6; // NACK/DTX
-		  harq_ack[3] = 1; // ACK
-		  tdd_multiplexing_mask = 0x9;
-		}
-		else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 6; // NACK/DTX
-		  harq_ack[3] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x1;
-		}
-		else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
-		  harq_ack[0] = 2; // NACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 6; // NACK/DTX
-		  harq_ack[3] = 6; // NACK/DTX
-		}
+	    } //else if ((uci->tdd_bundling == 0) && (res==3)) 
+	    else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==4)){ // multiplexing + no SR, implement Table 10.1.3-7 (Rel14) for multiplexing with M=4
+	      if (pucch_b0b1[0][0] == 4 ||
+		  pucch_b0b1[1][0] == 4 ||
+		  pucch_b0b1[2][0] == 4 ||
+		  pucch_b0b1[3][0] == 4) { // there isn't a likely transmission
+		harq_ack[0] = 4; // DTX
+		harq_ack[1] = 6; // NACK/DTX
+		harq_ack[2] = 6; // NACK/DTX
+		harq_ack[3] = 6; // NACK/DTX
+		max_metric = 0;
+	      } else {
 		
-	      } 
-	      else if (metric[1]==max_metric) {
-		if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 1; // ACK
-		  tdd_multiplexing_mask = 0xF;
-		}
-		else if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1 ) {
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 6; // NACK/DTX
-		  harq_ack[3] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x3;
-		}
-		else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] != 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 1; // ACK
-		  tdd_multiplexing_mask = 0xE;
-		}
-		else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 6; // NACK/DTX
-		  harq_ack[3] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x2;
-		}
-	      } 
-	      else if (metric[2]==max_metric) {
-		if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x7;
-		}
-		else if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] != 1 ) {
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 6; // NACK/DTX
-		  tdd_multiplexing_mask = 0x5;
-		}
-		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] == 1 ) {
-		  harq_ack[0] = 4; // NACK/DTX
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 4; // NACK/DTX
-		  tdd_multiplexing_mask = 0x6;
-		}
-		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] != 1 ) {
-		  harq_ack[0] = 4; // NACK/DTX
-		  harq_ack[1] = 4; // NACK/DTX
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 4; // NACK/DTX
-		  tdd_multiplexing_mask = 0x4;
-		}
-	      } 
-	      else { // max_metric[3]=max_metric
-		if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
-		  harq_ack[0] = 1; // ACK
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 1; // ACK
-		  tdd_multiplexing_mask = 0xD;
-		}
-		else if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] != 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 1; // ACK
-		  harq_ack[2] = 6; // NACK/DTX
-		  harq_ack[3] = 1; // ACK
-		  tdd_multiplexing_mask = 0xA;
-		}
-		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] == 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 1; // ACK
-		  harq_ack[3] = 1; // ACK
-		  tdd_multiplexing_mask = 0xC;
-		}
-		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] != 1 ) {
-		  harq_ack[0] = 6; // NACK/DTX
-		  harq_ack[1] = 6; // NACK/DTX
-		  harq_ack[2] = 6; // NACK/DTX
-		  harq_ack[3] = 1; // ACK
-		  tdd_multiplexing_mask = 0x8;
+		max_metric = max(metric[0],max(metric[1],max(metric[2],metric[3])));
+		
+		if (metric[0]==max_metric) {
+		  if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] != 1){
+		    harq_ack[0] = 2; // NACK
+		    harq_ack[1] = 4; // DTX
+		    harq_ack[2] = 4; // DTX
+		    harq_ack[3] = 4; // DTX
+		  }
+		  else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 6; // NACK/DTX
+		    harq_ack[3] = 1; // ACK
+		    tdd_multiplexing_mask = 0x9;
+		  }
+		  else if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 6; // NACK/DTX
+		    harq_ack[3] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x1;
+		  }
+		  else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
+		    harq_ack[0] = 2; // NACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 6; // NACK/DTX
+		    harq_ack[3] = 6; // NACK/DTX
+		  }
+		  
+		} 
+		else if (metric[1]==max_metric) {
+		  if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 1; // ACK
+		    tdd_multiplexing_mask = 0xF;
+		  }
+		  else if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1 ) {
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 6; // NACK/DTX
+		    harq_ack[3] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x3;
+		  }
+		  else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] != 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 1; // ACK
+		    tdd_multiplexing_mask = 0xE;
+		  }
+		  else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 6; // NACK/DTX
+		    harq_ack[3] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x2;
+		  }
+		} 
+		else if (metric[2]==max_metric) {
+		  if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x7;
+		  }
+		  else if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] != 1 ) {
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 6; // NACK/DTX
+		    tdd_multiplexing_mask = 0x5;
+		  }
+		  else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] == 1 ) {
+		    harq_ack[0] = 4; // NACK/DTX
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 4; // NACK/DTX
+		    tdd_multiplexing_mask = 0x6;
+		  }
+		  else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] != 1 ) {
+		    harq_ack[0] = 4; // NACK/DTX
+		    harq_ack[1] = 4; // NACK/DTX
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 4; // NACK/DTX
+		    tdd_multiplexing_mask = 0x4;
+		  }
+		} 
+		else { // max_metric[3]=max_metric
+		  if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
+		    harq_ack[0] = 1; // ACK
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 1; // ACK
+		    tdd_multiplexing_mask = 0xD;
+		  }
+		  else if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] != 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 1; // ACK
+		    harq_ack[2] = 6; // NACK/DTX
+		    harq_ack[3] = 1; // ACK
+		    tdd_multiplexing_mask = 0xA;
+		  }
+		  else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] == 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 1; // ACK
+		    harq_ack[3] = 1; // ACK
+		    tdd_multiplexing_mask = 0xC;
+		  }
+		  else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] != 1 ) {
+		    harq_ack[0] = 6; // NACK/DTX
+		    harq_ack[1] = 6; // NACK/DTX
+		    harq_ack[2] = 6; // NACK/DTX
+		    harq_ack[3] = 1; // ACK
+		    tdd_multiplexing_mask = 0x8;
+		  }
 		}
 	      }
+	      uci->stat = max_metric;
+	      fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
+	    } // else if ((uci->tdd_bundling == 0) && (res==4))
+	    else { // bundling
+	      harq_ack[0] = pucch_b0b1[0][0];
+	      harq_ack[1] = pucch_b0b1[0][1];
+	      uci->stat = metric[0];
+	      LOG_D(PHY,"bundling: (%d,%d), metric %d\n",harq_ack[0],harq_ack[1],uci->stat);
+	      fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,0,0xffff); // special_bundling mode
 	    }
-	    uci->stat = max_metric;
-	    fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
-	  } // else if ((uci->tdd_bundling == 0) && (res==4))
-	  else { // bundling
-	    harq_ack[0] = pucch_b0b1[0][0];
-	    harq_ack[1] = pucch_b0b1[0][1];
-	    uci->stat = metric[0];
-	    LOG_D(PHY,"bundling: (%d,%d), metric %d\n",harq_ack[0],harq_ack[1],uci->stat);
-	    fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,0,0xffff); // special_bundling mode
-	  }
-	  
+	    
 #ifdef DEBUG_PHY_PROC
-	  LOG_D (PHY, "[eNB %d][PDSCH %x] Frame %d subframe %d ACK/NAK metric 0 %d, metric 1 %d, (%d,%d)\n", eNB->Mod_id,
-		 eNB->dlsch[UE_id][0]->rnti, frame, subframe, metric0, metric1, pucch_b0b1[0], pucch_b0b1[1]);
+	    LOG_D (PHY, "[eNB %d][PDSCH %x] Frame %d subframe %d ACK/NAK metric 0 %d, metric 1 %d, (%d,%d)\n", eNB->Mod_id,
+		   eNB->dlsch[UE_id][0]->rnti, frame, subframe, metric0, metric1, pucch_b0b1[0], pucch_b0b1[1]);
 #endif
+	  }
+	  break;
+	default:
+	  AssertFatal (1 == 0, "Unsupported UCI type %d\n", uci->type);
+	  break;
 	}
-	break;
-      default:
-	AssertFatal (1 == 0, "Unsupported UCI type %d\n", uci->type);
-	break;
-      }
-      
-      if (SR_payload == 1) {
-	LOG_D (PHY, "[eNB %d][SR %x] Frame %d subframe %d Got SR for PUSCH, transmitting to MAC\n", eNB->Mod_id, uci->rnti, frame, subframe);
 	
-	if (eNB->first_sr[i] == 1) {    // this is the first request for uplink after Connection Setup, so clear HARQ process 0 use for Msg4
-	  eNB->first_sr[i] = 0;
-	  eNB->dlsch[i][0]->harq_processes[0]->round = 0;
-	  eNB->dlsch[i][0]->harq_processes[0]->status = SCH_IDLE;
-	  LOG_D (PHY, "[eNB %d][SR %x] Frame %d subframe %d First SR\n", eNB->Mod_id, eNB->ulsch[i]->rnti, frame, subframe);
+	if (SR_payload == 1) {
+	  LOG_D (PHY, "[eNB %d][SR %x] Frame %d subframe %d Got SR for PUSCH, transmitting to MAC\n", eNB->Mod_id, uci->rnti, frame, subframe);
+	  
+	  if (eNB->first_sr[i] == 1) {    // this is the first request for uplink after Connection Setup, so clear HARQ process 0 use for Msg4
+	    eNB->first_sr[i] = 0;
+	    eNB->dlsch[i][0]->harq_processes[0]->round = 0;
+	    eNB->dlsch[i][0]->harq_processes[0]->status = SCH_IDLE;
+	    LOG_D (PHY, "[eNB %d][SR %x] Frame %d subframe %d First SR\n", eNB->Mod_id, eNB->ulsch[i]->rnti, frame, subframe);
+	  }
 	}
       }
     }
@@ -1212,12 +1252,12 @@ void pusch_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
   const int subframe = proc->subframe_rx;
   const int frame    = proc->frame_rx;
   
-  harq_pid = subframe2harq_pid(&eNB->frame_parms,frame,subframe);
+  uint32_t harq_pid0 = subframe2harq_pid(&eNB->frame_parms,frame,subframe);
 
   
   for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
     ulsch = eNB->ulsch[i];
-    if (ulsch->ue_type > 0) harq_pid = 0;
+    if (ulsch->ue_type > 0) harq_pid = 0; else harq_pid=harq_pid0;
     
     ulsch_harq = ulsch->harq_processes[harq_pid];
     
diff --git a/openair1/SCHED/prach_procedures.c b/openair1/SCHED/prach_procedures.c
index ee16a4f5807a13429564024f47dd79b30b4f084d..534f67b16c3189dad756df50f3e29352ff996d58 100644
--- a/openair1/SCHED/prach_procedures.c
+++ b/openair1/SCHED/prach_procedures.c
@@ -102,6 +102,7 @@ void prach_procedures(PHY_VARS_eNB *eNB
     }
   }
 
+  // run PRACH detection for CE-level 0 only for now when br_flag is set
   rx_prach(eNB,
 	   eNB->RU_list[0],
 	   &max_preamble[0],
@@ -114,8 +115,8 @@ void prach_procedures(PHY_VARS_eNB *eNB
 #endif
 	   );
 
-  LOG_D(PHY,"[RAPROC] Frame %d, subframe %d : Most likely preamble %d, energy %d dB delay %d (prach_energy counter %d)\n",
-        frame,subframe,
+  LOG_D(PHY,"[RAPROC] Frame %d, subframe %d : BR %d  Most likely preamble %d, energy %d dB delay %d (prach_energy counter %d)\n",
+        frame,subframe,br_flag,
         max_preamble[0],
         max_preamble_energy[0]/10,
         max_preamble_delay[0],
@@ -141,7 +142,7 @@ void prach_procedures(PHY_VARS_eNB *eNB
     */
 
     if (eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0] == 1) {
-      if ((eNB->prach_energy_counter == 100) && (max_preamble_energy[0] > eNB->measurements.prach_I0 + 200)) {
+      if ((eNB->prach_energy_counter == 100) && (max_preamble_energy[0] > eNB->measurements.prach_I0 + eNB->prach_DTX_threshold_emtc[0])) {
         eNB->UL_INFO.rach_ind_br.rach_indication_body.number_of_preambles++;
 
         eNB->preamble_list_br[ind].preamble_rel8.timing_advance = max_preamble_delay[ind];      //
@@ -168,7 +169,7 @@ void prach_procedures(PHY_VARS_eNB *eNB
 
     {
       if ((eNB->prach_energy_counter == 100) && 
-          (max_preamble_energy[0] > eNB->measurements.prach_I0+100)) {
+          (max_preamble_energy[0] > eNB->measurements.prach_I0+eNB->prach_DTX_threshold)) {
 
 	LOG_I(PHY,"[eNB %d/%d][RAPROC] Frame %d, subframe %d Initiating RA procedure with preamble %d, energy %d.%d dB, delay %d\n",
 	      eNB->Mod_id,
diff --git a/openair2/COMMON/platform_types.h b/openair2/COMMON/platform_types.h
index ee8d6abcc9cb2e4b97ec53e0346e28ec59c44598..ef9f591958819c6d4d4f5aef784b6bddd204bece 100644
--- a/openair2/COMMON/platform_types.h
+++ b/openair2/COMMON/platform_types.h
@@ -236,9 +236,7 @@ typedef struct protocol_ctxt_s {
   sub_frame_t subframe;      /*!< \brief  LTE sub frame number.*/
   eNB_index_t eNB_index;     /*!< \brief  valid for UE indicating the index of connected eNB(s)      */
   boolean_t   configured;  /*!< \brief  flag indicating whether the instance is configured or not  */
-#ifdef Rel14
   boolean_t		brOption;
-#endif
 } protocol_ctxt_t;
 // warning time hardcoded
 #define PROTOCOL_CTXT_TIME_MILLI_SECONDS(CtXt_h) ((CtXt_h)->frame*10+(CtXt_h)->subframe)
diff --git a/openair2/COMMON/rrc_messages_types.h b/openair2/COMMON/rrc_messages_types.h
index 3880604e61f730203c7f665c5c6cd9da23f05e33..4a5851873b83b26e5fc429afc948fe6222eff3e1 100644
--- a/openair2/COMMON/rrc_messages_types.h
+++ b/openair2/COMMON/rrc_messages_types.h
@@ -148,7 +148,7 @@ typedef struct RadioResourceConfig_s {
   long                    ue_TimersAndConstants_n311;
   long                    ue_TransmissionMode;
   long                    ue_multiple_max;
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   //SIB2 BR Options
   long*			  preambleTransMax_CE_r13;
   BOOLEAN_t		  prach_ConfigCommon_v1310;
diff --git a/openair2/COMMON/x2ap_messages_def.h b/openair2/COMMON/x2ap_messages_def.h
index 65fa9c801dee5279383d0cbeefe57406fc682fb4..2a040c8000e9d001d8d0bc586fc30d6168fe39f4 100644
--- a/openair2/COMMON/x2ap_messages_def.h
+++ b/openair2/COMMON/x2ap_messages_def.h
@@ -32,6 +32,7 @@ MESSAGE_DEF(X2AP_SETUP_REQUEST_LOG              , MESSAGE_PRIORITY_MED, IttiMsgT
 
 /* eNB application layer -> X2AP messages */
 MESSAGE_DEF(X2AP_REGISTER_ENB_REQ               , MESSAGE_PRIORITY_MED, x2ap_register_enb_req_t          , x2ap_register_enb_req)
+MESSAGE_DEF(X2AP_SUBFRAME_PROCESS               , MESSAGE_PRIORITY_MED, x2ap_subframe_process_t          , x2ap_subframe_process)
 
 /* X2AP -> eNB application layer messages */
 MESSAGE_DEF(X2AP_REGISTER_ENB_CNF               , MESSAGE_PRIORITY_MED, x2ap_register_enb_cnf_t          , x2ap_register_enb_cnf)
@@ -40,6 +41,7 @@ MESSAGE_DEF(X2AP_DEREGISTERED_ENB_IND           , MESSAGE_PRIORITY_MED, x2ap_der
 /* handover messages X2AP <-> RRC */
 MESSAGE_DEF(X2AP_HANDOVER_REQ                   , MESSAGE_PRIORITY_MED, x2ap_handover_req_t              , x2ap_handover_req)
 MESSAGE_DEF(X2AP_HANDOVER_REQ_ACK               , MESSAGE_PRIORITY_MED, x2ap_handover_req_ack_t          , x2ap_handover_req_ack)
+MESSAGE_DEF(X2AP_HANDOVER_CANCEL                , MESSAGE_PRIORITY_MED, x2ap_handover_cancel_t           , x2ap_handover_cancel)
 
 /* handover messages X2AP <-> S1AP */
 MESSAGE_DEF(X2AP_UE_CONTEXT_RELEASE             , MESSAGE_PRIORITY_MED, x2ap_ue_context_release_t        , x2ap_ue_context_release)
diff --git a/openair2/COMMON/x2ap_messages_types.h b/openair2/COMMON/x2ap_messages_types.h
index 38429b712edc64caf6557a7bc98a710e308586da..708430b8b2a740c7f9d848d361333e12831dc789 100644
--- a/openair2/COMMON/x2ap_messages_types.h
+++ b/openair2/COMMON/x2ap_messages_types.h
@@ -34,6 +34,7 @@
 #define X2AP_REGISTER_ENB_CNF(mSGpTR)           (mSGpTR)->ittiMsg.x2ap_register_enb_cnf
 #define X2AP_DEREGISTERED_ENB_IND(mSGpTR)       (mSGpTR)->ittiMsg.x2ap_deregistered_enb_ind
 #define X2AP_UE_CONTEXT_RELEASE(mSGpTR)         (mSGpTR)->ittiMsg.x2ap_ue_context_release
+#define X2AP_HANDOVER_CANCEL(mSGpTR)            (mSGpTR)->ittiMsg.x2ap_handover_cancel
 
 
 #define X2AP_MAX_NB_ENB_IP_ADDRESS 2
@@ -48,6 +49,16 @@ typedef struct x2ap_ue_context_release_s {
   int source_assoc_id;
 } x2ap_ue_context_release_t;
 
+typedef enum {
+  X2AP_T_RELOC_PREP_TIMEOUT,
+  X2AP_TX2_RELOC_OVERALL_TIMEOUT
+} x2ap_handover_cancel_cause_t;
+
+typedef struct x2ap_handover_cancel_s {
+  int rnti;
+  x2ap_handover_cancel_cause_t cause;
+} x2ap_handover_cancel_t;
+
 typedef struct x2ap_register_enb_req_s {
   /* Unique eNB_id to identify the eNB within EPC.
    * For macro eNB ids this field should be 20 bits long.
@@ -105,8 +116,16 @@ typedef struct x2ap_register_enb_req_s {
 
   /* eNB port for X2C*/
   uint32_t enb_port_for_X2C;
+
+  /* timers (unit: millisecond) */
+  int t_reloc_prep;
+  int tx2_reloc_overall;
 } x2ap_register_enb_req_t;
 
+typedef struct x2ap_subframe_process_s {
+  /* nothing, we simply use the module ID in the header */
+} x2ap_subframe_process_t;
+
 //-------------------------------------------------------------------------------------------//
 // X2AP -> eNB application layer messages
 typedef struct x2ap_register_enb_cnf_s {
diff --git a/openair2/ENB_APP/L1_paramdef.h b/openair2/ENB_APP/L1_paramdef.h
index b062235ff69b6aaefb5cc40bff392419df524df3..210b753afbb19e84ba04693393651f1d73442373 100644
--- a/openair2/ENB_APP/L1_paramdef.h
+++ b/openair2/ENB_APP/L1_paramdef.h
@@ -44,7 +44,21 @@
 #define CONFIG_STRING_L1_LOCAL_N_PORTD                     "local_n_portd"
 #define CONFIG_STRING_L1_REMOTE_N_PORTD                    "remote_n_portd"
 #define CONFIG_STRING_L1_TRANSPORT_N_PREFERENCE            "tr_n_preference"
-
+#define CONFIG_STRING_L1_PRACH_DTX_THRESHOLD               "prach_dtx_threshold"
+#define CONFIG_STRING_L1_PUCCH1_DTX_THRESHOLD              "pucch1_dtx_threshold"
+#define CONFIG_STRING_L1_PUCCH1AB_DTX_THRESHOLD            "pucch1ab_dtx_threshold"
+#define CONFIG_STRING_L1_PRACH_DTX_EMTC0_THRESHOLD               "prach_dtx_emtc0_threshold"
+#define CONFIG_STRING_L1_PUCCH1_DTX_EMTC0_THRESHOLD              "pucch1_dtx_emtc0_threshold"
+#define CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC0_THRESHOLD            "pucch1ab_dtx_emtc0_threshold"
+#define CONFIG_STRING_L1_PRACH_DTX_EMTC1_THRESHOLD               "prach_dtx_emtc1_threshold"
+#define CONFIG_STRING_L1_PUCCH1_DTX_EMTC1_THRESHOLD              "pucch1_dtx_emtc1_threshold"
+#define CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC1_THRESHOLD            "pucch1ab_dtx_emtc1_threshold"
+#define CONFIG_STRING_L1_PRACH_DTX_EMTC2_THRESHOLD               "prach_dtx_emtc2_threshold"
+#define CONFIG_STRING_L1_PUCCH1_DTX_EMTC2_THRESHOLD              "pucch1_dtx_emtc2_threshold"
+#define CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC2_THRESHOLD            "pucch1ab_dtx_emtc2_threshold"
+#define CONFIG_STRING_L1_PRACH_DTX_EMTC3_THRESHOLD               "prach_dtx_emtc3_threshold"
+#define CONFIG_STRING_L1_PUCCH1_DTX_EMTC3_THRESHOLD              "pucch1_dtx_emtc3_threshold"
+#define CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC3_THRESHOLD            "pucch1ab_dtx_emtc3_threshold"
 /*----------------------------------------------------------------------------------------------------------------------------------------------------*/
 /*                                            L1 configuration parameters                                                                             */
 /*   optname                                         helpstr   paramflags    XXXptr              defXXXval                  type           numelt     */
@@ -59,7 +73,22 @@
 {CONFIG_STRING_L1_REMOTE_N_PORTC,                    NULL,      0,         uptr:NULL,           defintval:50030,           TYPE_UINT,     0},         \
 {CONFIG_STRING_L1_LOCAL_N_PORTD,                     NULL,      0,         uptr:NULL,           defintval:50031,           TYPE_UINT,     0},         \
 {CONFIG_STRING_L1_REMOTE_N_PORTD,                    NULL,      0,         uptr:NULL,           defintval:50031,           TYPE_UINT,     0},         \
-}
+{CONFIG_STRING_L1_PRACH_DTX_THRESHOLD,               NULL,      0,         iptr:NULL,           defintval:100,             TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1_DTX_THRESHOLD,              NULL,      0,         iptr:NULL,           defintval:0,                TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1AB_DTX_THRESHOLD,            NULL,      0,         iptr:NULL,           defintval:4,                TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PRACH_DTX_EMTC0_THRESHOLD,         NULL,      0,         iptr:NULL,           defintval:200,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1_DTX_EMTC0_THRESHOLD,        NULL,      0,         iptr:NULL,           defintval:0,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC0_THRESHOLD,      NULL,      0,         iptr:NULL,           defintval:4,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PRACH_DTX_EMTC1_THRESHOLD,         NULL,      0,         iptr:NULL,           defintval:200,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1_DTX_EMTC1_THRESHOLD,        NULL,      0,         iptr:NULL,           defintval:0,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC1_THRESHOLD,      NULL,      0,         iptr:NULL,           defintval:4,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PRACH_DTX_EMTC2_THRESHOLD,         NULL,      0,         iptr:NULL,           defintval:200,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1_DTX_EMTC2_THRESHOLD,        NULL,      0,         iptr:NULL,           defintval:0,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC2_THRESHOLD,      NULL,      0,         iptr:NULL,           defintval:4,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PRACH_DTX_EMTC3_THRESHOLD,         NULL,      0,         iptr:NULL,           defintval:200,           TYPE_INT,     0},         \
+{CONFIG_STRING_L1_PUCCH1_DTX_EMTC3_THRESHOLD,        NULL,      0,         iptr:NULL,           defintval:0,           TYPE_INT,     0},         \
+  {CONFIG_STRING_L1_PUCCH1AB_DTX_EMTC3_THRESHOLD,      NULL,      0,         iptr:NULL,           defintval:4,           TYPE_INT,     0} \
+  }
 #define L1_CC_IDX                                          0
 #define L1_TRANSPORT_N_PREFERENCE_IDX                      1
 #define L1_LOCAL_N_IF_NAME_IDX                             2
@@ -69,5 +98,19 @@
 #define L1_REMOTE_N_PORTC_IDX                              6
 #define L1_LOCAL_N_PORTD_IDX                               7
 #define L1_REMOTE_N_PORTD_IDX                              8
-
+#define L1_PRACH_DTX_THRESHOLD_IDX                         9
+#define L1_PUCCH1_DTX_THRESHOLD_IDX                        10
+#define L1_PUCCH1AB_DTX_THRESHOLD_IDX                      11
+#define L1_PRACH_DTX_EMTC0_THRESHOLD_IDX                   12
+#define L1_PUCCH1_DTX_EMTC0_THRESHOLD_IDX                  13
+#define L1_PUCCH1AB_DTX_EMTC0_THRESHOLD_IDX                14
+#define L1_PRACH_DTX_EMTC1_THRESHOLD_IDX                   15
+#define L1_PUCCH1_DTX_EMTC1_THRESHOLD_IDX                  16
+#define L1_PUCCH1AB_DTX_EMTC1_THRESHOLD_IDX                17
+#define L1_PRACH_DTX_EMTC2_THRESHOLD_IDX                   18
+#define L1_PUCCH1_DTX_EMTC2_THRESHOLD_IDX                  19
+#define L1_PUCCH1AB_DTX_EMTC2_THRESHOLD_IDX                20
+#define L1_PRACH_DTX_EMTC3_THRESHOLD_IDX                   21
+#define L1_PUCCH1_DTX_EMTC3_THRESHOLD_IDX                  22
+#define L1_PUCCH1AB_DTX_EMTC3_THRESHOLD_IDX                23
 /*----------------------------------------------------------------------------------------------------------------------------------------------------*/
diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c
index 8d128c03e22655cdb2031e9372238f4defcb205b..cba0211c51dc640273bb0dd0989793f0a122ceba 100644
--- a/openair2/ENB_APP/enb_app.c
+++ b/openair2/ENB_APP/enb_app.c
@@ -151,8 +151,8 @@ void *eNB_app_task(void *args_p) {
   uint32_t                        register_enb_pending=0;
   uint32_t                        registered_enb;
   long                            enb_register_retry_timer_id;
-  uint32_t                        x2_register_enb_pending;
-  uint32_t                        x2_registered_enb;
+  uint32_t                        x2_register_enb_pending = 0;
+  uint32_t                        x2_registered_enb = 0;
   long                            x2_enb_register_retry_timer_id;
   uint32_t                        enb_id;
   MessageDef                     *msg_p           = NULL;
@@ -188,9 +188,11 @@ void *eNB_app_task(void *args_p) {
     register_enb_pending = eNB_app_register (enb_id_start, enb_id_end);//, enb_properties_p);
   }
 
-  /* Try to register each eNB with each other */
-  x2_registered_enb = 0;
-  x2_register_enb_pending = eNB_app_register_x2 (enb_id_start, enb_id_end);
+  if (is_x2ap_enabled()) {
+    /* Try to register each eNB with each other */
+    x2_registered_enb = 0;
+    x2_register_enb_pending = eNB_app_register_x2 (enb_id_start, enb_id_end);
+  }
 
   do {
     // Wait for a message
diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c
index d4439ab349defe28e370bc8b85b92c36224c1160..6556a34e7bd4dbd27eefb801ab297ad49f9cc34b 100644
--- a/openair2/ENB_APP/enb_config.c
+++ b/openair2/ENB_APP/enb_config.c
@@ -236,6 +236,16 @@ void RCconfig_L1(void) {
                             RC.eNB[j][0]->eth_params_n     .remote_portd);
       } else { // other midhaul
       }
+      // PRACH/PUCCH parameters
+
+      RC.eNB[j][0]->prach_DTX_threshold    = *(L1_ParamList.paramarray[j][L1_PRACH_DTX_THRESHOLD_IDX].iptr);
+      RC.eNB[j][0]->pucch1_DTX_threshold   = *(L1_ParamList.paramarray[j][L1_PUCCH1_DTX_THRESHOLD_IDX].iptr);
+      RC.eNB[j][0]->pucch1ab_DTX_threshold = *(L1_ParamList.paramarray[j][L1_PUCCH1AB_DTX_THRESHOLD_IDX].iptr);
+      for (int ce_level=0;ce_level<4;ce_level++) {
+	RC.eNB[j][0]->prach_DTX_threshold_emtc[ce_level]    = *(L1_ParamList.paramarray[j][L1_PRACH_DTX_EMTC0_THRESHOLD_IDX+ce_level].iptr);
+	RC.eNB[j][0]->pucch1_DTX_threshold_emtc[ce_level]   = *(L1_ParamList.paramarray[j][L1_PUCCH1_DTX_EMTC0_THRESHOLD_IDX+ce_level].iptr);
+	RC.eNB[j][0]->pucch1ab_DTX_threshold_emtc[ce_level] = *(L1_ParamList.paramarray[j][L1_PUCCH1AB_DTX_EMTC0_THRESHOLD_IDX+ce_level].iptr);
+      }
     }// j=0..num_inst
 
     LOG_I(ENB_APP,"Initializing northbound interface for L1\n");
@@ -2053,6 +2063,28 @@ int RCconfig_X2(MessageDef *msg_p, uint32_t i) {
 	      }
 	    }
 	    
+            // timers
+            {
+              int t_reloc_prep = 0;
+              int tx2_reloc_overall = 0;
+
+              paramdef_t p[] = {
+                { "t_reloc_prep", "t_reloc_prep", 0, iptr:&t_reloc_prep, defintval:0, TYPE_INT, 0 },
+                { "tx2_reloc_overall", "tx2_reloc_overall", 0, iptr:&tx2_reloc_overall, defintval:0, TYPE_INT, 0 }
+              };
+
+              config_get(p, sizeof(p)/sizeof(paramdef_t), aprefix);
+
+              if (t_reloc_prep <= 0 || t_reloc_prep > 10000 ||
+                  tx2_reloc_overall <= 0 || tx2_reloc_overall > 20000) {
+                LOG_E(X2AP, "timers in configuration file have wrong values. We must have [0 < t_reloc_prep <= 10000] and [0 < tx2_reloc_overall <= 20000]\n");
+                exit(1);
+              }
+
+	      X2AP_REGISTER_ENB_REQ (msg_p).t_reloc_prep = t_reloc_prep;
+	      X2AP_REGISTER_ENB_REQ (msg_p).tx2_reloc_overall = tx2_reloc_overall;
+            }
+
 	    // SCTP SETTING
 	    X2AP_REGISTER_ENB_REQ (msg_p).sctp_out_streams = SCTP_OUT_STREAMS;
 	    X2AP_REGISTER_ENB_REQ (msg_p).sctp_in_streams  = SCTP_IN_STREAMS;
diff --git a/openair2/ENB_APP/enb_paramdef_emtc.h b/openair2/ENB_APP/enb_paramdef_emtc.h
index ba8483ef9f0fd6bb1d100098dd17bd356f802021..9f76bac2fa0ca6a1eef6ada061883453aee2afb6 100644
--- a/openair2/ENB_APP/enb_paramdef_emtc.h
+++ b/openair2/ENB_APP/enb_paramdef_emtc.h
@@ -67,7 +67,7 @@
 #define ENB_CONFIG_STRING_LAST_PREAMBLE_R13                                "lastPreamble_r13"
 #define ENB_CONFIG_STRING_RA_RESPONSE_WINDOW_SIZE_R13                      "ra_ResponseWindowSize_r13"
 #define ENB_CONFIG_STRING_MAC_CONTENTION_RESOLUTION_TIMER_R13              "mac_ContentionResolutionTimer_r13"
-#define ENB_CONFIG_STRING_RAR_HOPPING_CONFIG_R13                           "rar_HoppingConfig_r13  "
+#define ENB_CONFIG_STRING_RAR_HOPPING_CONFIG_R13                           "rar_HoppingConfig_r13"
 #define ENB_CONFIG_STRING_RACH_CE_LEVELINFOLIST_R13                        "rach_CE_LevelInfoList_r13"
 #define ENB_CONFIG_STRING_PRACH_CONFIG_INDEX_BR                            "prach_config_index_br"
 #define ENB_CONFIG_STRING_PRACH_FREQ_OFFSET_BR                             "prach_freq_offset_br"
diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h
index 6af0fd66ca9ed25f74c950970e7557a72ba6a18b..0ec0f6a723c97e1432a49981ca3c8bb4a9c964a2 100644
--- a/openair2/LAYER2/MAC/defs.h
+++ b/openair2/LAYER2/MAC/defs.h
@@ -61,13 +61,13 @@
 #include "RACH-ConfigCommon.h"
 #include "MeasObjectToAddModList.h"
 #include "MobilityControlInfo.h"
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 #include "MBSFN-AreaInfoList-r9.h"
 #include "MBSFN-SubframeConfigList.h"
 #include "PMCH-InfoList-r9.h"
 #include "SCellToAddMod-r10.h"
 #endif
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 #include "SystemInformationBlockType1-v1310-IEs.h"
 #endif
 
@@ -87,7 +87,7 @@
 #define SCH_PAYLOAD_SIZE_MAX 4096
 /// Logical channel ids from 36-311 (Note BCCH is not specified in 36-311, uses the same as first DRB)
 
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 
 // Mask for identifying subframe for MBMS
 #define MBSFN_TDD_SF3 0x80// for TDD
@@ -283,7 +283,7 @@ typedef struct {
   uint8_t payload[PCCH_PAYLOAD_SIZE_MAX] ;
 } __attribute__((__packed__))PCCH_PDU;
 
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 /*! \brief MCCH payload */
 typedef struct {
   uint8_t payload[MCCH_PAYLOAD_SIZE_MAX] ;
@@ -340,7 +340,7 @@ typedef struct {
 /*!\brief LCID of padding LCID for DLSCH */
 #define SHORT_PADDING 31
 
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
 // MCH LCHAN IDs (table6.2.1-4 TS36.321)
 /*!\brief LCID of MCCH for DL */
 #define MCCH_LCHANID 0
@@ -759,7 +759,7 @@ typedef struct {
   eNB_UE_estimated_distances distance;
 #endif
 
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint8_t rach_resource_type;
 
  uint16_t mpdcch_repetition_cnt;
@@ -923,7 +923,7 @@ typedef struct {
   uint8_t msg4_rrc_sdu_length;
   uint32_t msg4_delay;
 
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   uint8_t rach_resource_type;
   uint8_t msg2_mpdcch_repetition_cnt;
   uint8_t msg2_mpdcch_done;
@@ -985,7 +985,7 @@ typedef struct {
   uint32_t                         dl_CarrierFreq;
   BCCH_BCH_Message_t               *mib;
   RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon;
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon_BR;  
 #endif
   TDD_Config_t                     *tdd_Config;
@@ -1012,7 +1012,7 @@ typedef struct {
   struct MBSFN_SubframeConfig *mbsfn_SubframeConfig[8];
   /// number of subframe allocation pattern available for MBSFN sync area
   uint8_t num_sf_allocation_pattern;
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   /// MBMS Flag
   uint8_t MBMS_flag;
   /// Outgoing MCCH pdu for PHY
@@ -1034,7 +1034,7 @@ typedef struct {
   /// Outgoing MCH pdu for PHY
   MCH_PDU MCH_pdu;
 #endif
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   /// Rel13 parameters from SIB1
   SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext;
   /// Counter for SIB1-BR scheduling
@@ -1222,7 +1222,7 @@ typedef struct {
   struct RACH_ConfigDedicated *rach_ConfigDedicated;
   /// pointer to RRC PHY configuration
   struct PhysicalConfigDedicated *physicalConfigDedicated;
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   /// pointer to RRC PHY configuration SCEll
   struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10;
 #endif
@@ -1298,7 +1298,7 @@ typedef struct {
   struct MBSFN_SubframeConfig *mbsfn_SubframeConfig[8]; // FIXME replace 8 by MAX_MBSFN_AREA?
   /// number of subframe allocation pattern available for MBSFN sync area
   uint8_t num_sf_allocation_pattern;
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
   /// number of active MBSFN area
   uint8_t num_active_mbsfn_area;
   /// MBSFN Area Info
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 4ebe7313e8764d2658382b6a7445c938a6c6b5f5..42f09dc90f66d1779d39b99e7b02cd9b98cfa761 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -261,12 +261,9 @@ schedule_SR(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
       ul_req_body   = &ul_req->ul_config_request_body;
 
       // drop the allocation if the UE hasn't send RRCConnectionSetupComplete yet
-      if (mac_eNB_get_rrc_status(module_idP, UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED) continue;
+      //if (mac_eNB_get_rrc_status(module_idP, UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED) continue;
 
-      AssertFatal(UE_list->
-		  UE_template[CC_id][UE_id].physicalConfigDedicated!= NULL,
-		  "physicalConfigDedicated is null for UE %d\n",
-		  UE_id);
+      if (UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated== NULL) continue;
 
       if ((SRconfig = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->schedulingRequestConfig) != NULL) {
 	if (SRconfig->present == LTE_SchedulingRequestConfig_PR_setup) {
@@ -681,9 +678,9 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP,
     schedule_SR(module_idP, frameP, subframeP);
     // This schedules UCI_CSI in subframeP
     schedule_CSI(module_idP, frameP, subframeP);
-#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
     // This schedules DLSCH in subframeP
-    schedule_ue_spec_br(module_idP,frameP,subframeP);
+    schedule_ue_spec_br(module_idP, frameP, subframeP);
 #endif
     // This schedules DLSCH in subframeP
     if (schedule_ue_spec_p != NULL) {
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index ff4b1e6517b3693bb3ebe874a1ecf9040346a252..2ebb45e68ec2e68aeb66f68b91c01bc47bdedb96 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -122,9 +122,9 @@ add_msg3(module_id_t module_idP, int CC_id, RA_t * ra, frame_t frameP,
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
   if (ra->rach_resource_type > 0) {
-    LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : CC_id %d CE level %d is active, Msg3 in (%d,%d)\n",
+    LOG_D (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : CC_id %d CE level %d is active, Msg3 in (%d,%d)\n",
            module_idP, frameP, subframeP, CC_id, ra->rach_resource_type - 1, ra->Msg3_frame, ra->Msg3_subframe);
-    LOG_I (MAC, "Frame %d, Subframe %d Adding Msg3 UL Config Request for (%d,%d) : (%d,%d)\n",
+    LOG_D (MAC, "Frame %d, Subframe %d Adding Msg3 UL Config Request for (%d,%d) : (%d,%d)\n",
            frameP, subframeP, ra->Msg3_frame, ra->Msg3_subframe, ra->msg3_nb_rb, ra->msg3_round);
 
     ul_config_pdu = &ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus];
@@ -239,21 +239,27 @@ add_msg3(module_id_t module_idP, int CC_id, RA_t * ra, frame_t frameP,
     }				// non-BL/CE UE case
 }
 
-void
-generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
-	      sub_frame_t subframeP, RA_t * ra)
+//------------------------------------------------------------------------------
+/*
+ * Generate the RAR (message2)
+ */
+void generate_Msg2(module_id_t module_idP, 
+              int CC_idP, 
+              frame_t frameP,
+	            sub_frame_t subframeP, 
+              RA_t *ra)
+//------------------------------------------------------------------------------
 {
-
-
   eNB_MAC_INST *mac = RC.mac[module_idP];
   COMMON_channels_t *cc = mac->common_channels;
   
-  uint8_t *vrb_map;
-  int first_rb;
-  int N_RB_DL;
-  nfapi_dl_config_request_pdu_t *dl_config_pdu;
-  nfapi_tx_request_pdu_t *TX_req;
-  nfapi_dl_config_request_body_t *dl_req_body;
+  uint8_t *vrb_map = NULL;
+  int first_rb = 0;
+  int N_RB_DL = 0;
+
+  nfapi_dl_config_request_pdu_t *dl_config_pdu = NULL;
+  nfapi_tx_request_pdu_t *TX_req = NULL;
+  nfapi_dl_config_request_body_t *dl_req_body = NULL;
   
   vrb_map = cc[CC_idP].vrb_map;
   dl_req_body = &mac->DL_req[CC_idP].dl_config_request_body;
@@ -261,74 +267,81 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
   N_RB_DL = to_prb(cc[CC_idP].mib->message.dl_Bandwidth);
   
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-  int             rmax = 0;
-  int             rep = 0;
-  int             reps = 0;
-  int             num_nb = 0;
+  int rmax = 0;
+  int rep = 0;
+  int reps = 0;
+  int num_nb = 0;
 
   first_rb = 0;
-  struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach;
-  LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13;
+  struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = NULL;
+  LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL;
   LTE_PRACH_ParametersCE_r13_t *p[4] = { NULL, NULL, NULL, NULL };
 
-  uint16_t        absSF = (10 * frameP) + subframeP;
-  uint16_t        absSF_Msg2 = (10 * ra->Msg2_frame) + ra->Msg2_subframe;
-
-  if (absSF > absSF_Msg2)
-    return;                     // we're not ready yet, need to be to start ==  
+  uint16_t absSF = (10 * frameP) + subframeP;
+  uint16_t absSF_Msg2 = (10 * ra->Msg2_frame) + ra->Msg2_subframe;
 
-  if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && 
-      cc[CC_idP].radioResourceConfigCommon_BR) {
+  if (absSF > absSF_Msg2) {
+    return; // we're not ready yet
+  }
 
+  if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && cc[CC_idP].radioResourceConfigCommon_BR) {
     ext4_prach = cc[CC_idP].radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
     prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
 
     switch (prach_ParametersListCE_r13->list.count) {
-    case 4:
-      p[3] = prach_ParametersListCE_r13->list.array[3];
-    case 3:
-      p[2] = prach_ParametersListCE_r13->list.array[2];
-    case 2:
-      p[1] = prach_ParametersListCE_r13->list.array[1];
-    case 1:
-      p[0] = prach_ParametersListCE_r13->list.array[0];
-      break;
-    default:
-      AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", (int) prach_ParametersListCE_r13->list.count);
-      break;
-
+      case 4:
+        p[3] = prach_ParametersListCE_r13->list.array[3];
+      case 3:
+        p[2] = prach_ParametersListCE_r13->list.array[2];
+      case 2:
+        p[1] = prach_ParametersListCE_r13->list.array[1];
+      case 1:
+        p[0] = prach_ParametersListCE_r13->list.array[0];
+        break;
+      default:
+        AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", (int) prach_ParametersListCE_r13->list.count);
+        break;
     }
   }
 
   if (ra->rach_resource_type > 0) {
+    /* This uses an MPDCCH Type 2 common allocation according to Section 9.1.5 36-213
+     * Parameters:
+     *    p = 2 + 4 PRB set (number of PRB pairs 3)
+     *    rmax = mpdcch-NumRepetition-RA-r13 => Table 9.1.5-3
+     *    if CELevel = 0,1 => Table 9.1.5-1b for MPDCCH candidates
+     *    if CELevel = 2,3 => Table 9.1.5-2b for MPDCCH candidates
+     *    distributed transmission
+     */
 
-    // This uses an MPDCCH Type 2 common allocation according to Section 9.1.5 36-213
-    // Parameters:
-    //    p=2+4 PRB set (number of PRB pairs 3)
-    //    rmax = mpdcch-NumRepetition-RA-r13 => Table 9.1.5-3
-    //    if CELevel = 0,1 => Table 9.1.5-1b for MPDCCH candidates
-    //    if CELevel = 2,3 => Table 9.1.5-2b for MPDCCH candidates
-    //    distributed transmission
-
-    // rmax from SIB2 information
-    AssertFatal (rmax < 9, "rmax>8!\n");
+    /* rmax from SIB2 information */
+    AssertFatal (rmax < 9, "rmax > 8!\n"); // not sure of this assertion
     rmax = 1 << p[ra->rach_resource_type - 1]->mpdcch_NumRepetition_RA_r13;
-    // choose r1 by default for RAR (Table 9.1.5-5)
+    
+    /* Choose r1 by default for RAR (Table 9.1.5-5) */
     rep = 0;
-    // get actual repetition count from Table 9.1.5-3
+    
+    /* Get actual repetition count from Table 9.1.5-3 */
     reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep));
-    // get narrowband according to higher-layer config 
+    
+    /* Get narrowband according to higher-layer config */
     num_nb = p[ra->rach_resource_type - 1]->mpdcch_NarrowbandsToMonitor_r13.list.count;
-    ra->msg2_narrowband = *p[ra->rach_resource_type - 1]->mpdcch_NarrowbandsToMonitor_r13.list.array[ra->preamble_index % num_nb]-1;
-    first_rb = narrowband_to_first_rb (&cc[CC_idP], ra->msg2_narrowband);
+    ra->msg2_narrowband = *p[ra->rach_resource_type - 1]->mpdcch_NarrowbandsToMonitor_r13.list.array[ra->preamble_index % num_nb] - 1;
+    first_rb = narrowband_to_first_rb(&cc[CC_idP], ra->msg2_narrowband);
 
-    if ((ra->msg2_mpdcch_repetition_cnt == 0) && (mpdcch_sf_condition (mac, CC_idP, frameP, subframeP, rmax, TYPE2, -1) > 0)) {
+    if ((ra->msg2_mpdcch_repetition_cnt == 0) && (mpdcch_sf_condition(mac, CC_idP, frameP, subframeP, rmax, TYPE2, -1) > 0)) {
       ra->msg2_mpdcch_done = 0;
-      // MPDCCH configuration for RAR
-      LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2 for CE Level %d, Programming MPDCCH %d repetitions\n", module_idP, frameP, subframeP, ra->rach_resource_type-1,reps);
 
+      /* MPDCCH configuration for RAR */
+      LOG_D(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2 for CE Level %d, Programming MPDCCH %d repetitions\n", 
+            module_idP, 
+            frameP, 
+            subframeP, 
+            ra->rach_resource_type - 1,
+            reps);
 
       memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t));
+
       dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE;
       dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu));
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (ra->rach_resource_type > 1) ? 11 : 10;
@@ -336,7 +349,9 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6;
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = 1;   // imposed (9.1.5 in 213) for Type 2 Common search space  
+      
       AssertFatal (cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 != NULL, "cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n");
+
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0;        // Note: this should be dynamic
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 24;        // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
@@ -346,7 +361,7 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = cc[CC_idP].physCellId;
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000;     // 0dB
-      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV (6, 0, 6) | (ra->msg2_narrowband<<5);      
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV(6, 0, 6) | (ra->msg2_narrowband<<5);      
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 0;       // adjust according to size of RAR, 208 bits with N1A_PRB=3
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 0;    // fix to 4 for now
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = 0;
@@ -373,51 +388,64 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0;
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0;        // this is not needed by OAI L1, but should be filled in
       dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1;
+      
       ra->msg2_mpdcch_repetition_cnt++;
       dl_req_body->number_pdu++;
       ra->Msg2_subframe = (ra->Msg2_subframe + 9) % 10;
+    } // repetition_count == 0 && SF condition met
 
-    }                           //repetition_count==0 && SF condition met
     if (ra->msg2_mpdcch_repetition_cnt > 0) {  // we're in a stream of repetitions
+      if ((ra->msg2_mpdcch_repetition_cnt == reps) && (ra->msg2_mpdcch_done == 0)) {  // this is the last mpdcch repetition
+	      ra->msg2_mpdcch_done = 1;
 
-
-      if ((ra->msg2_mpdcch_repetition_cnt == reps)&&
-	  (ra->msg2_mpdcch_done == 0)){    // this is the last mpdcch repetition
-	ra->msg2_mpdcch_done = 1;
-        if (cc[CC_idP].tdd_Config == NULL) {    // FDD case
+        if (cc[CC_idP].tdd_Config == NULL) { // FDD case
           // wait 2 subframes for PDSCH transmission
           if (subframeP > 7)
             ra->Msg2_frame = (frameP + 1) & 1023;
           else
             ra->Msg2_frame = frameP;
-          ra->Msg2_subframe = (subframeP + 2) % 10;    // +2 is the "n+x" from Section 7.1.11  in 36.213
-          LOG_I(MAC,"[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, programmed Msg2 for %d.%d\n", module_idP, frameP, subframeP, ra->Msg2_frame,ra->Msg2_subframe); 
+            ra->Msg2_subframe = (subframeP + 2) % 10; // +2 is the "n+x" from Section 7.1.11  in 36.213
+          
+          LOG_D(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, programmed Msg2 for %d.%d\n", 
+                module_idP, 
+                frameP, 
+                subframeP, 
+                ra->Msg2_frame,
+                ra->Msg2_subframe); 
         } else {
-          AssertFatal (1 == 0, "TDD case not done yet\n");
+          AssertFatal(1 == 0, "TDD case not done yet\n");
         }
-      }                         // mpdcch_repetition_count == reps
-      else if (ra->msg2_mpdcch_done == 0) {
-        LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, MPDCCH repetition %d\n", module_idP, frameP, subframeP, ra->msg2_mpdcch_repetition_cnt);
+      } else if (ra->msg2_mpdcch_done == 0) {  // mpdcch_repetition_count != reps
+        LOG_D(MAC,"[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, MPDCCH repetition %d\n", 
+               module_idP, 
+               frameP, 
+               subframeP, 
+               ra->msg2_mpdcch_repetition_cnt);
+
         ra->msg2_mpdcch_repetition_cnt++;
       }
 
-
-      if ((ra->Msg2_frame == frameP) && (ra->Msg2_subframe == subframeP)) {
-        // Program PDSCH
-        LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming PDSCH\n", module_idP, frameP, subframeP);
+      if((ra->Msg2_frame == frameP) && (ra->Msg2_subframe == subframeP)) {
+        /* Program PDSCH */
+        LOG_D(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming PDSCH\n", 
+              module_idP, 
+              frameP, 
+              subframeP);
 
         dl_config_pdu = &dl_req_body->dl_config_pdu_list[dl_req_body->number_pdu];
+        
         memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t));
+        
         dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE;
         dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_dlsch_pdu));
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = mac->pdu_index[CC_idP];
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = ra->RA_rnti;
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2;
-        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0;     // localized
-        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV (N_RB_DL, first_rb, 6);
-        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK
+        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0; // localized
+        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(N_RB_DL, first_rb, 6);
+        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; // QPSK
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0;
-        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1;   // first block
+        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1; // first block
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0;
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc[CC_idP].p_eNB == 1) ? 0 : 1;
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1;
@@ -427,28 +455,36 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0;
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0;
-        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize (cc[CC_idP].mib->message.dl_Bandwidth); // ignored
+        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize(cc[CC_idP].mib->message.dl_Bandwidth); // ignored
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc[CC_idP].p_eNB == 1) ? 1 : 2;
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1;
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1;
         //      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ; 
 
-        // Rel10 fields
+        /* Rel10 fields */
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = cc[CC_idP].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
-        // Rel13 fields
+
+        /* Rel13 fields */
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (ra->rach_resource_type < 3) ? 1 : 2;;
-        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2;        // not SI message
+        dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2; // not SI message
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP;
         dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0;
         dl_req_body->number_pdu++;
 
-	fill_rar_br (mac, CC_idP, ra, frameP, subframeP, cc[CC_idP].RAR_pdu.payload, ra->rach_resource_type - 1)     ; 
-// Program UL processing for Msg3, same as regular LTE
+	      fill_rar_br(mac, CC_idP, ra, frameP, subframeP, cc[CC_idP].RAR_pdu.payload, ra->rach_resource_type - 1);
+        
+        /* Program UL processing for Msg3, same as regular LTE */
         get_Msg3alloc (&cc[CC_idP], subframeP, frameP, &ra->Msg3_frame, &ra->Msg3_subframe);
         add_msg3 (module_idP, CC_idP, ra, frameP, subframeP);
-	ra->state = WAITMSG3;
-        // DL request
-        LOG_I (MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming TX Req\n", module_idP, frameP, subframeP);
+
+	      ra->state = WAITMSG3;
+
+        /* DL request */
+        LOG_D(MAC, "[eNB %d][RAPROC] Frame %d, Subframe %d : In generate_Msg2, Programming TX Req\n", 
+              module_idP, 
+              frameP, 
+              subframeP);
+
         mac->TX_req[CC_idP].sfn_sf = (frameP << 4) + subframeP;
         TX_req = &mac->TX_req[CC_idP].tx_request_body.tx_pdu_list[mac->TX_req[CC_idP].tx_request_body.number_of_pdus];
         TX_req->pdu_length = 7; // This should be changed if we have more than 1 preamble 
@@ -459,7 +495,6 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
         mac->TX_req[CC_idP].tx_request_body.number_of_pdus++;
       }
     }
-
   } else
 
 #endif
@@ -571,104 +606,115 @@ generate_Msg2(module_id_t module_idP, int CC_idP, frame_t frameP,
 	}			// Msg2 frame/subframe condition
     }				// else BL/CE
 }
-void
-generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
-	      sub_frame_t subframeP, RA_t * ra)
-{
 
-  
+//------------------------------------------------------------------------------
+/*
+ * Generate message 4 of RA procedure (RRC connection setup)
+ */
+void
+generate_Msg4(module_id_t module_idP, 
+              int CC_idP, 
+              frame_t frameP,
+	            sub_frame_t subframeP, 
+              RA_t * ra)
+//------------------------------------------------------------------------------
+{  
   eNB_MAC_INST *mac = RC.mac[module_idP];
   COMMON_channels_t *cc = mac->common_channels;
-  int16_t rrc_sdu_length;
+  UE_list_t *UE_list = &(mac->UE_list);
+
+  int16_t rrc_sdu_length = 0;
+  uint16_t msg4_padding = 0;
+  uint16_t msg4_post_padding = 0;
+  uint16_t msg4_header = 0;
   int UE_id = -1;
-  uint16_t msg4_padding;
-  uint16_t msg4_post_padding;
-  uint16_t msg4_header;
+  int first_rb = 0;
+  int N_RB_DL = 0;
+  uint8_t lcid = 0;
+  uint8_t offset = 0;
+  uint8_t *vrb_map = NULL;
   
-  uint8_t                         *vrb_map;
-  int                             first_rb;
-  int                             N_RB_DL;
-  nfapi_dl_config_request_pdu_t   *dl_config_pdu;
-  nfapi_ul_config_request_pdu_t   *ul_config_pdu;
-  nfapi_tx_request_pdu_t          *TX_req;
-  UE_list_t                       *UE_list=&mac->UE_list;
-  nfapi_dl_config_request_t      *dl_req;
-  nfapi_dl_config_request_body_t *dl_req_body;
-  nfapi_ul_config_request_body_t *ul_req_body;
-  uint8_t                         lcid;
-  uint8_t                         offset;
-
+  nfapi_dl_config_request_pdu_t   *dl_config_pdu = NULL;
+  nfapi_ul_config_request_pdu_t   *ul_config_pdu = NULL;
+  nfapi_tx_request_pdu_t          *TX_req = NULL;
 
+  nfapi_dl_config_request_t      *dl_req = NULL;
+  nfapi_dl_config_request_body_t *dl_req_body = NULL;
+  nfapi_ul_config_request_body_t *ul_req_body = NULL;
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-  int             rmax = 0;
-  int             rep = 0;
-  int             reps = 0;
-
+  int rmax = 0;
+  int rep = 0;
+  int reps = 0;
 
   first_rb = 0;
-  struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach;
-  struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch;
-  LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13;
-  struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13;
+
+  struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = NULL;
+  struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch = NULL;
+  LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL;
+  struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13 = NULL;
   LTE_PRACH_ParametersCE_r13_t *p[4] = { NULL, NULL, NULL, NULL };
   int             pucchreps[4] = { 1, 1, 1, 1 };
   int             n1pucchan[4] = { 0, 0, 0, 0 };
 
-  if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && 
-      cc[CC_idP].radioResourceConfigCommon_BR) {
+  if (cc[CC_idP].mib->message.schedulingInfoSIB1_BR_r13 > 0 && cc[CC_idP].radioResourceConfigCommon_BR) {
 
     ext4_prach = cc[CC_idP].radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
-    ext4_pucch = cc[CC_idP].radioResourceConfigCommon_BR->ext4->pucch_ConfigCommon_v1310;
     prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
+
+    ext4_pucch = cc[CC_idP].radioResourceConfigCommon_BR->ext4->pucch_ConfigCommon_v1310;
     pucch_N1PUCCH_AN_InfoList_r13 = ext4_pucch->n1PUCCH_AN_InfoList_r13;
+    
     AssertFatal (prach_ParametersListCE_r13 != NULL, "prach_ParametersListCE_r13 is null\n");
     AssertFatal (pucch_N1PUCCH_AN_InfoList_r13 != NULL, "pucch_N1PUCCH_AN_InfoList_r13 is null\n");
-    // check to verify CE-Level compatibility in SIB2_BR
+    
+    /* Check to verify CE-Level compatibility in SIB2_BR */
     AssertFatal (prach_ParametersListCE_r13->list.count == pucch_N1PUCCH_AN_InfoList_r13->list.count, "prach_ParametersListCE_r13->list.count!= pucch_N1PUCCH_AN_InfoList_r13->list.count\n");
 
     switch (prach_ParametersListCE_r13->list.count) {
-    case 4:
-      p[3] = prach_ParametersListCE_r13->list.array[3];
-      n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n");
-      pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13);
-
-    case 3:
-      p[2] = prach_ParametersListCE_r13->list.array[2];
-      n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n");
-      pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13);
-    case 2:
-      p[1] = prach_ParametersListCE_r13->list.array[1];
-      n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n");
-      pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13);
-    case 1:
-      p[0] = prach_ParametersListCE_r13->list.array[0];
-      n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n");
-      pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13);
-      break;
-    default:
-      AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count);
-
+      case 4:
+        p[3] = prach_ParametersListCE_r13->list.array[3];
+        n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3];
+        AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n");
+        pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13);
+
+      case 3:
+        p[2] = prach_ParametersListCE_r13->list.array[2];
+        n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2];
+        AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n");
+        pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13);
+      case 2:
+        p[1] = prach_ParametersListCE_r13->list.array[1];
+        n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1];
+        AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n");
+        pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13);
+      case 1:
+        p[0] = prach_ParametersListCE_r13->list.array[0];
+        n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0];
+        AssertFatal(ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n");
+        pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13);
+        break;
+      default:
+        AssertFatal(1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count);
     }
   }
 
 #endif
 
-
     vrb_map = cc[CC_idP].vrb_map;
 
     dl_req        = &mac->DL_req[CC_idP];
     dl_req_body   = &dl_req->dl_config_request_body;
     dl_config_pdu = &dl_req_body->dl_config_pdu_list[dl_req_body->number_pdu];
+    
     N_RB_DL = to_prb(cc[CC_idP].mib->message.dl_Bandwidth);
 
     UE_id = find_UE_id(module_idP, ra->rnti);
+    
     if (UE_id < 0) {
-      LOG_E(MAC,"Can't find UE for t-crnti %x, kill RA procedure for this UE\n",ra->rnti);
+      LOG_E(MAC, "Can't find UE for t-crnti %x, kill RA procedure for this UE\n",
+            ra->rnti);
+            
       cancel_ra_proc(module_idP, CC_idP, frameP, ra->rnti);
       return;
     }
@@ -725,7 +771,7 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
       AssertFatal (ra->msg4_rrc_sdu_length > 0, "[MAC][eNB Scheduler] CCCH not allocated\n");
       
       
-      LOG_I (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: UE_id %d, rrc_sdu_length %d, dl_req->num_pdu %d\n", module_idP, CC_idP, frameP, subframeP, UE_id, ra->msg4_rrc_sdu_length,dl_req_body->number_pdu);
+      LOG_D (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: UE_id %d, rrc_sdu_length %d, dl_req->num_pdu %d\n", module_idP, CC_idP, frameP, subframeP, UE_id, ra->msg4_rrc_sdu_length,dl_req_body->number_pdu);
       
       // MPDCCH configuration for Msg4
       ra->msg4_mpdcch_done=0;
@@ -783,7 +829,7 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
     
     if ((ra->msg4_mpdcch_repetition_cnt > 0)&&
 	(ra->msg4_mpdcch_done==0)) {     // we're in a stream of repetitions
-      LOG_I(MAC,"SFN.SF %d.%d : msg4 mpdcch repetition number %d/%d\n",
+      LOG_D(MAC,"SFN.SF %d.%d : msg4 mpdcch repetition number %d/%d\n",
 	    frameP,subframeP,ra->msg4_mpdcch_repetition_cnt,reps);
       if (ra->msg4_mpdcch_repetition_cnt == reps) {    // this is the last mpdcch repetition
         ra->msg4_mpdcch_done = 1;
@@ -794,7 +840,7 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
           else
             ra->Msg4_frame = frameP;
           ra->Msg4_subframe = (subframeP + 2) % 10;
-	  LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Set Msg4 PDSCH in %d.%d\n",
+	  LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Set Msg4 PDSCH in %d.%d\n",
 		module_idP, CC_idP, frameP, subframeP, ra->Msg4_frame,ra->Msg4_subframe);
         } else {
           AssertFatal (1 == 0, "TDD case not done yet\n");
@@ -808,7 +854,7 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
       
       // Program PDSCH
       
-      LOG_I (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 BR with RRC Piggyback (ce_level %d RNTI %x)\n",
+      LOG_D (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 BR with RRC Piggyback (ce_level %d RNTI %x)\n",
 	     module_idP, CC_idP, frameP, subframeP, ra->rach_resource_type - 1, ra->rnti);
       
       
@@ -864,7 +910,7 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
 	msg4_post_padding = ra->msg4_TBsize - ra->msg4_rrc_sdu_length - msg4_header - 1;
       }
       
-      LOG_I (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d subframeP %d Msg4 : TBS %d, sdu_len %d, msg4_header %d, msg4_padding %d, msg4_post_padding %d\n",
+      LOG_D (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d subframeP %d Msg4 : TBS %d, sdu_len %d, msg4_header %d, msg4_padding %d, msg4_post_padding %d\n",
 	     module_idP, CC_idP, frameP, subframeP, ra->msg4_TBsize, ra->msg4_rrc_sdu_length, msg4_header, msg4_padding, msg4_post_padding);
       DevAssert (UE_id != UE_INDEX_INVALID);  // FIXME not sure how to gracefully return
       // CHECK THIS: &cc[CC_idP].CCCH_pdu.payload[0]
@@ -1208,9 +1254,10 @@ check_Msg4_retransmission(module_id_t module_idP, int CC_idP,
     if (round != 8) {
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-	if (ra->rach_resource_type > 0) {
+	if (ra->rach_resource_type > 0 && round > 0) {
 	    AssertFatal(1 == 0,
-			"Msg4 Retransmissions not handled yet for BL/CE UEs\n");
+			"Msg4 Retransmissions not handled yet for BL/CE UEs, Frame %d, subframeP %d harq_pid %d round %d, UE_id: %d \n",
+                        frameP, subframeP, ra->harq_pid, round, UE_id);
 	} else
 #endif
 	{
@@ -1542,7 +1589,7 @@ cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP,
         ra[i].RRC_timer = 20;
         ra[i].rnti = 0;
         ra[i].msg3_round = 0;
-        LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Canceled RA procedure for UE rnti %x\n", module_idP, CC_id, frameP, rnti);
+        LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Canceled RA procedure for UE rnti %x\n", module_idP, CC_id, frameP, rnti);
       }
     }
 }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
index 26eef0be27e54da4eab7ccbbaf1f1858f6db3518..f848207b7bfe4207c394c79832b24752b16286f4 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
@@ -456,1078 +456,6 @@ void  getRepetition(UE_TEMPLATE * pue_template,unsigned int *maxRep , unsigned i
 
 }
 
-
-
-/*void
-schedule_ue_spec_br(
-    module_id_t   module_idP,
-    frame_t       frameP,
-    sub_frame_t   subframeP,
-    int*          mbsfn_flag
-)
-//------------------------------------------------------------------------------
-{
-	uint8_t                        CC_id;
-	int                            UE_id;
-	unsigned char                  aggregation;
-	mac_rlc_status_resp_t          rlc_status;
-	unsigned char                  header_len_dcch = 0, header_len_dcch_tmp = 0;
-	unsigned char                  header_len_dtch = 0, header_len_dtch_tmp = 0, header_len_dtch_last = 0;
-	unsigned char                  ta_len = 0;
-	unsigned char                  sdu_lcids[NB_RB_MAX], lcid, offset, num_sdus = 0;
-	uint16_t                       nb_rb, nb_rb_temp, nb_available_rb;
-	uint16_t                       TBS, j, sdu_lengths[NB_RB_MAX], rnti, padding = 0, post_padding = 0;
-	unsigned char                  dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES];
-	unsigned char                  round = 0;
-	unsigned char                  harq_pid = 0;
-	eNB_UE_STATS                   *eNB_UE_stats = NULL;
-	uint16_t                       sdu_length_total = 0;
-
-	eNB_MAC_INST                   *eNB = RC.mac[module_idP];
-	COMMON_channels_t              *cc = eNB->common_channels;
-	UE_list_t                      *UE_list = &eNB->UE_list;
-	int                            continue_flag = 0;
-	int32_t                        normalized_rx_power, target_rx_power;
-	int32_t                        tpc = 1;
-	static int32_t                 tpc_accumulated = 0;
-	UE_sched_ctrl                  *ue_sched_ctl;
-	int                            mcs;
-	int                            i;
-	int                            min_rb_unit[MAX_NUM_CCs];
-	int                            N_RB_DL[MAX_NUM_CCs];
-	int                            total_nb_available_rb[MAX_NUM_CCs];
-	int                            N_RBG[MAX_NUM_CCs];
-	nfapi_dl_config_request_body_t *dl_req;
-	nfapi_dl_config_request_pdu_t  *dl_config_pdu;
-	nfapi_tx_request_pdu_t         *TX_req;
-	int                            tdd_sfa;
-
-#if 0
-	if (UE_list->head == -1) {
-		return;
-	}
-#endif
-
-	uint8_t                         *vrb_map;
-	int								first_rb;
-	start_meas(&eNB->schedule_dlsch);
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_IN);
-
-
-
-	aggregation = 2;
-	for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-		N_RB_DL[CC_id] = to_prb(cc[CC_id].mib->message.dl_Bandwidth);
-		min_rb_unit[CC_id] = get_min_rb_unit(module_idP, CC_id);
-		// get number of PRBs less those used by common channels
-		total_nb_available_rb[CC_id] = N_RB_DL[CC_id];
-		for (i = 0; i < N_RB_DL[CC_id]; i++)
-			if (cc[CC_id].vrb_map[i] != 0)
-				total_nb_available_rb[CC_id]--;
-
-		N_RBG[CC_id] = to_rbg(cc[CC_id].mib->message.dl_Bandwidth);
-
-		// store the global enb stats:
-		eNB->eNB_stats[CC_id].num_dlactive_UEs = UE_list->num_UEs;
-		eNB->eNB_stats[CC_id].available_prbs = total_nb_available_rb[CC_id];
-		eNB->eNB_stats[CC_id].total_available_prbs += total_nb_available_rb[CC_id];
-		eNB->eNB_stats[CC_id].dlsch_bytes_tx = 0;
-		eNB->eNB_stats[CC_id].dlsch_pdus_tx = 0;
-	}
-
-	/// CALLING Pre_Processor for downlink scheduling (Returns estimation of RBs required by each UE and the allocation on sub-band)
-
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, VCD_FUNCTION_IN);
-	//start_meas(&eNB->schedule_dlsch_preprocessor);
-	//dlsch_scheduler_pre_processor(module_idP,
-	 //   frameP,
-	//    subframeP,
-	//    N_RBG,
-	 //   mbsfn_flag);
-	//stop_meas(&eNB->schedule_dlsch_preprocessor);
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_PREPROCESSOR, VCD_FUNCTION_OUT);
-
-
-	for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++)
-	{
-		vrb_map = cc[CC_id].vrb_map;
-
-		LOG_D(MAC, "doing schedule_ue_spec for CC_id %d\n", CC_id);
-
-		dl_req = &eNB->DL_req[CC_id].dl_config_request_body;
-
-		if (mbsfn_flag[CC_id] > 0)
-			continue;
-		
-	    unsigned int rmax;
-            unsigned int narrowBandindex_index;
-            unsigned int first_rb, rep, reps;
-
-            // rmax from RRC connection setup
-            getRepetition(&UE_list->UE_template[CC_id][UE_id], &rmax, &narrowBandindex_index);
-
-            first_rb = narrowband_to_first_rb(cc,narrowBandindex_index);
-
-		if (vrb_map[first_rb] == 1)  // skip scheduling emtc UEs if first RB is taken 
-			continue ; 
-
-		for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id])
-		{
-
-            if (UE_list->UE_template[CC_id][UE_id].rach_resource_type ==0 )  // do  the following scheduling only if the UE is emtc
-                  continue ;
-
-            //[khalid] ******** allocate here the vrb_map
-            // 1st check on the vrb_map[] and allocate the one that is next to them
-
-            // at the end of the scheduler make sure the right subbands coresponding to these RBs are allocated the UE in UE_template directely
-            // also check on the fill_DCI function
-
-            
-
-            vrb_map[first_rb] = 1;
-            vrb_map[first_rb + 1] = 1;
-            vrb_map[first_rb + 2] = 1;
-            vrb_map[first_rb + 3] = 1;
-            vrb_map[first_rb + 4] = 1;
-            vrb_map[first_rb + 5] = 1;
-
-
-
-
-
-			continue_flag = 0; // reset the flag to allow allocation for the remaining UEs
-			rnti = UE_RNTI(module_idP, UE_id);
-			eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
-			ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-
-            //[khalid] allocate the middle RB subbands in sf 1,5 for synch signals and PBCH
-
-
-
-
-			if (rnti == NOT_A_RNTI) {
-				LOG_D(MAC, "Cannot find rnti for UE_id %d (num_UEs %d)\n", UE_id, UE_list->num_UEs);
-				continue_flag = 1;
-			}
-
-			if (eNB_UE_stats == NULL) {
-				LOG_D(MAC, "[eNB] Cannot find eNB_UE_stats\n");
-				continue_flag = 1;
-			}
-
-			//if (continue_flag != 1) {
-			//	switch (get_tmode(module_idP, CC_id, UE_id)) {
-			//	case 1:
-			//	case 2:
-			//	case 7:
-			//		aggregation = get_aggregation(get_bw_index(module_idP, CC_id),
-			//			eNB_UE_stats->dl_cqi,
-			//			format1);
-			//		break;
-			//	case 3:
-			//		aggregation = get_aggregation(get_bw_index(module_idP, CC_id),
-			//			eNB_UE_stats->dl_cqi,
-			//			format2A);
-			//		break;
-			//	default:
-			//		LOG_W(MAC, "Unsupported transmission mode %d\n", get_tmode(module_idP, CC_id, UE_id));
-			//		aggregation = 2;
-			//	}
-			//}
-
-			if ((ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) ||  // no RBs allocated
-				CCE_allocation_infeasible(module_idP, CC_id, 0, subframeP, aggregation, rnti)
-				) {
-				LOG_D(MAC, "[eNB %d] Frame %d : no RB allocated for UE %d on CC_id %d: continue \n",
-					module_idP, frameP, UE_id, CC_id);
-				continue_flag = 1; //to next user (there might be rbs availiable for other UEs in TM5
-			}
-
-			//if (cc[CC_id].tdd_Config != NULL) { //TDD
-			//	set_ue_dai(subframeP,
-			//		UE_id,
-			//		CC_id,
-			//		cc[CC_id].tdd_Config->subframeAssignment,
-			//		UE_list);
-			//	// update UL DAI after DLSCH scheduling
-			//	set_ul_DAI(module_idP, UE_id, CC_id, frameP, subframeP);
-			//}
-
-		   //if (continue_flag == 1) {
-			//    add_ue_dlsch_info(module_idP,
-		   //         CC_id,
-			//        UE_id,
-			//        subframeP,
-			//        S_DL_NONE);
-		  //      continue;
-		   // }
-
-			nb_available_rb = 6; // to be checked
-			harq_pid = ue_sched_ctl->harq_pid[CC_id];
-			round = ue_sched_ctl->round[CC_id];
-			UE_list->eNB_UE_stats[CC_id][UE_id].crnti = rnti;
-			UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status = mac_eNB_get_rrc_status(module_idP, rnti);x
-			UE_list->eNB_UE_stats[CC_id][UE_id].harq_pid = harq_pid;
-			UE_list->eNB_UE_stats[CC_id][UE_id].harq_round = round;
-
-			sdu_length_total = 0;
-			num_sdus = 0;
-
-
-			//DevCheck(((eNB_UE_stats->dl_cqi < MIN_CQI_VALUE) || (eNB_UE_stats->dl_cqi > MAX_CQI_VALUE)),
-			//eNB_UE_stats->dl_cqi, MIN_CQI_VALUE, MAX_CQI_VALUE);
-
-			eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[eNB_UE_stats->dl_cqi]; //to be checked
-			eNB_UE_stats->dlsch_mcs1 = cmin(eNB_UE_stats->dlsch_mcs1, 15);
-
-
-			// store stats
-			UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi = eNB_UE_stats->dl_cqi;
-
-			// initializing the rb allocation indicator for each UE
-			//to be checked
-			for (j = 0; j < N_RBG[CC_id]; j++) {
-				UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = 0;
-			}
-
-			LOG_D(MAC, "[eNB %d] Frame %d: Scheduling UE %d on CC_id %d (rnti %x, harq_pid %d, round %d, rb %d, cqi %d, mcs %d, rrc %d)\n",
-				module_idP, frameP, UE_id, CC_id, rnti, harq_pid, round, nb_available_rb,
-				eNB_UE_stats->dl_cqi, eNB_UE_stats->dlsch_mcs1,
-				UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status);
-
-
-
-			// process retransmission
-
-			if (round > 0)
-			{
-
-
-                // choose r3 by default for RAR (Table 9.1.5-5)
-                rep = 2;
-                // get actual repetition count from Table 9.1.5-3
-                reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep));
-
-
-				// get freq_allocation
-				nb_rb = 6;//UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
-
-				if (nb_rb <= nb_available_rb)
-				{
-					
-
-					//if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) {
-						for (j = 0; j < N_RBG[CC_id]; j++) { // for indicating the rballoc for each sub-band
-							UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j];
-						}
-					//}
-					//else {
-					//	nb_rb_temp = nb_rb;
-					//	j = 0;
-
-					//	while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) {
-					//		if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 1) {
-					//			UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j];
-
-					//			if ((j == N_RBG[CC_id] - 1) &&
-					//				((N_RB_DL[CC_id] == 25) ||
-					//				(N_RB_DL[CC_id] == 50))) {
-					//				nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id] + 1;
-					//			}
-					//			else {
-					//				nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id];
-					//			}
-					//		}
-
-					//		j = j + 1;
-					//	}
-					//}
-
-					nb_available_rb -= nb_rb;
-
-					//eNB->mu_mimo_mode[UE_id].pre_nb_available_rbs = nb_rb;
-					//eNB->mu_mimo_mode[UE_id].dl_pow_off = ue_sched_ctl->dl_pow_off[CC_id];
-
-					//for(j=0; j<N_RBG[CC_id]; j++) {
-					//eNB->mu_mimo_mode[UE_id].rballoc_sub[j] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j];
-					//}
-
-
-					switch (get_tmode(module_idP, CC_id, UE_id)) {
-					case 1:
-					case 2:
-					case 7:
-					default:
-                    {
-
-                        if ((UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == 0) &&
-                            (mpdcch_sf_condition(eNB, CC_id, frameP, subframeP, rmax, TYPEUESPEC,UE_id) > 0))
-						{
-							// MPDCCH configuration for RAR
-							dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
-							memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t));
-							dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE;
-							dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_mpdcch_pdu));
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 1) ? 11 : 10;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = narrowBandindex_index;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = 1; // imposed (9.1.5 in 213) for Type 2 Common search space
-                            AssertFatal(cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 != NULL,
-								"cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n");
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0;  // Note: this should be dynamic
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 16; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4;  // other-RNTI
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti;
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2;
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = cc[CC_id].physCellId;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000; // 0dB
-
-                            //[khalid] missing DCI format   should be 10 for 6-1A
-
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV(6, 0, 6);  // Note: still to be checked if it should not be (getRIV(N_RB_DL,first_rb,6)) : Check nFAPI specifications and what is done L1 with this parameter
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]; // adjust according to size of RAR, 208 bits with N1A_PRB=3
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 4; // fix to 4 for now
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = (round & 3);
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = harq_pid;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rep;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 1;// N1A_PRB=3 (36.212); => 208 bits for mcs=4, choose mcs according t message size TBD
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1;
-                            UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++;
-							dl_req->number_pdu++;
-
-
-							
-
-							//eNB_UE_stats->dlsch_trials[round]++;
-							UE_list->eNB_UE_stats[CC_id][UE_id].num_retransmission += 1;
-							UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx = nb_rb;
-							UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_retx += nb_rb;
-							UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1;
-							UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2 = eNB_UE_stats->dlsch_mcs1;
-
-							add_ue_dlsch_info(module_idP,
-								CC_id,
-								UE_id,
-								subframeP,
-								S_DL_SCHEDULED);
-
-						} //repetition_count==0 && SF condition met
-                        else if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt > 0)
-						{
-							// we're in a stream of repetitions
-                            UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++;
-                            if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == reps)
-							{
-								// this is the last mpdcch repetition
-                                if (cc[CC_id].tdd_Config == NULL) { // FDD case
-																	 // wait 2 subframes for PDSCH transmission
-                                    if (subframeP > 7) UE_list->UE_template[CC_id][UE_id].Msg2_frame = (frameP + 1) & 1023;
-                                    else             UE_list->UE_template[CC_id][UE_id].Msg2_frame = frameP;
-                                    UE_list->UE_template[CC_id][UE_id].Msg2_subframe = (subframeP + 2) % 10; // +2 is the "n+x" from Section 7.1.11  in 36.213
-								}
-								else {
-									AssertFatal(1 == 0, "TDD case not done yet\n");
-								}
-							} // mpdcch_repetition_count == reps
-                            if ((UE_list->UE_template[CC_id][UE_id].Msg2_frame == frameP) && (UE_list->UE_template[CC_id][UE_id].Msg2_subframe == subframeP)) {
-								// Program PDSCH
-
-								dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
-								memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t));
-								dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE;
-								dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_dlsch_pdu));
-                                dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = eNB->pdu_index[CC_id];
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 4;   // format 6-1A
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0;   // localized
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(N_RB_DL, first_rb, 6);
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = (round & 3);
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1;// first block
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc->p_eNB == 1) ? 0 : 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1;
-								//	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index                         = ;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize(cc->mib->message.dl_Bandwidth); // ignored
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc->p_eNB == 1) ? 1 : 2;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1;
-								//	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ;
-
-                                dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2;;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2;  // not SI message
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0;
-								dl_req->number_pdu++;
-
-
-							}
-						}
-
-					}
-
-
-
-					
-					}
-
-					
-
-					
-				}
-				else {
-					LOG_D(MAC, "[eNB %d] Frame %d CC_id %d : don't schedule UE %d, its retransmission takes more resources than we have\n",
-						module_idP, frameP, CC_id, UE_id);
-				}
-			}
-			else 
-			{ 
-				// This is a potentially new SDU opportunity //
-
-				rlc_status.bytes_in_buffer = 0;
-				// Now check RLC information to compute number of required RBs
-				// get maximum TBS size for RLC request
-
-
-
-				TBS = 408;
-				// check first for RLC data on DCCH
-				// add the length for  all the control elements (timing adv, drx, etc) : header + payload
-
-				ta_len = (ue_sched_ctl->ta_update != 0) ? 2 : 0;
-
-				header_len_dcch = 2; // 2 bytes DCCH SDU subheader
-
-				if (TBS - ta_len - header_len_dcch > 0) {
-					rlc_status = mac_rlc_status_ind(
-						module_idP,
-						rnti,
-						module_idP,
-						frameP,
-						subframeP,
-						ENB_FLAG_YES,
-						MBMS_FLAG_NO,
-						DCCH,
-						(TBS - ta_len - header_len_dcch)); // transport block set size
-
-					sdu_lengths[0] = 0;
-
-					if (rlc_status.bytes_in_buffer > 0) {  // There is DCCH to transmit
-						LOG_D(MAC, "[eNB %d] Frame %d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
-							module_idP, frameP, CC_id, TBS - header_len_dcch);
-						sdu_lengths[0] = mac_rlc_data_req(
-							module_idP,
-							rnti,
-							module_idP,
-							frameP,
-							ENB_FLAG_YES,
-							MBMS_FLAG_NO,
-							DCCH,
-							TBS, //not used
-							(char *)&dlsch_buffer[0]);
-
-						T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-							T_INT(harq_pid), T_INT(DCCH), T_INT(sdu_lengths[0]));
-
-						LOG_D(MAC, "[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n", module_idP, CC_id, sdu_lengths[0]);
-						sdu_length_total = sdu_lengths[0];
-						sdu_lcids[0] = DCCH;
-						UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH] += 1;
-						UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH] += sdu_lengths[0];
-						num_sdus = 1;
-#ifdef DEBUG_eNB_SCHEDULER
-						LOG_T(MAC, "[eNB %d][DCCH] CC_id %d Got %d bytes :", module_idP, CC_id, sdu_lengths[0]);
-
-						for (j = 0; j < sdu_lengths[0]; j++) {
-							LOG_T(MAC, "%x ", dlsch_buffer[j]);
-						}
-
-						LOG_T(MAC, "\n");
-#endif
-					}
-					else {
-						header_len_dcch = 0;
-						sdu_length_total = 0;
-					}
-				}
-
-				// check for DCCH1 and update header information (assume 2 byte sub-header)
-				if (TBS - ta_len - header_len_dcch - sdu_length_total > 0) {
-					rlc_status = mac_rlc_status_ind(
-						module_idP,
-						rnti,
-						module_idP,
-						frameP,
-						subframeP,
-						ENB_FLAG_YES,
-						MBMS_FLAG_NO,
-						DCCH + 1,
-						(TBS - ta_len - header_len_dcch - sdu_length_total)); // transport block set size less allocations for timing advance and
-																			  // DCCH SDU
-					sdu_lengths[num_sdus] = 0;
-
-					if (rlc_status.bytes_in_buffer > 0) {
-						LOG_I(MAC, "[eNB %d], Frame %d, DCCH1->DLSCH, CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
-							module_idP, frameP, CC_id, TBS - header_len_dcch - sdu_length_total);
-						sdu_lengths[num_sdus] += mac_rlc_data_req(
-							module_idP,
-							rnti,
-							module_idP,
-							frameP,
-							ENB_FLAG_YES,
-							MBMS_FLAG_NO,
-							DCCH + 1,
-							TBS, //not used
-							(char *)&dlsch_buffer[sdu_length_total]);
-
-						T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-							T_INT(harq_pid), T_INT(DCCH + 1), T_INT(sdu_lengths[num_sdus]));
-
-						sdu_lcids[num_sdus] = DCCH1;
-						sdu_length_total += sdu_lengths[num_sdus];
-						header_len_dcch += 2;
-						UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH1] += 1;
-						UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1] += sdu_lengths[num_sdus];
-						num_sdus++;
-#ifdef DEBUG_eNB_SCHEDULER
-						LOG_T(MAC, "[eNB %d][DCCH1] CC_id %d Got %d bytes :", module_idP, CC_id, sdu_lengths[num_sdus]);
-
-						for (j = 0; j < sdu_lengths[num_sdus]; j++) {
-							LOG_T(MAC, "%x ", dlsch_buffer[j]);
-						}
-
-						LOG_T(MAC, "\n");
-#endif
-
-					}
-				}
-
-				// assume the max dtch header size, and adjust it later
-				header_len_dtch = 0;
-				header_len_dtch_last = 0; // the header length of the last mac sdu
-										  // lcid has to be sorted before the actual allocation (similar struct as ue_list).
-				for (lcid = NB_RB_MAX - 1; lcid >= DTCH; lcid--) {
-					// TBD: check if the lcid is active
-
-					header_len_dtch += 3;
-					header_len_dtch_last = 3;
-					LOG_D(MAC, "[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n",
-						module_idP, frameP, lcid, TBS,
-						TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch);
-
-					if (TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch > 0) { // NN: > 2 ? 
-						rlc_status = mac_rlc_status_ind(module_idP,
-							rnti,
-							module_idP,
-							frameP,
-							subframeP,
-							ENB_FLAG_YES,
-							MBMS_FLAG_NO,
-							lcid,
-							TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch);
-
-
-						if (rlc_status.bytes_in_buffer > 0) {
-
-							LOG_D(MAC, "[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n",
-								module_idP, frameP, TBS - header_len_dcch - sdu_length_total - header_len_dtch, lcid, header_len_dtch);
-							sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP,
-								rnti,
-								module_idP,
-								frameP,
-								ENB_FLAG_YES,
-								MBMS_FLAG_NO,
-								lcid,
-								TBS,	//not used
-								(char*)&dlsch_buffer[sdu_length_total]);
-							T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-								T_INT(harq_pid), T_INT(lcid), T_INT(sdu_lengths[num_sdus]));
-
-							LOG_D(MAC, "[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n", module_idP, sdu_lengths[num_sdus], lcid);
-							sdu_lcids[num_sdus] = lcid;
-							sdu_length_total += sdu_lengths[num_sdus];
-							UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[lcid] += 1;
-							UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[lcid] += sdu_lengths[num_sdus];
-							if (sdu_lengths[num_sdus] < 128) {
-								header_len_dtch--;
-								header_len_dtch_last--;
-							}
-							num_sdus++;
-						} // no data for this LCID
-						else {
-							header_len_dtch -= 3;
-						}
-					} // no TBS left
-					else {
-						header_len_dtch -= 3;
-						break;
-					}
-				}
-				if (header_len_dtch == 0)
-					header_len_dtch_last = 0;
-				// there is at least one SDU 
-				// if (num_sdus > 0 ){
-				if ((sdu_length_total + header_len_dcch + header_len_dtch) > 0) {
-
-					// Now compute number of required RBs for total sdu length
-					// Assume RAH format 2
-					// adjust  header lengths
-					header_len_dcch_tmp = header_len_dcch;
-					header_len_dtch_tmp = header_len_dtch;
-					if (header_len_dtch == 0) {
-						header_len_dcch = (header_len_dcch > 0) ? 1 : 0;//header_len_dcch;  // remove length field
-					}
-					else {
-						header_len_dtch_last -= 1; // now use it to find how many bytes has to be removed for the last MAC SDU 
-						header_len_dtch = (header_len_dtch > 0) ? header_len_dtch - header_len_dtch_last : header_len_dtch;     // remove length field for the last SDU
-					}
-
-					//mcs = eNB_UE_stats->dlsch_mcs1;
-					//if (mcs == 0) {
-					//	nb_rb = 4;  // don't let the TBS get too small
-					//}
-					//else {
-					//	nb_rb = min_rb_unit[CC_id];
-					//}
-
-                    //[khalid]: maximum MCS (7 or 15) depend on the DCI formate used from UE_list->UE_template[CC_id [UE_id].rach_resource_type
-
-					mcs = 4;
-					nb_rb = 6;
-
-
-					TBS = 408;//get_TBS_DL(mcs, nb_rb);
-
-					//while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) {
-					//	nb_rb += min_rb_unit[CC_id];  //
-
-					//	if (nb_rb > nb_available_rb) { // if we've gone beyond the maximum number of RBs
-					//								 // (can happen if N_RB_DL is odd)
-					//		TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_available_rb);
-					//		nb_rb = nb_available_rb;
-					//		break;
-					//	}
-
-					//	TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rb);
-					//}
-
-					//if (nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) {
-						for (j = 0; j < N_RBG[CC_id]; j++) { // for indicating the rballoc for each sub-band
-							UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j];
-						}
-					//}
-					//else 
-					//{
-					//	nb_rb_temp = nb_rb;
-					//	j = 0;
-
-					//	while ((nb_rb_temp > 0) && (j < N_RBG[CC_id])) {
-					//		if (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 1) {
-					//			UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j] = ue_sched_ctl->rballoc_sub_UE[CC_id][j];
-
-					//			if ((j == N_RBG[CC_id] - 1) &&
-					//				((N_RB_DL[CC_id] == 25) ||
-					//				(N_RB_DL[CC_id] == 50))) {
-					//				nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id] + 1;
-					//			}
-					//			else {
-					//				nb_rb_temp = nb_rb_temp - min_rb_unit[CC_id];
-					//			}
-					//		}
-
-					//		j = j + 1;
-					//	}
-					//}
-					
-					//RC.eNB[module_idP][CC_id]->mu_mimo_mode[UE_id].pre_nb_available_rbs = nb_rb;
-					//RC.eNB[module_idP][CC_id]->mu_mimo_mode[UE_id].dl_pow_off = ue_sched_ctl->dl_pow_off[CC_id];
-
-					//for(j=0; j<N_RBG[CC_id]; j++) {
-					//RC.eNB[module_idP][CC_id]->mu_mimo_mode[UE_id].rballoc_sub[j] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][j];
-
-					//}
-					//
-					// decrease mcs until TBS falls below required length
-					//while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs > 0)) {
-					//	mcs--;
-					//	TBS = get_TBS_DL(mcs, nb_rb);
-					//}
-
-                    // if we have decreased too much or we don't have enough RBs, increase MCS
-					//while ((TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (((ue_sched_ctl->dl_pow_off[CC_id] > 0) && (mcs < 28))
-					//	|| ((ue_sched_ctl->dl_pow_off[CC_id] == 0) && (mcs <= 15)))) {
-					//	mcs++;
-					//	TBS = get_TBS_DL(mcs, nb_rb);
-					//}
-
-					LOG_D(MAC, "dlsch_mcs before and after the rate matching = (%d, %d)\n", eNB_UE_stats->dlsch_mcs1, mcs);
-
-#ifdef DEBUG_eNB_SCHEDULER
-					LOG_D(MAC, "[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n",
-						module_idP, CC_id, mcs, TBS, nb_rb);
-					// msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n",
-					//  TBS, sdu_length_total, offset, TBS-sdu_length_total-offset);
-#endif
-
-					if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) {
-						padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len);
-						post_padding = 0;
-					}
-					else {
-						padding = 0;
-
-						// adjust the header len
-						if (header_len_dtch == 0) {
-							header_len_dcch = header_len_dcch_tmp;
-						}
-						else { //if (( header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2)))
-							header_len_dtch = header_len_dtch_tmp;
-						}
-
-						post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len; // 1 is for the postpadding header
-					}
-
-
-					offset = generate_dlsch_header((unsigned char*)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
-						num_sdus,              //num_sdus
-						sdu_lengths,  //
-						sdu_lcids,
-						255,                                   // no drx
-						ue_sched_ctl->ta_update, // timing advance
-						NULL,                                  // contention res id
-						padding,
-						post_padding);
-
-					//#ifdef DEBUG_eNB_SCHEDULER
-					if (ue_sched_ctl->ta_update) {
-						LOG_I(MAC,
-							"[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n",
-							module_idP, frameP, UE_id, CC_id, sdu_length_total, num_sdus, sdu_lengths[0], sdu_lcids[0], offset,
-							ue_sched_ctl->ta_update, padding, post_padding, mcs, TBS, nb_rb, header_len_dcch, header_len_dtch);
-					}
-					//#endif
-#ifdef DEBUG_eNB_SCHEDULER
-					LOG_T(MAC, "[eNB %d] First 16 bytes of DLSCH : \n");
-
-					for (i = 0; i < 16; i++) {
-						LOG_T(MAC, "%x.", dlsch_buffer[i]);
-					}
-
-					LOG_T(MAC, "\n");
-#endif
-					// cycle through SDUs and place in dlsch_buffer
-					memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset], dlsch_buffer, sdu_length_total);
-					// memcpy(RC.mac[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]);
-
-					// fill remainder of DLSCH with random data
-					for (j = 0; j < (TBS - sdu_length_total - offset); j++) {
-						UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset + sdu_length_total + j] = (char)(taus() & 0xff);
-					}
-
-
-					if (opt_enabled == 1) {
-						trace_pdu(1, (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
-							TBS, module_idP, 3, UE_RNTI(module_idP, UE_id),
-							eNB->frame, eNB->subframe, 0, 0);
-						LOG_D(OPT, "[eNB %d][DLSCH] CC_id %d Frame %d  rnti %x  with size %d\n",
-							module_idP, CC_id, frameP, UE_RNTI(module_idP, UE_id), TBS);
-					}
-
-					T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-						T_INT(harq_pid), T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS));
-
-					UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid] = nb_rb;
-
-					add_ue_dlsch_info(module_idP,
-						CC_id,
-						UE_id,
-						subframeP,
-						S_DL_SCHEDULED);
-					// store stats
-					eNB->eNB_stats[CC_id].dlsch_bytes_tx += sdu_length_total;
-					eNB->eNB_stats[CC_id].dlsch_pdus_tx += 1;
-
-					UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used = nb_rb;
-					UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used += nb_rb;
-					UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1 = 4;//eNB_UE_stats->dlsch_mcs1;
-					UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2 = mcs;
-					UE_list->eNB_UE_stats[CC_id][UE_id].TBS = TBS;
-
-					UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes = TBS - sdu_length_total;
-					UE_list->eNB_UE_stats[CC_id][UE_id].total_sdu_bytes += sdu_length_total;
-					UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes += TBS;
-					UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus += 1;
-
-					
-
-					// do PUCCH power control
-					// this is the normalized RX power
-					eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
-					normalized_rx_power = eNB_UE_stats->Po_PUCCH_dBm;
-					target_rx_power = get_target_pucch_rx_power(module_idP, CC_id) + 20;
-
-					// this assumes accumulated tpc
-					// make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
-					//int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame * 10 + UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe;
-					//if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || //normal case
-					//	((framex10psubframe > (frameP * 10 + subframeP)) && (((10240 - framex10psubframe + frameP * 10 + subframeP) >= 10)))) //frame wrap-around
-					//	if (eNB_UE_stats->Po_PUCCH_update == 1) {
-					//		eNB_UE_stats->Po_PUCCH_update = 0;
-
-					//		UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame = frameP;
-					//		UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe = subframeP;
-
-					//		if (normalized_rx_power > (target_rx_power + 1)) {
-					//			tpc = 0; //-1
-					//			tpc_accumulated--;
-					//		}
-					//		else if (normalized_rx_power < (target_rx_power - 1)) {
-					//			tpc = 2; //+1
-					//			tpc_accumulated++;
-					//		}
-					//		else {
-					//			tpc = 1; //0
-					//		}
-					//		
-					//		
-
-					//	} // Po_PUCCH has been updated 
-					//	else {
-					//		tpc = 1; //0
-					//	} // time to do TPC update 
-					//else {
-					//	tpc = 1; //0
-					//}
-
-                    {
-
-						// choose r3 by default for RAR (Table 9.1.5-5)
-						rep = 2;
-						// get actual repetition count from Table 9.1.5-3
-						reps = (rmax <= 8) ? (1 << rep) : (rmax >> (3 - rep));
-						
-
-
-                        if ((UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == 0) &&
-                            (mpdcch_sf_condition(eNB, CC_id, frameP, subframeP, rmax, TYPEUESPEC,UE_id) > 0))
-						{
-							// MPDCCH configuration for RAR
-							dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
-							memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t));
-							dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE;
-							dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_mpdcch_pdu));
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 1) ? 11 : 10;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = narrowBandindex_index;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = 1; // imposed (9.1.5 in 213) for Type 2 Common search space
-                            AssertFatal(cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 != NULL,
-								"cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13 is null\n");
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = cc[CC_id].sib1_v13ext->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0;  // Note: this should be dynamic
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 16; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4;  // other-RNTI
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti;
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2;
-                            dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = cc[CC_id].physCellId;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000; // 0dB
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV(6, 0, 6);  // Note: still to be checked if it should not be (getRIV(N_RB_DL,first_rb,6)) : Check nFAPI specifications and what is done L1 with this parameter
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 4; // adjust according to size of RAR, 208 bits with N1A_PRB=3
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 4; // fix to 4 for now
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = harq_pid;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rep;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 1;// N1A_PRB=3 (36.212); => 208 bits for mcs=4, choose mcs according t message size TBD
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0;
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in
-							dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1;
-                            UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++;
-							dl_req->number_pdu++;
-
-
-							// Toggle NDI for next time
-							LOG_D(MAC, "CC_id %d Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n",
-								CC_id, frameP, subframeP, UE_id,
-								UE_list->UE_template[CC_id][UE_id].rnti, harq_pid, UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]);
-
-							UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid] = 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-							UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid] = mcs;
-							UE_list->UE_template[CC_id][UE_id].oldmcs2[harq_pid] = 0;
-
-							eNB->TX_req[CC_id].sfn_sf = (frameP << 3) + subframeP;
-							TX_req = &eNB->TX_req[CC_id].tx_request_body.tx_pdu_list[eNB->TX_req[CC_id].tx_request_body.number_of_pdus];
-							TX_req->pdu_length = TBS;
-							TX_req->pdu_index = eNB->pdu_index[CC_id]++;
-							TX_req->num_segments = 1;
-							TX_req->segments[0].segment_length = TBS;
-							TX_req->segments[0].segment_data = eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[harq_pid];
-							eNB->TX_req[CC_id].tx_request_body.number_of_pdus++;
-
-						} //repetition_count==0 && SF condition met
-                        else if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt > 0)
-						{
-							// we're in a stream of repetitions
-                            UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt++;
-                            if (UE_list->UE_template[CC_id][UE_id].mpdcch_repetition_cnt == reps)
-							{ 
-								// this is the last mpdcch repetition
-                                if (cc[CC_id].tdd_Config == NULL) { // FDD case
-																	 // wait 2 subframes for PDSCH transmission
-                                    if (subframeP > 7) UE_list->UE_template[CC_id][UE_id].Msg2_frame = (frameP + 1) & 1023;
-                                    else             UE_list->UE_template[CC_id][UE_id].Msg2_frame = frameP;
-                                    UE_list->UE_template[CC_id][UE_id].Msg2_subframe = (subframeP + 2) % 10; // +2 is the "n+x" from Section 7.1.11  in 36.213
-								}
-								else {
-									AssertFatal(1 == 0, "TDD case not done yet\n");
-								}
-							} // mpdcch_repetition_count == reps
-                            if ((UE_list->UE_template[CC_id][UE_id].Msg2_frame == frameP) && (UE_list->UE_template[CC_id][UE_id].Msg2_subframe == subframeP)) {
-								// Program PDSCH
-								
-								dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
-								memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t));
-								dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE;
-								dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_dlsch_pdu));
-                                dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = eNB->pdu_index[CC_id];
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 4;   // format 6-1A
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0;   // localized
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV(N_RB_DL, first_rb, 6);
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1;// first block
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc->p_eNB == 1) ? 0 : 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1;
-								//	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index                         = ;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize(cc->mib->message.dl_Bandwidth); // ignored
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc->p_eNB == 1) ? 1 : 2;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1;
-								//	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ;
-
-                                dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_list->UE_template[CC_id][UE_id].rach_resource_type < 3) ? 1 : 2;;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2;  // not SI message
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP;
-								dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0;
-								dl_req->number_pdu++;
-
-								// Program UL processing for Msg3, same as regular LTE
-								//get_Msg3alloc(&cc[CC_idP], subframeP, frameP, &RA_template->Msg3_frame, &RA_template->Msg3_subframe);
-
-
-								//fill_rar_br(eNB, CC_idP, RA_template, frameP, subframeP, cc[CC_idP].RAR_pdu.payload, RA_template->rach_resource_type - 1);
-								//// DL request
-								//eNB->TX_req[CC_idP].sfn_sf = (frameP << 3) + subframeP;
-								//TX_req = &eNB->TX_req[CC_idP].tx_request_body.tx_pdu_list[eNB->TX_req[CC_idP].tx_request_body.number_of_pdus];
-								//TX_req->pdu_length = 7;  // This should be changed if we have more than 1 preamble
-								//TX_req->pdu_index = eNB->pdu_index[CC_idP]++;
-								//TX_req->num_segments = 1;
-								//TX_req->segments[0].segment_length = 7;
-								//TX_req->segments[0].segment_data = cc[CC_idP].RAR_pdu.payload;
-								//eNB->TX_req[CC_idP].tx_request_body.number_of_pdus++;
-							}
-						}
-
-					}
-
-					//dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
-					//memset((void*)dl_config_pdu, 0, sizeof(nfapi_dl_config_request_pdu_t));
-					//dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE;
-					//dl_config_pdu->pdu_size = (uint8_t)(2 + sizeof(nfapi_dl_config_dci_dl_pdu));
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = NFAPI_DL_DCI_FORMAT_1;
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = get_aggregation(get_bw_index(module_idP, CC_id), eNB_UE_stats->dl_cqi, format1);
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = rnti;
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = 1;    // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power
-
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = harq_pid;
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = tpc; // dont adjust power when retransmitting
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = 1 - UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs;
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = 0;
-					////deactivate second codeword
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = 0;
-					//dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = 1;
-				
-					//dl_req->number_dci++;
-					//dl_req->number_pdu++;
-
-
-				}
-				else {  // There is no data from RLC or MAC header, so don't schedule
-
-				}
-			}
-
-			if (cc[CC_id].tdd_Config != NULL) { // TDD
-				set_ul_DAI(module_idP, UE_id, CC_id, frameP, subframeP);
-			}
-
-		} // UE_id loop
-	}  // CC_id loop
-
-
-	fill_DLSCH_dci(module_idP, frameP, subframeP, mbsfn_flag);
-
-	stop_meas(&eNB->schedule_dlsch);
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH, VCD_FUNCTION_OUT);
-
-}
-*/
-
-			
 //------------------------------------------------------------------------------
 void
 schedule_ue_spec(module_id_t module_idP,
@@ -2925,151 +1853,180 @@ void dlsch_scheduler_qos_multiplexing(module_id_t Mod_id, int frameP, sub_frame_
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 //------------------------------------------------------------------------------
+/*
+ * Default DLSCH scheduler for LTE-M
+ */
 void
-schedule_ue_spec_br(
-		    module_id_t   module_idP,
-		    frame_t       frameP,
-		    sub_frame_t   subframeP
-		    ) {
-  int CC_id = 0,UE_id;
-  eNB_MAC_INST                        *mac = RC.mac[module_idP];
-  COMMON_channels_t                    *cc = mac->common_channels;
-  UE_list_t                      *UE_list  = &mac->UE_list;
-  UE_TEMPLATE       *UE_template;
-  UE_sched_ctrl     *ue_sched_ctl;
-  int32_t                        tpc=1;
+schedule_ue_spec_br(module_id_t module_idP,
+		                frame_t     frameP,
+		                sub_frame_t subframeP) 
+//------------------------------------------------------------------------------        
+{
+  int CC_id = 0;
+  int UE_id = -1; 
   int rvseq[4] = {0,2,3,1};
-  mac_rlc_status_resp_t          rlc_status;
-  unsigned char                  header_len_dcch=0, header_len_dcch_tmp=0; 
-  unsigned char                  header_len_dtch=0, header_len_dtch_tmp=0, header_len_dtch_last=0; 
-  unsigned char                  ta_len=0;
-  unsigned char                  sdu_lcids[NB_RB_MAX],lcid,offset,num_sdus=0;
-  uint16_t                       TBS,j,sdu_lengths[NB_RB_MAX],rnti,padding=0,post_padding=0;
-  unsigned char                  dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES];
-  int round;
-  int                            ta_update;
-  uint16_t                       sdu_length_total = 0;
-  int                            mcs;
-  int32_t                        normalized_rx_power, target_rx_power;
-
-  nfapi_dl_config_request_pdu_t *dl_config_pdu;
-  nfapi_ul_config_request_pdu_t *ul_config_pdu;
-  nfapi_tx_request_pdu_t *TX_req;
-  nfapi_dl_config_request_body_t *dl_req;
-  nfapi_ul_config_request_body_t *ul_req;
+  int mcs = 0;
+  int round_DL = 0;
+  int ta_update = 0;
+  int32_t tpc = 1;
+  int32_t normalized_rx_power = 0;
+  int32_t target_rx_power = 0;
+  uint16_t TBS = 0;
+  uint16_t j = 0;
+  uint16_t sdu_lengths[NB_RB_MAX];
+  uint16_t rnti = 0;
+  uint16_t padding = 0;
+  uint16_t post_padding = 0;
+  uint16_t sdu_length_total = 0;
 
-  struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach;
-  struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch;
-  LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13;
-  struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13;
-  int             pucchreps[4] = { 1, 1, 1, 1 };
-  int             n1pucchan[4] = { 0, 0, 0, 0 }; 
-  uint32_t        ackNAK_absSF;
-  int             first_rb;
+  mac_rlc_status_resp_t rlc_status;
+  rrc_eNB_ue_context_t *ue_contextP = NULL;
 
-  dl_req = &mac->DL_req[CC_id].dl_config_request_body;
-  dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
+  unsigned char header_len_dcch = 0;
+  unsigned char header_len_dcch_tmp = 0;
+  unsigned char header_len_dtch = 0; 
+  unsigned char header_len_dtch_tmp = 0;
+  unsigned char header_len_dtch_last = 0;
+  unsigned char ta_len = 0;
+  unsigned char sdu_lcids[NB_RB_MAX];
+  unsigned char lcid = 0;
+  unsigned char  offset,num_sdus=0;
+  unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES];
 
-  if ((frameP&1) == 0) return;
+  eNB_MAC_INST *mac = RC.mac[module_idP];
+  COMMON_channels_t *cc = mac->common_channels;
+  UE_list_t *UE_list = &mac->UE_list;
+  UE_TEMPLATE *UE_template = NULL;
+  UE_sched_ctrl *ue_sched_ctl = NULL;
+
+  nfapi_dl_config_request_pdu_t *dl_config_pdu = NULL;
+  nfapi_ul_config_request_pdu_t *ul_config_pdu = NULL;
+  nfapi_tx_request_pdu_t *TX_req = NULL;
+  nfapi_dl_config_request_body_t *dl_req = NULL;
+  nfapi_ul_config_request_body_t *ul_req = NULL;
+
+  struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = NULL;
+  struct LTE_PUCCH_ConfigCommon_v1310 *ext4_pucch = NULL;
+  LTE_PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL;
+  struct LTE_N1PUCCH_AN_InfoList_r13 *pucch_N1PUCCH_AN_InfoList_r13 = NULL;
+  int pucchreps[4] = { 1, 1, 1, 1 };
+  int n1pucchan[4] = { 0, 0, 0, 0 }; 
+  uint32_t ackNAK_absSF;
+  int first_rb;
+
+  dl_req = &(mac->DL_req[CC_id].dl_config_request_body);
+  dl_config_pdu = &(dl_req->dl_config_pdu_list[dl_req->number_pdu]);
+
+  /* Return if frame is even */
+  if ((frameP & 1) == 0) {
+    return;
+  }
 
-  if (cc[CC_id].mib->message.schedulingInfoSIB1_BR_r13 ==0) return;
+  if (cc[CC_id].mib->message.schedulingInfoSIB1_BR_r13 == 0) {
+    return;
+  }
 
   if (cc[CC_id].radioResourceConfigCommon_BR) {
-
     ext4_prach = cc[CC_id].radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
     ext4_pucch = cc[CC_id].radioResourceConfigCommon_BR->ext4->pucch_ConfigCommon_v1310;
     prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
     pucch_N1PUCCH_AN_InfoList_r13 = ext4_pucch->n1PUCCH_AN_InfoList_r13;
+
     AssertFatal (prach_ParametersListCE_r13 != NULL, "prach_ParametersListCE_r13 is null\n");
     AssertFatal (pucch_N1PUCCH_AN_InfoList_r13 != NULL, "pucch_N1PUCCH_AN_InfoList_r13 is null\n");
-    // check to verify CE-Level compatibility in SIB2_BR
+    /* Check to verify CE-Level compatibility in SIB2_BR */
     AssertFatal (prach_ParametersListCE_r13->list.count == pucch_N1PUCCH_AN_InfoList_r13->list.count, "prach_ParametersListCE_r13->list.count!= pucch_N1PUCCH_AN_InfoList_r13->list.count\n");
 
     switch (prach_ParametersListCE_r13->list.count) {
-    case 4:
-      n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n");
-      pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13);
+      case 4:
+        n1pucchan[3] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[3];
+        AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level3 shouldn't be NULL\n");
+        pucchreps[3] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level3_r13);
 
-    case 3:
-      n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n");
-      pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13);
-    case 2:
-      n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n");
-      pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13);
-    case 1:
-      n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0];
-      AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n");
-      pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13);
-      break;
-    default:
-      AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count);
+      case 3:
+        n1pucchan[2] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[2];
+        AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level2 shouldn't be NULL\n");
+        pucchreps[2] = (int) (4 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level2_r13);
+      case 2:
+        n1pucchan[1] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[1];
+        AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level1 shouldn't be NULL\n");
+        pucchreps[1] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level1_r13);
+      case 1:
+        n1pucchan[0] = *pucch_N1PUCCH_AN_InfoList_r13->list.array[0];
+        AssertFatal (ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13 != NULL, "pucch_NumRepetitionCE_Msg4_Level0 shouldn't be NULL\n");
+        pucchreps[0] = (int) (1 << *ext4_pucch->pucch_NumRepetitionCE_Msg4_Level0_r13);
+        break;
+      default:
+        AssertFatal (1 == 0, "Illegal count for prach_ParametersListCE_r13 %d\n", prach_ParametersListCE_r13->list.count);
     }
   }
 
-  for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
-
+  for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
     int harq_pid = 0;
 
-    rnti = UE_RNTI(module_idP,UE_id);
-    if (rnti==NOT_A_RNTI)  continue;
+    rnti = UE_RNTI(module_idP, UE_id);
 
-    ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
-    UE_template  = &UE_list->UE_template[CC_id][UE_id];
+    if (rnti==NOT_A_RNTI) {
+      continue;
+    }
 
-    if (UE_template->rach_resource_type == 0) continue;
+    ue_sched_ctl = &(UE_list->UE_sched_ctrl[UE_id]);
+    UE_template  = &(UE_list->UE_template[CC_id][UE_id]);
+
+    if (UE_template->rach_resource_type == 0) {
+      continue;
+    }
+    
     uint8_t rrc_status = mac_eNB_get_rrc_status(module_idP, rnti);
 
-    if (rrc_status < RRC_CONNECTED) continue;
+    if (rrc_status < RRC_CONNECTED) {
+      continue;
+    }
 
-    round = ue_sched_ctl->round[CC_id][harq_pid];
+    round_DL = ue_sched_ctl->round[CC_id][harq_pid];
 
-    AssertFatal (UE_template->physicalConfigDedicated != NULL, 
-		 "UE_template->physicalConfigDedicated is null\n");
-    AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, 
-		 "UE_template->physicalConfigDedicated->ext4 is null\n");
-    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, 
-		 "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n");
+    AssertFatal (UE_template->physicalConfigDedicated != NULL, "UE_template->physicalConfigDedicated is null\n");
+    AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, "UE_template->physicalConfigDedicated->ext4 is null\n");
+    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n");
     AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, 
-		 "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n");
+		             "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n");
     AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL,
-		 "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n");
+		             "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n");
 
     LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0];
 
     AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n");
-    AssertFatal(epdcch_setconfig_r11->ext2!=NULL, "epdcch_setconfig_r11->ext2 is null\n");
-    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL,
-		"epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
-    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL,
-		"epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
-    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present==LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, 
-		"epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n");
-    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310!=NULL,
-		"epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null");
-    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present==LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, 
-		"epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n");
+    AssertFatal(epdcch_setconfig_r11->ext2 != NULL, "epdcch_setconfig_r11->ext2 is null\n");
+    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
+    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
+    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, 
+		            "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n");
+    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 != NULL, "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null");
+    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present == LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, 
+		            "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n");
            
-
-    // simple scheduler for 1 repetition, 1 HARQ
+    /* Simple scheduler for 1 repetition, 1 HARQ */
     if (subframeP == 5) { // MPDCCH
+      if (round_DL < 8) LOG_D(MAC, "MPDCCH round_DL = %d in frame %d subframe %d\n", round_DL, frameP, subframeP);
 
-      if (round == 8) {
+      if (round_DL == 8) {
         rlc_status.bytes_in_buffer = 0;
-        // Now check RLC information to compute number of required RBs
-        // get maximum TBS size for RLC request
+
+        /* Now check RLC information to compute number of required RBs */
+        
+        /* Get maximum TBS size for RLC request */
         TBS = get_TBS_DL(9,6);
-        // check first for RLC data on DCCH
-        // add the length for  all the control elements (timing adv, drx, etc) : header + payload
+        
+        /* Check first for RLC data on DCCH */
+        
+        /* Add the length for all the control elements (timing adv, drx, etc) : header + payload */
 
         if (ue_sched_ctl->ta_timer == 0) {
           ta_update = ue_sched_ctl->ta_update;
-          /* if we send TA then set timer to not send it for a while */
+          /* If we send TA then set timer to not send it for a while */
           if (ta_update != 31)
             ue_sched_ctl->ta_timer = 20;
-          /* reset ta_update */
+          /* Reset ta_update */
           ue_sched_ctl->ta_update = 31;
         } else {
           ta_update = 31;
@@ -3079,43 +2036,57 @@ schedule_ue_spec_br(
 
         header_len_dcch = 2; // 2 bytes DCCH SDU subheader
 
-        if ( TBS-ta_len-header_len_dcch > 0 ) {
-	  LOG_I(MAC,"Calling mac_rlc_status_ind for DCCH\n");
-          rlc_status = mac_rlc_status_ind(
-					  module_idP,
-					  rnti,
-					  module_idP,
-					  frameP,
-					  subframeP,
-					  ENB_FLAG_YES,
-					  MBMS_FLAG_NO,
-					  DCCH,
-					  (TBS-ta_len-header_len_dcch)
-					  ,0, 0
-					  ); // transport block set size
-
-          sdu_lengths[0]=0;
+        if (TBS - ta_len-header_len_dcch > 0 ) {
+          LOG_D(MAC, "Calling mac_rlc_status_ind for DCCH\n");
+          
+          rlc_status = mac_rlc_status_ind(module_idP,
+                                          rnti,
+                                          module_idP,
+                                          frameP,
+                                          subframeP,
+                                          ENB_FLAG_YES,
+                                          MBMS_FLAG_NO,
+                                          DCCH,
+                                          (TBS-ta_len-header_len_dcch),
+                                          0,
+                                          0); // transport block set size
+
+          sdu_lengths[0] = 0;
 
           if (rlc_status.bytes_in_buffer > 0) {  // There is DCCH to transmit
-            LOG_I(MAC,"[eNB %d] Frame %d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
-                  module_idP,frameP,CC_id,TBS-header_len_dcch);
-            sdu_lengths[0] = mac_rlc_data_req(
-					      module_idP,
-					      rnti,
-					      module_idP,
-					      frameP,
-					      ENB_FLAG_YES,
-					      MBMS_FLAG_NO,
-					      DCCH,
-					      TBS, //not used
-					      (char *)&dlsch_buffer[0]
-					      ,0, 0
-);
-
-            T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-              T_INT(harq_pid), T_INT(DCCH), T_INT(sdu_lengths[0]));
-
-            LOG_I(MAC,"[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n",module_idP,CC_id,sdu_lengths[0]);
+            LOG_D(MAC, "[eNB %d] Frame %d, DL-DCCH->DLSCH CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
+                  module_idP,
+                  frameP,
+                  CC_id,
+                  TBS-header_len_dcch);
+
+            sdu_lengths[0] = mac_rlc_data_req(module_idP,
+                                              rnti,
+                                              module_idP,
+                                              frameP,
+                                              ENB_FLAG_YES,
+                                              MBMS_FLAG_NO,
+                                              DCCH,
+                                              TBS, //not used
+                                              (char *)&dlsch_buffer[0],
+                                              0,
+                                              0);
+
+            T(T_ENB_MAC_UE_DL_SDU, 
+              T_INT(module_idP), 
+              T_INT(CC_id), 
+              T_INT(rnti), 
+              T_INT(frameP), 
+              T_INT(subframeP),
+              T_INT(harq_pid), 
+              T_INT(DCCH), 
+              T_INT(sdu_lengths[0]));
+
+            LOG_D(MAC,"[eNB %d][DCCH] CC_id %d Got %d bytes from RLC\n",
+                  module_idP,
+                  CC_id,
+                  sdu_lengths[0]);
+
             sdu_length_total = sdu_lengths[0];
             sdu_lcids[0] = DCCH;
             UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH]+=1;
@@ -3127,399 +2098,502 @@ schedule_ue_spec_br(
           }
         }
 	
-        // check for DCCH1 and update header information (assume 2 byte sub-header)
-        if (TBS-ta_len-header_len_dcch-sdu_length_total > 0 ) {
-          rlc_status = mac_rlc_status_ind(
-					  module_idP,
-					  rnti,
-					  module_idP,
-					  frameP,
-					  subframeP,
-					  ENB_FLAG_YES,
-					  MBMS_FLAG_NO,
-					  DCCH+1,
-					  (TBS-ta_len-header_len_dcch-sdu_length_total)
-					  ,0, 0); // transport block set size less allocations for timing advance and
-          // DCCH SDU
-	  sdu_lengths[num_sdus] = 0;
+        /* Check for DCCH1 and update header information (assume 2 byte sub-header) */
+        if (TBS - ta_len-header_len_dcch - sdu_length_total > 0) {
+          rlc_status = mac_rlc_status_ind(module_idP,
+                                          rnti,
+                                          module_idP,
+                                          frameP,
+                                          subframeP,
+                                          ENB_FLAG_YES,
+                                          MBMS_FLAG_NO,
+                                          DCCH + 1,
+                                          (TBS-ta_len-header_len_dcch-sdu_length_total),
+                                          0, 
+                                          0); // transport block set size less allocations for timing advance and DCCH SDU
+	        
+          sdu_lengths[num_sdus] = 0;
 	  
           if (rlc_status.bytes_in_buffer > 0) {
-            LOG_I(MAC,"[eNB %d], Frame %d, DCCH1->DLSCH, CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
-                  module_idP,frameP,CC_id,TBS-header_len_dcch-sdu_length_total);
-            sdu_lengths[num_sdus] += mac_rlc_data_req(
-						      module_idP,
-						      rnti,
-						      module_idP,
-						      frameP,
-						      ENB_FLAG_YES,
-						      MBMS_FLAG_NO,
-						      DCCH+1,
-						      TBS, //not used
-						      (char *)&dlsch_buffer[sdu_length_total]
-						      ,0, 0
-						      );
+            LOG_D(MAC,"[eNB %d], Frame %d, DCCH1->DLSCH, CC_id %d, Requesting %d bytes from RLC (RRC message)\n",
+                  module_idP,
+                  frameP,
+                  CC_id,
+                  TBS-header_len_dcch - sdu_length_total);
+
+            sdu_lengths[num_sdus] += mac_rlc_data_req(module_idP,
+                                                      rnti,
+                                                      module_idP,
+                                                      frameP,
+                                                      ENB_FLAG_YES,
+                                                      MBMS_FLAG_NO,
+                                                      DCCH+1,
+                                                      TBS, //not used
+                                                      (char *)&dlsch_buffer[sdu_length_total],
+                                                      0, 
+                                                      0);
 	    
-            T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-              T_INT(harq_pid), T_INT(DCCH+1), T_INT(sdu_lengths[num_sdus]));
+            T(T_ENB_MAC_UE_DL_SDU, 
+              T_INT(module_idP), 
+              T_INT(CC_id), 
+              T_INT(rnti), 
+              T_INT(frameP), 
+              T_INT(subframeP),
+              T_INT(harq_pid), 
+              T_INT(DCCH+1), 
+              T_INT(sdu_lengths[num_sdus]));
 
             sdu_lcids[num_sdus] = DCCH1;
             sdu_length_total += sdu_lengths[num_sdus];
             header_len_dcch += 2;
-            UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH1]+=1;
-            UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1]+=sdu_lengths[num_sdus];
-	    num_sdus++;
-	  }
+            UE_list->eNB_UE_stats[CC_id][UE_id].num_pdu_tx[DCCH1] += 1;
+            UE_list->eNB_UE_stats[CC_id][UE_id].num_bytes_tx[DCCH1] += sdu_lengths[num_sdus];
+	          num_sdus++;
+	        }
         }
 
-	// assume the max dtch header size, and adjust it later
-	header_len_dtch=0;
-	header_len_dtch_last=0; // the header length of the last mac sdu
-	// lcid has to be sorted before the actual allocation (similar struct as ue_list).
-	for (lcid=NB_RB_MAX-1; lcid>=DTCH ; lcid--){
-	  // TBD: check if the lcid is active
-	  
-	  header_len_dtch+=3; 
-	  header_len_dtch_last=3;
-	  LOG_D(MAC,"[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n",
-		module_idP,frameP,lcid,TBS,
-		TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch);
-	  
-	  if (TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch > 0 ) { // NN: > 2 ? 
-	    rlc_status = mac_rlc_status_ind(module_idP,
-					    rnti,
-					    module_idP,
-					    frameP,
-					    subframeP,
-					    ENB_FLAG_YES,
-					    MBMS_FLAG_NO,
-					    lcid,
-					    TBS-ta_len-header_len_dcch-sdu_length_total-header_len_dtch
-					    ,0, 0);
-	    
-
-	    if (rlc_status.bytes_in_buffer > 0) {
-	      
-	      LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n",
-		    module_idP,frameP,TBS-header_len_dcch-sdu_length_total-header_len_dtch,lcid, header_len_dtch);
-	      sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP,
-						       rnti,
-						       module_idP,
-						       frameP,
-						       ENB_FLAG_YES,
-						       MBMS_FLAG_NO,
-						       lcid,
-						       TBS,	//not used
-						       (char*)&dlsch_buffer[sdu_length_total]
-						       ,0, 0);
-	      T(T_ENB_MAC_UE_DL_SDU, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-              T_INT(harq_pid), T_INT(lcid), T_INT(sdu_lengths[num_sdus]));
-
-	      LOG_I(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",module_idP,sdu_lengths[num_sdus],lcid);
-	      sdu_lcids[num_sdus] = lcid;
-	      sdu_length_total += sdu_lengths[num_sdus];
-
-	      if (sdu_lengths[num_sdus] < 128) {
-		header_len_dtch--;
-		header_len_dtch_last--;
-	      }
-	      num_sdus++;
-	    } // no data for this LCID
-	    else {
-	      header_len_dtch-=3;
-	    }
-	  } // no TBS left
-	  else {
-	    header_len_dtch-=3;
-	    break; 
-	  }
-	}
-	if (header_len_dtch == 0 )
-	  header_len_dtch_last= 0;
-	// there is at least one SDU 
-	// if (num_sdus > 0 ){
-	if ((sdu_length_total + header_len_dcch + header_len_dtch )> 0) {
-	  
-	  // Now compute number of required RBs for total sdu length
-	  // Assume RAH format 2
-	  // adjust  header lengths
-	  header_len_dcch_tmp = header_len_dcch;
-	  header_len_dtch_tmp = header_len_dtch;
-	  if (header_len_dtch==0) {
-	    header_len_dcch = (header_len_dcch >0) ? 1 : 0;//header_len_dcch;  // remove length field
-	  } else {
-	    header_len_dtch_last-=1; // now use it to find how many bytes has to be removed for the last MAC SDU 
-	    header_len_dtch = (header_len_dtch > 0) ? header_len_dtch - header_len_dtch_last  :header_len_dtch;     // remove length field for the last SDU
-	  }
-
-          mcs = 9;
-
-          // decrease mcs until TBS falls below required length
-          while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs>0)) {
-            mcs--;
-            TBS = get_TBS_DL(mcs,6);
-          }
+      /* Assume the max dtch header size, and adjust it later */
+      header_len_dtch = 0;
+      header_len_dtch_last = 0; // the header length of the last mac sdu
+      
+      /* lcid has to be sorted before the actual allocation (similar struct as ue_list) */
+      for (lcid = NB_RB_MAX-1; lcid >= DTCH ; lcid--){
+        /* TBD: check if the lcid is active */        
+        header_len_dtch += 3; 
+        header_len_dtch_last = 3;
 
-          // if we have decreased too much or we don't have enough RBs, increase MCS
-          while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) {
-            mcs++;
-            TBS = get_TBS_DL(mcs,6);
-          }
+        LOG_D(MAC,"[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n",
+              module_idP,
+              frameP,
+              lcid,
+              TBS,
+              TBS - ta_len-header_len_dcch - sdu_length_total - header_len_dtch);
+        
+        if (TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch > 0) { // NN: > 2 ?
+          rlc_status = mac_rlc_status_ind(module_idP,
+                                          rnti,
+                                          module_idP,
+                                          frameP,
+                                          subframeP,
+                                          ENB_FLAG_YES,
+                                          MBMS_FLAG_NO,
+                                          lcid,
+                                          TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch,
+                                          0,
+                                          0);
+          
+          if (rlc_status.bytes_in_buffer > 0) {
+            /* RRC inactivity LTE-M */
+            /* Reset RRC inactivity timer after uplane activity */
+            ue_contextP = rrc_eNB_get_ue_context(RC.rrc[module_idP], rnti);
+
+            if (ue_contextP != NULL) {
+              ue_contextP->ue_context.ue_rrc_inactivity_timer = 1;
+            } else {
+              LOG_E(MAC, "[eNB %d] CC_id %d Couldn't find the context associated to UE (RNTI %d) and reset RRC inactivity timer\n",
+                    module_idP,
+                    CC_id,
+                    rnti);
+            }
+            
+            LOG_D(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d)\n",
+                      module_idP,
+                      frameP,
+                      TBS - header_len_dcch - sdu_length_total - header_len_dtch,
+                      lcid, 
+                      header_len_dtch);
+            
+            sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP,
+                                                    rnti,
+                                                    module_idP,
+                                                    frameP,
+                                                    ENB_FLAG_YES,
+                                                    MBMS_FLAG_NO,
+                                                    lcid,
+                                                    TBS,	//not used
+                                                    (char*) &dlsch_buffer[sdu_length_total],
+                                                    0,
+                                                    0);
 
-	  //#ifdef DEBUG_eNB_SCHEDULER
-          LOG_I(MAC,"[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n",
-                module_idP,CC_id,mcs,TBS,6);
-          // msg("[MAC][eNB ] Reminder of DLSCH with random data %d %d %d %d \n",
-          //  TBS, sdu_length_total, offset, TBS-sdu_length_total-offset);
+            T(T_ENB_MAC_UE_DL_SDU, 
+              T_INT(module_idP), 
+              T_INT(CC_id), 
+              T_INT(rnti), 
+              T_INT(frameP), 
+              T_INT(subframeP),
+              T_INT(harq_pid), 
+              T_INT(lcid), 
+              T_INT(sdu_lengths[num_sdus]));
 
+            LOG_D(MAC,"[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",
+                  module_idP,
+                  sdu_lengths[num_sdus],
+                  lcid);
 
-          if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) {
-            padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len);
-            post_padding = 0;
-          } else {
-            padding = 0;
+            sdu_lcids[num_sdus] = lcid;
+            sdu_length_total += sdu_lengths[num_sdus];
 
-            // adjust the header len
-            if (header_len_dtch==0) {
-              header_len_dcch = header_len_dcch_tmp;
-            } else { //if (( header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2)))
-              header_len_dtch = header_len_dtch_tmp;
+            if (sdu_lengths[num_sdus] < 128) {
+              header_len_dtch--;
+              header_len_dtch_last--;
             }
 
-            post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len ; // 1 is for the postpadding header
+            num_sdus++;
+          } else { // no data for this LCID
+            header_len_dtch -= 3;
           }
+        } else { // no TBS left
+          header_len_dtch -= 3;
+          break;
+        }
+      } // for loop LCID
 
+    if (header_len_dtch == 0) {
+      header_len_dtch_last = 0;
+    }
 
-          offset = generate_dlsch_header((unsigned char*)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
-                                         num_sdus,              //num_sdus
-                                         sdu_lengths,  //
-                                         sdu_lcids,
-                                         255,                                   // no drx
-                                         ta_update, // timing advance
-                                         NULL,                                  // contention res id
-                                         padding,
-                                         post_padding);
+    /* There is at least one SDU  */
+    if ((sdu_length_total + header_len_dcch + header_len_dtch) > 0) {
+      /* Now compute number of required RBs for total sdu length */
+      /* Assume RAH format 2 */
+      /* Adjust  header lengths */
+      header_len_dcch_tmp = header_len_dcch;
+      header_len_dtch_tmp = header_len_dtch;
+      
+      if (header_len_dtch == 0) {
+        header_len_dcch = (header_len_dcch > 0) ? 1 : 0; // remove length field
+      } else {
+        header_len_dtch_last -= 1; // now use it to find how many bytes has to be removed for the last MAC SDU 
+        header_len_dtch = (header_len_dtch > 0) ? header_len_dtch - header_len_dtch_last : header_len_dtch; // remove length field for the last SDU
+      }
 
+      mcs = 9;
 
-          if (ta_update != 31) {
-            LOG_D(MAC,
-                  "[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n",
-                  module_idP,frameP, UE_id, CC_id, sdu_length_total,num_sdus,sdu_lengths[0],sdu_lcids[0],offset,
-                  ta_update,padding,post_padding,mcs,TBS,6,header_len_dcch,header_len_dtch);
-	  }
+      /* Decrease mcs until TBS falls below required length */
+      while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs>0)) {
+        mcs--;
+        TBS = get_TBS_DL(mcs,6);
+      }
 
+      /* If we have decreased too much or we don't have enough RBs, increase MCS */
+      while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) {
+        mcs++;
+        TBS = get_TBS_DL(mcs,6);
+      }
 
+      LOG_D(MAC, "[eNB %d] CC_id %d Generated DLSCH header (mcs %d, TBS %d, nb_rb %d)\n",
+            module_idP,
+            CC_id,
+            mcs,
+            TBS,
+            6);
+            
+      if ((TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len) <= 2) {
+        padding = (TBS - header_len_dcch - header_len_dtch - sdu_length_total - ta_len);
+        post_padding = 0;
+      } else {
+        padding = 0;
 
-          // cycle through SDUs and place in dlsch_buffer
-          memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset],dlsch_buffer,sdu_length_total);
-          // memcpy(RC.mac[0].DLSCH_pdu[0][0].payload[0][offset],dcch_buffer,sdu_lengths[0]);
+        /* Adjust the header len */
+        if (header_len_dtch == 0) {
+          header_len_dcch = header_len_dcch_tmp;
+        } else { // if ((header_len_dcch==0)&&((header_len_dtch==1)||(header_len_dtch==2)))
+          header_len_dtch = header_len_dtch_tmp;
+        }
 
-          // fill remainder of DLSCH with random data
-          for (j=0; j<(TBS-sdu_length_total-offset); j++) {
-            UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset+sdu_length_total+j] = (char)(taus()&0xff);
-          }
+        post_padding = TBS - sdu_length_total - header_len_dcch - header_len_dtch - ta_len; // 1 is for the postpadding header
+      }
 
+      offset = generate_dlsch_header((unsigned char*)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
+                                      num_sdus,     //num_sdus
+                                      sdu_lengths,  //
+                                      sdu_lcids,
+                                      255,          // no drx
+                                      ta_update,    // timing advance
+                                      NULL,         // contention res id
+                                      padding,
+                                      post_padding);
 
-          if (opt_enabled == 1) {
-            trace_pdu(1, (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
-                      TBS, module_idP, 3, UE_RNTI(module_idP,UE_id),
-                      mac->frame, mac->subframe,0,0);
-            LOG_D(OPT,"[eNB %d][DLSCH] CC_id %d Frame %d  rnti %x  with size %d\n",
-                  module_idP, CC_id, frameP, UE_RNTI(module_idP,UE_id), TBS);
-          }
 
-          T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP), T_INT(subframeP),
-            T_INT(harq_pid), T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS));
+      if (ta_update != 31) {
+        LOG_D(MAC,"[eNB %d][DLSCH] Frame %d Generate header for UE_id %d on CC_id %d: sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d,timing advance value : %d, padding %d,post_padding %d,(mcs %d, TBS %d, nb_rb %d),header_dcch %d, header_dtch %d\n",
+              module_idP,
+              frameP, 
+              UE_id, 
+              CC_id, 
+              sdu_length_total,
+              num_sdus,
+              sdu_lengths[0],
+              sdu_lcids[0],
+              offset,
+              ta_update,
+              padding,
+              post_padding,
+              mcs,
+              TBS,
+              6,
+              header_len_dcch,
+              header_len_dtch);
+	    }
 
-	  // do PUCCH power control
-          // this is the normalized RX power
+      /* Cycle through SDUs and place in dlsch_buffer */
+      memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset], dlsch_buffer, sdu_length_total);
+      
+      /* Fill remainder of DLSCH with random data */
+      for (j = 0; j < (TBS - sdu_length_total - offset); j++) {
+        UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset + sdu_length_total + j] = (char)(taus()&0xff);
+      }
+
+      if (opt_enabled == 1) {
+        trace_pdu(1, 
+                  (uint8_t *)UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0],
+                  TBS, 
+                  module_idP, 
+                  3, 
+                  UE_RNTI(module_idP,UE_id),
+                  mac->frame, 
+                  mac->subframe,
+                  0,
+                  0);
+
+        LOG_D(OPT,"[eNB %d][DLSCH] CC_id %d Frame %d  rnti %x  with size %d\n",
+              module_idP, 
+              CC_id, 
+              frameP, 
+              UE_RNTI(module_idP, UE_id), 
+              TBS);
+      }
 
-          /* TODO: fix how we deal with power, unit is not dBm, it's special from nfapi */
-	  normalized_rx_power = (5*ue_sched_ctl->pucch1_snr[CC_id]-640)/10+30;
-	  target_rx_power = mac->puCch10xSnr/10+30;
+      T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, 
+        T_INT(module_idP), 
+        T_INT(CC_id), 
+        T_INT(rnti), 
+        T_INT(frameP), 
+        T_INT(subframeP),
+        T_INT(harq_pid), 
+        T_BUFFER(UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS));
+
+	    /* Do PUCCH power control */
+      /* This is the normalized RX power */
+      /* TODO: fix how we deal with power, unit is not dBm, it's special from nfapi */
+	    normalized_rx_power = (5 * ue_sched_ctl->pucch1_snr[CC_id]-640) / 10 + 30;
+	    target_rx_power = mac->puCch10xSnr / 10 + 30;
 	    
-          // this assumes accumulated tpc
-	  // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
-	  int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame*10+UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe;
-          if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case
-	      ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around
-	    if (ue_sched_ctl->pucch1_cqi_update[CC_id] == 1) { 
-	      ue_sched_ctl->pucch1_cqi_update[CC_id] = 0;
-
-	      UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame=frameP;
-	      UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe=subframeP;
-	      
-	      if (normalized_rx_power>(target_rx_power+4)) {
-		tpc = 0; //-1
-	      } else if (normalized_rx_power<(target_rx_power-4)) {
-		tpc = 2; //+1
-	      } else {
-		tpc = 1; //0
-	      }
-	      	      
-	      LOG_D(MAC,"[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, normalized/target rx power %d/%d\n",
-		    module_idP,frameP, subframeP,harq_pid,tpc,
-		    normalized_rx_power,target_rx_power);
-
-	    } // Po_PUCCH has been updated 
-	    else {
+      /* This assumes accumulated tpc */
+	    /* Make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out */
+	    int32_t framex10psubframe = UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame * 10 + UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe;
+      
+      if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || // normal case
+	        ((framex10psubframe > (frameP * 10 + subframeP)) && 
+            (((10240 - framex10psubframe +frameP * 10 + subframeP) >= 10)))) { // frame wrap-around
+	      if (ue_sched_ctl->pucch1_cqi_update[CC_id] == 1) { 
+	        ue_sched_ctl->pucch1_cqi_update[CC_id] = 0;
+      
+          UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_frame = frameP;
+          UE_list->UE_template[CC_id][UE_id].pucch_tpc_tx_subframe = subframeP;
+          
+          if (normalized_rx_power > (target_rx_power + 4)) {
+            tpc = 0; //-1
+          } else if (normalized_rx_power<(target_rx_power - 4)) {
+            tpc = 2; //+1
+          } else {
+            tpc = 1; //0
+          }
+                  
+          LOG_D(MAC,"[eNB %d] DLSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, normalized/target rx power %d/%d\n",
+                module_idP,
+                frameP, 
+                subframeP,
+                harq_pid,
+                tpc,
+                normalized_rx_power,
+                target_rx_power);
+        } else { // Po_PUCCH has been updated 
+	        tpc = 1; // 0
+        }
+	    } else { // time to do TPC update 
 	      tpc = 1; //0
-	    } // time to do TPC update 
-	  else {
-	    tpc = 1; //0
-	  }
-
-	  // Toggle NDI in first round
-	  UE_template->oldNDI[harq_pid] = 1-UE_template->oldNDI[harq_pid];
-	  ue_sched_ctl->round[CC_id][harq_pid] = 0;
-	  round=0;
-	}
-
-      }
+	    }
 
-      if (round < 8) {
-	// fill in MDPDCCH
-	memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t));
-	dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE;
-	dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu));
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 11 : 10;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = epdcch_setconfig_r11->transmissionType_r11;  
-	AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11!=NULL,
-		    "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n");
-	
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0;        // Note: this should be dynamic
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 24;        // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4; // t-CRNTI
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000;     // 0dB
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV (6, 0, 6) | ((epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1)<<5);
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = 9;       // adjust according to size of RAR, 208 bits with N1A_PRB=3
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 0;    // fix to 4 for now
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rvseq[round&3];
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = UE_template->oldNDI[harq_pid];
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 3; 
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0;
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0;        // this is not needed by OAI L1, but should be filled in
-	dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1;
-	dl_req->number_pdu++;
-	UE_template->mcs[harq_pid] = dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs;
-      }
+      // Toggle NDI in first round
+      UE_template->oldNDI[harq_pid] = 1 - UE_template->oldNDI[harq_pid];
+      ue_sched_ctl->round[CC_id][harq_pid] = 0;
+      round_DL = 0;
+	  } // if ((sdu_length_total + header_len_dcch + header_len_dtch) > 0)
+  } 
+  
+    if (round_DL < 8) {
+      /* Fill in MDPDCCH */
+      memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t));
+
+      dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE;
+      dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu));
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 11 : 10;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = 6;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = epdcch_setconfig_r11->transmissionType_r11;  
+
+      AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 != NULL,
+                  "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n");
+      
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = 0;         // Note: this should be dynamic
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = 4; // t-CRNTI
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.rnti = rnti;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = 6000;     // 0dB
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = getRIV (6, 0, 6) | ((epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1)<<5);
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs = mcs;       // adjust according to size of RAR, 208 bits with N1A_PRB=3
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = 0;    // fix to 4 for now
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rvseq[round_DL&3];
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = UE_template->oldNDI[harq_pid];
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_process = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpmi = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.pmi = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.tpc = 3; 
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.srs_request = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = 0;
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = 0; // this is not needed by OAI L1, but should be filled in
+      dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = 1;
+      dl_req->number_pdu++;
+      UE_template->mcs[harq_pid] = dl_config_pdu->mpdcch_pdu.mpdcch_pdu_rel13.mcs;
     }
-    else if ((subframeP == 7)&&(round<8)) {  // DLSCH
+  } else if ((subframeP == 7) && (round_DL < 8)) { // DLSCH
+    LOG_D(MAC, "DLSCH round_DL = %d in frame %d subframe %d\n", round_DL, frameP, subframeP);
 	  
-	  int             absSF = (frameP * 10) + subframeP;
+	  int absSF = (frameP * 10) + subframeP;
 	  
-	  // Have to check that MPDCCH was generated
-	  LOG_I (MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating DLSCH (ce_level %d RNTI %x)\n",
-	    module_idP, CC_id, frameP, subframeP, UE_template->rach_resource_type - 1,rnti);
+	  /* Have to check that MPDCCH was generated */
+	  LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating DLSCH (ce_level %d RNTI %x)\n",
+	        module_idP, 
+          CC_id, 
+          frameP, 
+          subframeP, 
+          UE_template->rach_resource_type - 1,
+          rnti);
 	  
-	  first_rb = narrowband_to_first_rb (&cc[CC_id], epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1);            
-	  dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
-	  memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t));
-      dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE;
-      dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_dlsch_pdu));
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = mac->pdu_index[CC_id];
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2;   // format 1A/1B/1D
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0;     // localized
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV (to_prb (cc[CC_id].mib->message.dl_Bandwidth), first_rb, 6);  // check that this isn't getRIV(6,0,6)
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1;   // first block
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc[CC_id].p_eNB == 1) ? 0 : 1;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1;
-      //      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index                         = ;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize (cc[CC_id].mib->message.dl_Bandwidth); // ignored
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc[CC_id].p_eNB == 1) ? 1 : 2;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1;
-      //      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ; 
-      
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
-      
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2;        // not SI message
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP;
-      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0;
-      dl_req->number_pdu++;
+	  first_rb = narrowband_to_first_rb(&cc[CC_id], epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1);
 
-      // DL request
-      mac->TX_req[CC_id].sfn_sf = (frameP << 4) + subframeP;
-      TX_req = &mac->TX_req[CC_id].tx_request_body.tx_pdu_list[mac->TX_req[CC_id].tx_request_body.number_of_pdus];
-      TX_req->pdu_length = get_TBS_DL(UE_template->mcs[harq_pid],
-				      6);
-      TX_req->pdu_index = mac->pdu_index[CC_id]++;
-      TX_req->num_segments = 1;
-      TX_req->segments[0].segment_length = TX_req->pdu_length;
-      TX_req->segments[0].segment_data = mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0];
-      mac->TX_req[CC_id].tx_request_body.number_of_pdus++;
-
-      ackNAK_absSF = absSF + 4;
-      ul_req = &mac->UL_req_tmp[CC_id][ackNAK_absSF % 10].ul_config_request_body;
-      ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus];
-      
-      ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE;
-      ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_ul_config_uci_harq_pdu));
-      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0;      // don't know how to use this
-      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti = rnti;
-      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2;
-      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.empty_symbols = 0;
-      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions = pucchreps[UE_template->rach_resource_type - 1];
-      ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.repetition_number = 0;
-
-      if (cc[CC_id].tdd_Config == NULL) {    // FDD case
-	ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = n1pucchan[UE_template->rach_resource_type - 1];
-	// NOTE: How to fill in the rest of the n_pucch_1_0 information 213 Section 10.1.2.1 in the general case
-	// = N_ECCE_q + Delta_ARO + n1pucchan[ce_level]
-	// higher in the MPDCCH configuration, N_ECCE_q is hard-coded to 0, and harq resource offset to 0 =>
-	// Delta_ARO = 0 from Table 10.1.2.1-1
-	ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.harq_size = 1; // 1-bit ACK/NAK
-	ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.number_of_pucch_resources = 1;
+	  dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu];
+	  
+    memset ((void *) dl_config_pdu, 0, sizeof (nfapi_dl_config_request_pdu_t));
+    
+    dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE;
+    dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_dlsch_pdu));
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index = mac->pdu_index[CC_id];
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti = rnti;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = 2;   // format 1A/1B/1D
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0;     // localized
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = getRIV (to_prb (cc[CC_id].mib->message.dl_Bandwidth), first_rb, 6);  // check that this isn't getRIV(6,0,6)
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation = 2; //QPSK
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version = 0;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = 1;   // first block
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = 0;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = (cc[CC_id].p_eNB == 1) ? 0 : 1;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers = 1;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 1;
+    //      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index                         = ;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = 1;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa = 4; // 0 dB
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = 0;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap = 0;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb = get_subbandsize (cc[CC_id].mib->message.dl_Bandwidth); // ignored
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode = (cc[CC_id].p_eNB == 1) ? 1 : 2;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 1;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 1;
+    //      dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ; 
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel10.pdsch_start = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = 2;        // not SI message
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = (10 * frameP) + subframeP;
+    dl_config_pdu->dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = 0;
+    dl_req->number_pdu++;
+
+    // DL request
+    mac->TX_req[CC_id].sfn_sf = (frameP << 4) + subframeP;
+    TX_req = &mac->TX_req[CC_id].tx_request_body.tx_pdu_list[mac->TX_req[CC_id].tx_request_body.number_of_pdus];
+    TX_req->pdu_length = get_TBS_DL(UE_template->mcs[harq_pid], 6);
+    TX_req->pdu_index = mac->pdu_index[CC_id]++;
+    TX_req->num_segments = 1;
+    TX_req->segments[0].segment_length = TX_req->pdu_length;
+    TX_req->segments[0].segment_data = mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0];
+    mac->TX_req[CC_id].tx_request_body.number_of_pdus++;
+
+    ackNAK_absSF = absSF + 4;
+    ul_req = &mac->UL_req_tmp[CC_id][ackNAK_absSF % 10].ul_config_request_body;
+    ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus];
+    
+    ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE;
+    ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_ul_config_uci_harq_pdu));
+    ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0;      // don't know how to use this
+    ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti = rnti;
+    ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type = (UE_template->rach_resource_type < 3) ? 1 : 2;
+    ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.empty_symbols = 0;
+    ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.total_number_of_repetitions = pucchreps[UE_template->rach_resource_type - 1];
+    ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.repetition_number = 0;
+
+    if (cc[CC_id].tdd_Config == NULL) {  // FDD case
+      ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = n1pucchan[UE_template->rach_resource_type - 1];
+      // NOTE: How to fill in the rest of the n_pucch_1_0 information 213 Section 10.1.2.1 in the general case
+      // = N_ECCE_q + Delta_ARO + n1pucchan[ce_level]
+      // higher in the MPDCCH configuration, N_ECCE_q is hard-coded to 0, and harq resource offset to 0 =>
+      // Delta_ARO = 0 from Table 10.1.2.1-1
+      ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.harq_size = 1; // 1-bit ACK/NAK
+      ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel9_fdd.number_of_pucch_resources = 1;
       } else {
-	AssertFatal (1 == 0, "PUCCH configuration for ACK/NAK not handled yet for TDD BL/CE case\n");
+      	AssertFatal (1 == 0, "PUCCH configuration for ACK/NAK not handled yet for TDD BL/CE case\n");
       }
+
       ul_req->number_of_pdus++;
-      T (T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT (module_idP), T_INT (CC_id), T_INT (rnti), T_INT (frameP), T_INT (subframeP),
-	 T_INT (0 /*harq_pid always 0? */ ), T_BUFFER (&mac->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0], TX_req->pdu_length));
+      
+      T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, 
+        T_INT (module_idP), 
+        T_INT (CC_id), 
+        T_INT (rnti), 
+        T_INT (frameP), 
+        T_INT (subframeP),
+	      T_INT (0 /* harq_pid always 0? */ ), 
+        T_BUFFER (&mac->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0], TX_req->pdu_length));
       
       if (opt_enabled == 1) {
-	trace_pdu (1, (uint8_t *) mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0], TX_req->pdu_length , UE_id, 3, rnti, frameP, subframeP, 0, 0);
-	LOG_D (OPT, "[eNB %d][DLSCH] CC_id %d Frame %d trace pdu for rnti %x with size %d\n", module_idP, CC_id, frameP, rnti, TX_req->pdu_length );
-      }
-
-    }
-  }
+        trace_pdu(1, 
+                  (uint8_t *) mac->UE_list.DLSCH_pdu[CC_id][0][(unsigned char) UE_id].payload[0], 
+                  TX_req->pdu_length, 
+                  UE_id, 
+                  3, 
+                  rnti, 
+                  frameP, 
+                  subframeP, 
+                  0, 
+                  0);
 
+        LOG_D(OPT, "[eNB %d][DLSCH] CC_id %d Frame %d trace pdu for rnti %x with size %d\n", 
+              module_idP, 
+              CC_id, 
+              frameP, 
+              rnti, 
+              TX_req->pdu_length);
+      }
+    } // end else if ((subframeP == 7) && (round_DL < 8))
+  } // end loop on UE_id
 }
 #endif
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
index 3cc76dd67a72996f09eb8978d98161312ca12f69..db98335527cf4a8af652cbe44222e84d6b318f07 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
@@ -1451,7 +1451,7 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
                                             MBMS_FLAG_NO,
                                             lcid,
                                             TBS - ta_len - header_len_dcch - sdu_length_total - header_len_dtch
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                             , 0, 0
 #endif
                                            );
@@ -1472,7 +1472,7 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
                                       lcid,
                                       TBS,  //not used
                                       (char *)&dlsch_buffer[sdu_length_total]
-#ifdef Rel14
+#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                                       , 0, 0
 #endif
                                                       );
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index 219b288fd38634f1a03b00ce579a21e923c736e6..579449ac15dcc624692f9ed22439f528019fc21d 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -1951,8 +1951,7 @@ find_UE_id(module_id_t mod_idP,
 
   for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) {
     if (UE_list->active[UE_id] == TRUE) {
-      if (UE_list->UE_template[UE_PCCID(mod_idP, 
-                                        UE_id)][UE_id].rnti == rntiP) {
+      if (UE_list->UE_template[UE_PCCID(mod_idP, UE_id)][UE_id].rnti == rntiP) {
         return UE_id;
       }
     }
@@ -4075,6 +4074,8 @@ extract_harq(module_id_t mod_idP,
             }
           }
 
+          LOG_D(MAC, "In extract_harq(): pdu[0] = %d for harq_pid = %d\n", pdu[0], harq_pid);
+
           if (pdu[0] == 1) {  // ACK
             sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process
             sched_ctl->tbcnt[CC_idP][harq_pid] = 0;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index 10d4fc1523d837e886a5c31bd26b5d98a6a15b29..d86622ec52c665821e9e1329cd457e1b08deb0c9 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -458,9 +458,9 @@ rx_sdu(const module_id_t enb_mod_idP,
                                ,ra->rach_resource_type > 0
 #endif
                               );
-              /* Prepare transmission of Msg4(RRCConnectionReconfiguration) */
+              /* Received a new rnti */
               ra->state = MSGCRNTI;
-              LOG_I(MAC, "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) RRCConnectionReconfiguration(Msg4)\n",
+              LOG_I(MAC, "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) Received rnti(Msg4)\n",
                     enb_mod_idP,
                     frameP,
                     subframeP,
@@ -686,9 +686,9 @@ rx_sdu(const module_id_t enb_mod_idP,
               rx_lengths[i],
               payload_ptr - sduP);
 
-            if ((UE_id = add_new_ue(enb_mod_idP, CC_idP, mac->common_channels[CC_idP].ra->rnti, harq_pid
+            if ((UE_id = add_new_ue(enb_mod_idP, CC_idP, ra->rnti, harq_pid
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-                                    , mac->common_channels[CC_idP].ra->rach_resource_type
+                                    , ra->rach_resource_type
 #endif
                                     )) == -1) {
               LOG_E(MAC,"[MAC][eNB] Max user count reached\n");
@@ -1385,6 +1385,7 @@ schedule_ulsch_rnti(module_id_t module_idP,
     if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx)) {
       continue;
     }
+    if (UE_list->UE_template[UE_PCCID(module_idP, UE_id)][UE_id].rach_resource_type > 0)  continue;
 
     // don't schedule if Msg5 is not received yet
     if (UE_list->UE_template[UE_PCCID(module_idP, UE_id)][UE_id].configured == FALSE) {
@@ -1909,426 +1910,487 @@ schedule_ulsch_rnti(module_id_t module_idP,
 }
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
+//-----------------------------------------------------------------------------
+/*
+ * default ULSCH scheduler for LTE-M
+ */
 void schedule_ulsch_rnti_emtc(module_id_t   module_idP,
-			     frame_t       frameP,
-			     sub_frame_t   subframeP,
-			     unsigned char sched_subframeP,
-			     int          *emtc_active)
+                              frame_t       frameP,
+                              sub_frame_t   subframeP,
+                              unsigned char sched_subframeP,
+                              int          *emtc_active)
+//-----------------------------------------------------------------------------
 {
-  int               UE_id;
+  int               UE_id          = -1;
   rnti_t            rnti           = -1;
-  uint8_t           round          = 0;
+  uint8_t           round_UL       = 0;
   uint8_t           harq_pid       = 0;
   uint8_t           status         = 0;
-  uint32_t          cshift,ndi;
-  int32_t           normalized_rx_power;
-  int32_t           target_rx_power=-90;
-  int               n;
-  int               CC_id = 0;
-  int               N_RB_UL;
+  uint32_t          cshift         = 0;
+  uint32_t          ndi            = 0;
+  int32_t           normalized_rx_power = 0;
+  int32_t           target_rx_power = -90;
+  int               n       = 0;
+  int               CC_id   = 0;
+  int               N_RB_UL = 0;
+  int               sched_frame = frameP;
+  int               rvidx_tab[4] = {0,2,3,1};
+  int               tpc = 0;
+  int               cqi_req = 0;
   eNB_MAC_INST      *eNB = RC.mac[module_idP];
   COMMON_channels_t *cc  = eNB->common_channels;
-  UE_list_t         *UE_list=&eNB->UE_list;
-  UE_TEMPLATE       *UE_template;
-  UE_sched_ctrl     *UE_sched_ctrl;
-  int               sched_frame=frameP;
-  int               rvidx_tab[4] = {0,2,3,1};
-  int               tpc=0;
-  int               cqi_req=0;
+  UE_list_t         *UE_list = &(eNB->UE_list);
+  UE_TEMPLATE       *UE_template = NULL;
+  UE_sched_ctrl     *UE_sched_ctrl = NULL;
 
-  if (sched_subframeP<subframeP) sched_frame++;
+  if (sched_subframeP < subframeP) {
+    sched_frame++;
+  } 
 
-  nfapi_hi_dci0_request_body_t   *hi_dci0_req = &eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body;
-  nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu;
+  nfapi_hi_dci0_request_body_t   *hi_dci0_req = &(eNB->HI_DCI0_req[CC_id][subframeP].hi_dci0_request_body);
+  nfapi_hi_dci0_request_pdu_t    *hi_dci0_pdu = NULL;
 
-  nfapi_ul_config_request_body_t *ul_req_tmp       = &eNB->UL_req_tmp[CC_id][sched_subframeP].ul_config_request_body;
+  nfapi_ul_config_request_body_t *ul_req_tmp = &(eNB->UL_req_tmp[CC_id][sched_subframeP].ul_config_request_body);
 
-  // loop over all active UEs
-  if ((frameP&1) == 1) return;
+  /* If frameP odd don't schedule */
+  if ((frameP & 1) == 1) {
+    return;
+  }
 
-  for (UE_id=UE_list->head_ul; UE_id>=0; UE_id=UE_list->next_ul[UE_id]) {
+  /* Loop over all active UEs */
+  for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) {
+    UE_template = &(UE_list->UE_template[UE_PCCID(module_idP, UE_id)][UE_id]);
 
-    if (UE_list->UE_template[UE_PCCID(module_idP,UE_id)][UE_id].rach_resource_type == 0) continue;
+    /* LTE-M device */
+    if (UE_template->rach_resource_type == 0) continue;
 
-    // don't schedule if Msg4 is not received yet
-    if (UE_list->UE_template[UE_PCCID(module_idP,UE_id)][UE_id].configured==FALSE) {
-      LOG_D(MAC,"[eNB %d] frame %d subfarme %d, UE %d: not configured, skipping UE scheduling \n",
-            module_idP,frameP,subframeP,UE_id);
+    /* Don't schedule if Msg4 is not received yet */
+    if (UE_template->configured == FALSE) {
+      LOG_D(MAC,"[eNB %d] frame %d subframe %d, UE %d: not configured, skipping UE scheduling \n",
+            module_idP,
+            frameP,
+            subframeP,
+            UE_id);
       continue;
     }
 
-    rnti = UE_RNTI(module_idP,UE_id);
+    rnti = UE_RNTI(module_idP, UE_id);
+
+    if (rnti == NOT_A_RNTI) {
+      LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d: no RNTI \n", 
+            module_idP,
+            frameP,
+            subframeP,
+            UE_id);
 
-    if (rnti==NOT_A_RNTI) {
-      LOG_W(MAC,"[eNB %d] frame %d subfarme %d, UE %d: no RNTI \n", module_idP,frameP,subframeP,UE_id);
       continue;
     }
 
-    // loop over all active UL CC_ids for this UE
-    for (n=0; n<UE_list->numactiveULCCs[UE_id]; n++) {
-      // This is the actual CC_id in the list
-      CC_id        = UE_list->ordered_ULCCids[n][UE_id];
-      N_RB_UL      = to_prb(cc[CC_id].ul_Bandwidth);
-
+    /* Loop over all active UL CC_ids for this UE */
+    for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) {
+      /* This is the actual CC_id in the list */
+      CC_id   = UE_list->ordered_ULCCids[n][UE_id];
+      N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth);
 
-      UE_template   = &UE_list->UE_template[CC_id][UE_id];
+      UE_template   = &(UE_list->UE_template[CC_id][UE_id]);
       UE_sched_ctrl = &UE_list->UE_sched_ctrl[UE_id];
+
       harq_pid      = 0;
-      round         = UE_sched_ctrl->round_UL[CC_id][harq_pid];
-      AssertFatal(round<8,"round %d > 7 for UE %d/%x\n",round,UE_id,rnti);
+      round_UL      = UE_sched_ctrl->round_UL[CC_id][harq_pid];
+
+      AssertFatal(round_UL < 8,"round_UL %d > 7 for UE %d/%x\n",
+                  round_UL,
+                  UE_id,
+                  rnti);
+
       LOG_D(MAC,"[eNB %d] frame %d subframe %d,Checking PUSCH %d for BL/CE UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n",
-            module_idP,frameP,subframeP,harq_pid,UE_id,rnti,CC_id, 24,N_RB_UL);
+            module_idP,
+            frameP,
+            subframeP,
+            harq_pid,
+            UE_id,
+            rnti,
+            CC_id, 
+            24, // agregation level
+            N_RB_UL);
 
       RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP] = UE_template->estimated_ul_buffer;
-      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO,RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP]);
-      if ((UE_template->ul_SR >0  || round > 0 || status < RRC_CONNECTED)&&(subframeP==5)) 
-        // if there is information on bsr of DCCH, DTCH or if there is UL_SR, or if there is a packet to retransmit, or we want to schedule a periodic feedback every 10 frames
-        {
-          LOG_I(MAC,"[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x in round %d(SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n",
-                module_idP,harq_pid,frameP,subframeP,UE_id,rnti,round,UE_template->ul_SR,
-                UE_sched_ctrl->ul_inactivity_timer,
-
-                UE_sched_ctrl->ul_failure_timer,
-
-                UE_sched_ctrl->cqi_req_timer);
-          // reset the scheduling request
-	  emtc_active[CC_id]=1;
-          UE_template->ul_SR = 0;
-          status = mac_eNB_get_rrc_status(module_idP,rnti);
-
-	  /*
-          if (status < RRC_CONNECTED)
-            cqi_req = 0;
-          else if (UE_sched_ctrl->cqi_req_timer>300) {
-            cqi_req = 1;
-            UE_sched_ctrl->cqi_req_timer=0;
+      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO, UE_template->estimated_ul_buffer);
+      
+      //if ((UE_is_to_be_scheduled(module_idP, CC_id, UE_id) > 0) && (subframeP == 5)) {
+      if ((UE_template->ul_SR > 0 || round_UL > 0 || status < RRC_CONNECTED) && (subframeP == 5)) {
+        /* 
+         * if there is information on bsr of DCCH, DTCH,
+         * or if there is UL_SR, 
+         * or if there is a packet to retransmit, 
+         * or we want to schedule a periodic feedback every frame
+         */
+        
+        LOG_D(MAC,"[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x in round_UL %d(SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n",
+              module_idP,
+              harq_pid,
+              frameP,
+              subframeP,
+              UE_id,
+              rnti,
+              round_UL,
+              UE_template->ul_SR,
+              UE_sched_ctrl->ul_inactivity_timer,
+              UE_sched_ctrl->ul_failure_timer,
+              UE_sched_ctrl->cqi_req_timer);
+
+        /* Reset the scheduling request */
+        emtc_active[CC_id] = 1;
+        UE_template->ul_SR = 0;
+        status = mac_eNB_get_rrc_status(module_idP,rnti);
+        cqi_req = 0;
 
-          }
-          else
-            cqi_req = 0;
-	  */
-	  cqi_req = 0;
+        /* Power control: compute the expected ULSCH RX power (for the stats) */
+        /* This is the normalized RX power and this should be constant (regardless of mcs) */
+        normalized_rx_power = UE_sched_ctrl->pusch_snr[CC_id];
+        target_rx_power = 178;
 
- 
-          //power control
-          //compute the expected ULSCH RX power (for the stats)
-
-          // this is the normalized RX power and this should be constant (regardless of mcs
-          normalized_rx_power = UE_sched_ctrl->pusch_snr[CC_id];
-          target_rx_power = 178;
-
-          // this assumes accumulated tpc
-          // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
-          int32_t framex10psubframe = UE_template->pusch_tpc_tx_frame*10+UE_template->pusch_tpc_tx_subframe;
-          if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case
-              ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around
-            {
-              UE_template->pusch_tpc_tx_frame=frameP;
-              UE_template->pusch_tpc_tx_subframe=subframeP;
-              if (normalized_rx_power>(target_rx_power+4)) {
-                tpc = 0; //-1
-                UE_sched_ctrl->tpc_accumulated[CC_id]--;
-              } else if (normalized_rx_power<(target_rx_power-4)) {
-                tpc = 2; //+1
-                UE_sched_ctrl->tpc_accumulated[CC_id]++;
-              } else {
-                tpc = 1; //0
-              }
+        /* This assumes accumulated tpc */
+        /* Make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out */
+        int32_t framex10psubframe = UE_template->pusch_tpc_tx_frame * 10 + UE_template->pusch_tpc_tx_subframe;
+        if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || // normal case
+            ((framex10psubframe > (frameP * 10 + subframeP)) && (((10240 - framex10psubframe + frameP * 10 + subframeP) >= 10)))) // frame wrap-around
+          {
+            UE_template->pusch_tpc_tx_frame = frameP;
+            UE_template->pusch_tpc_tx_subframe = subframeP;
+            if (normalized_rx_power > (target_rx_power + 4)) {
+              tpc = 0; //-1
+              UE_sched_ctrl->tpc_accumulated[CC_id]--;
+            } else if (normalized_rx_power < (target_rx_power - 4)) {
+              tpc = 2; //+1
+              UE_sched_ctrl->tpc_accumulated[CC_id]++;
             } else {
+              tpc = 1; //0
+            }
+          } else {
             tpc = 1; //0
-          }
-          //tpc = 1;
+        }
+
+        if (tpc != 1) {
+          LOG_D(MAC,"[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n",
+                module_idP,
+                frameP,
+                subframeP,
+                harq_pid,
+                tpc,
+                UE_sched_ctrl->tpc_accumulated[CC_id],
+                normalized_rx_power,
+                target_rx_power);
+        }
 
+        /* New transmission */
+        if (round_UL == 0) {
+          ndi = 1 - UE_template->oldNDI_UL[harq_pid];
+          
+          UE_template->oldNDI_UL[harq_pid] = ndi;
+          UE_template->mcs_UL[harq_pid] = 4;
+          UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid], 6);
 
-          if (tpc!=1) {
-            LOG_D(MAC,"[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n",
-                  module_idP,frameP,subframeP,harq_pid,tpc,
-                  UE_sched_ctrl->tpc_accumulated[CC_id],normalized_rx_power,target_rx_power);
-          }
+          UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power = normalized_rx_power;
+          UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power = target_rx_power;
+          UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1 = 4;
+          UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2 = UE_template->mcs_UL[harq_pid];
+          UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx += 6;
+          UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS = UE_template->TBS_UL[harq_pid];
+          
+          T(T_ENB_MAC_UE_UL_SCHEDULE, 
+            T_INT(module_idP), 
+            T_INT(CC_id), 
+            T_INT(rnti), 
+            T_INT(frameP),
+            T_INT(subframeP), 
+            T_INT(harq_pid), 
+            T_INT(UE_template->mcs_UL[harq_pid]), 
+            T_INT(0), 
+            T_INT(6),
+            T_INT(UE_template->TBS_UL[harq_pid]), 
+            T_INT(ndi));
 
-          // new transmission
-          if (round==0) {
-
-            ndi = 1-UE_template->oldNDI_UL[harq_pid];
-            UE_template->oldNDI_UL[harq_pid]=ndi;
-            UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power=normalized_rx_power;
-            UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power=target_rx_power;
-            UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1=4;
-            UE_template->mcs_UL[harq_pid] = 4;
-
-
-            UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=UE_template->mcs_UL[harq_pid];
-            //            buffer_occupancy = UE_template->ul_total_buffer;
-
-
-
-            UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid],6);
-            UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx+=6;
-            UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS=UE_template->TBS_UL[harq_pid];
-            //            buffer_occupancy -= TBS;
-
-            T(T_ENB_MAC_UE_UL_SCHEDULE, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP),
-              T_INT(subframeP), T_INT(harq_pid), T_INT(UE_template->mcs_UL[harq_pid]), T_INT(0), T_INT(6),
-              T_INT(UE_template->TBS_UL[harq_pid]), T_INT(ndi));
-
-            // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
-            //store for possible retransmission
-            UE_template->nb_rb_ul[harq_pid]    = 6;
-
-
-            UE_sched_ctrl->ul_scheduled |= (1<<harq_pid);
-            if (UE_id == UE_list->head)
-              VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED,UE_sched_ctrl->ul_scheduled);
-
-            // adjust total UL buffer status by TBS, wait for UL sdus to do final update
-            UE_template->scheduled_ul_bytes += UE_template->TBS_UL[harq_pid];
-
-            LOG_D(MAC, "scheduled_ul_bytes, new %d\n", UE_template->scheduled_ul_bytes);
-
-
-            // Cyclic shift for DM RS
-            cshift = 0;// values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1)
-            // save it for a potential retransmission
-            UE_template->cshift[harq_pid] = cshift;
-
-	    AssertFatal (UE_template->physicalConfigDedicated != NULL, 
-			 "UE_template->physicalConfigDedicated is null\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, 
-			 "UE_template->physicalConfigDedicated->ext4 is null\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, 
-			 "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, 
-	      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL,
-	      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n");
-	    LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0];
-	    AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n");
-	    AssertFatal(epdcch_setconfig_r11->ext2!=NULL, "epdcch_setconfig_r11->ext2 is null\n");
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL,
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL,
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present==LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, 
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n");
-	    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310!=NULL,
-			"epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null");
-	    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present==LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, 
-			"epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n");
-
-	    LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d,UESS MPDCCH Narrowband %d\n",
-                  harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP,(int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1);
-
-            UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb (cc,
-									 epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1);	     
-            hi_dci0_pdu                                                         = &hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci+hi_dci0_req->number_of_hi];
-            memset((void*)hi_dci0_pdu,0,sizeof(nfapi_hi_dci0_request_pdu_t));
-
-	    hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE;
-	    hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu));
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1; 
-
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6;       // checked above that it has to be this
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11;  // distibuted
-
-	    AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11!=NULL,
-	      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n");
-
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0;        // Note: this should be dynamic
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24;        // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000;     // 0dB
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid];
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4;       // adjust according to size of RAR, 208 bits with N1A_PRB=3
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0;
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13==
-			LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off,
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); 
-    	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag  = 1-epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid];
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc;       
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1;
-
-            hi_dci0_req->number_of_dci++;
-
-
-            LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d, UESS mpdcch narrowband %d\n",
-                  harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP,
-		  (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1);
-
-
-            fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
-                                                 cqi_req,
-                                                 cc,
-                                                 UE_template->physicalConfigDedicated,
-                                                 get_tmode(module_idP,CC_id,UE_id),
-                                                 eNB->ul_handle,
-                                                 rnti,
-                                                 UE_template->first_rb_ul[harq_pid], // resource_block_start
-                                                 UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks
-                                                 UE_template->mcs_UL[harq_pid],
-                                                 cshift, // cyclic_shift_2_for_drms
-                                                 0, // frequency_hopping_enabled_flag
-                                                 0, // frequency_hopping_bits
-                                                 UE_template->oldNDI_UL[harq_pid], // new_data_indication
-                                                 rvidx_tab[round&3], // redundancy_version
-                                                 harq_pid, // harq_process_number
-                                                 0, // ul_tx_mode
-                                                 0, // current_tx_nb
-                                                 0, // n_srs
-                                                 UE_template->TBS_UL[harq_pid]
-                                                 );
-	    fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
-						 UE_template->rach_resource_type>2 ? 2 : 1,
-						 1, //total_number_of_repetitions
-						 1, //repetition_number
-						 (frameP*10)+subframeP);
-	  
+          /* Store for possible retransmission */
+          UE_template->nb_rb_ul[harq_pid] = 6;
+          UE_sched_ctrl->ul_scheduled |= (1 << harq_pid);
 
-            ul_req_tmp->number_of_pdus++;
-            eNB->ul_handle++;
+          if (UE_id == UE_list->head) {
+            VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED, UE_sched_ctrl->ul_scheduled);
+          }
 
-            add_ue_ulsch_info(module_idP,
-                              CC_id,
-                              UE_id,
-                              subframeP,
-                              S_UL_SCHEDULED);
+          /* Adjust total UL buffer status by TBS, wait for UL sdus to do final update */
+          UE_template->scheduled_ul_bytes += UE_template->TBS_UL[harq_pid];
 
-            LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", module_idP,CC_id,frameP,subframeP,UE_id);
+          LOG_D(MAC, "scheduled_ul_bytes, new %d\n", UE_template->scheduled_ul_bytes);
 
-          }
-          else { // round > 0 => retransmission
-            T(T_ENB_MAC_UE_UL_SCHEDULE_RETRANSMISSION, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP),
-              T_INT(subframeP), T_INT(harq_pid), T_INT(UE_template->mcs_UL[harq_pid]), T_INT(0), T_INT(6),
-              T_INT(round));
-
-	    AssertFatal (UE_template->physicalConfigDedicated != NULL, 
-			 "UE_template->physicalConfigDedicated is null\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, 
-			 "UE_template->physicalConfigDedicated->ext4 is null\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, 
-			 "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, 
-	      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n");
-	    AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL,
-	      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n");
-	    LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0];
-	    AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n");
-	    AssertFatal(epdcch_setconfig_r11->ext2!=NULL, "epdcch_setconfig_r11->ext2 is null\n");
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL,
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13!=NULL,
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present==LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, 
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n");
-	    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310!=NULL,
-			"epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null");
-	    AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present==LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, 
-			"epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n");
-
-	    LOG_I(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d,UESS MPDCCH Narrowband %d\n",
-                  harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP,(int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1);
-
-            UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb (cc,
-									 epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1);	     
-            hi_dci0_pdu                                                         = &hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci+hi_dci0_req->number_of_hi];
-            memset((void*)hi_dci0_pdu,0,sizeof(nfapi_hi_dci0_request_pdu_t));
-
-	    hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE;
-	    hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu));
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1; 
-
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6;       // checked above that it has to be this
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11;  // distibuted
-
-	    AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11!=NULL,
-	      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n");
-
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0;        // Note: this should be dynamic
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24;        // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000;     // 0dB
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid];
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4;       // adjust according to size of RAR, 208 bits with N1A_PRB=3
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0;
-	    AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13==
-			LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off,
-			"epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); 
-    	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag  = 1-epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = rvidx_tab[round&3];
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid];
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = harq_pid;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0;
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz
-	    hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1;
-
-	    hi_dci0_req->number_of_dci++;
-            fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
-                                                 cqi_req,
-                                                 cc,
-                                                 UE_template->physicalConfigDedicated,
-                                                 get_tmode(module_idP,CC_id,UE_id),
-                                                 eNB->ul_handle,
-                                                 rnti,
-                                                 UE_template->first_rb_ul[harq_pid], // resource_block_start
-                                                 UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks
-                                                 UE_template->mcs_UL[harq_pid],
-                                                 cshift, // cyclic_shift_2_for_drms
-                                                 0, // frequency_hopping_enabled_flag
-                                                 0, // frequency_hopping_bits
-                                                 UE_template->oldNDI_UL[harq_pid], // new_data_indication
-                                                 rvidx_tab[round&3], // redundancy_version
-                                                 harq_pid, // harq_process_number
-                                                 0, // ul_tx_mode
-                                                 0, // current_tx_nb
-                                                 0, // n_srs
-                                                 UE_template->TBS_UL[harq_pid]
-                                                 );
-	    fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
-						 UE_template->rach_resource_type>2 ? 2 : 1,
-						 1, //total_number_of_repetitions
-						 1, //repetition_number
-						 (frameP*10)+subframeP);
-            
-	    ul_req_tmp->number_of_pdus++;
-	    eNB->ul_handle++;
+          /* Cyclic shift for DMRS */
+          cshift = 0; // values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1)
+          /* save it for a potential retransmission */
+          UE_template->cshift[harq_pid] = cshift;
+
+          AssertFatal (UE_template->physicalConfigDedicated != NULL, "UE_template->physicalConfigDedicated is null\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, "UE_template->physicalConfigDedicated->ext4 is null\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, 
+                      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL,
+                      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n");
+          
+          LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0];
+
+          AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n");
+          AssertFatal(epdcch_setconfig_r11->ext2 != NULL, "epdcch_setconfig_r11->ext2 is null\n");
+          AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
+          AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, 
+                      "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n");
+          AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 != NULL, "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null");
+          AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present == LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, 
+                      "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n");
+
+          LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d, UESS MPDCCH Narrowband %d\n",
+                harq_pid,
+                frameP,
+                subframeP,
+                UE_id,
+                rnti,
+                sched_frame,
+                sched_subframeP,
+                (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1);
 
-          }
-        } // UE_is_to_be_scheduled
+          UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb (cc, epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1);
+          
+          hi_dci0_pdu = &(hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci + hi_dci0_req->number_of_hi]);
+          memset((void*) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t));
+
+          hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE;
+          hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu));
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1; 
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6;       // checked above that it has to be this
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11;  // distibuted
+
+          AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 != NULL,
+                      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n");
+
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0;          // Note: this should be dynamic
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2; // already set above...
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000;     // 0dB
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid];
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4;       // adjust according to size of RAR, 208 bits with N1A_PRB = 3
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0;
+
+          AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13 == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off,
+                      "epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); 
+          
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag = 1 - epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid];
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc;       
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1;
+
+          hi_dci0_req->number_of_dci++;
+
+          LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG. Request for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d, UESS mpdcch narrowband %d\n",
+                harq_pid,
+                frameP,
+                subframeP,
+                UE_id,
+                rnti,
+                sched_frame,
+                sched_subframeP,
+                (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1);
+
+          fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
+                                                cqi_req,
+                                                cc,
+                                                UE_template->physicalConfigDedicated,
+                                                get_tmode(module_idP,CC_id,UE_id),
+                                                eNB->ul_handle,
+                                                rnti,
+                                                UE_template->first_rb_ul[harq_pid], // resource_block_start
+                                                UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks
+                                                UE_template->mcs_UL[harq_pid],
+                                                cshift, // cyclic_shift_2_for_drms
+                                                0, // frequency_hopping_enabled_flag
+                                                0, // frequency_hopping_bits
+                                                UE_template->oldNDI_UL[harq_pid], // new_data_indication
+                                                rvidx_tab[round_UL&3], // redundancy_version
+                                                harq_pid, // harq_process_number
+                                                0, // ul_tx_mode
+                                                0, // current_tx_nb
+                                                0, // n_srs
+                                                UE_template->TBS_UL[harq_pid]
+                                                );
+
+          fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
+                                              UE_template->rach_resource_type > 2 ? 2 : 1,
+                                              1, // total_number_of_repetitions
+                                              1, // repetition_number
+                                              (frameP * 10) + subframeP);
+  
+          ul_req_tmp->number_of_pdus++;
+          eNB->ul_handle++;
+
+          add_ue_ulsch_info(module_idP,
+                            CC_id,
+                            UE_id,
+                            subframeP,
+                            S_UL_SCHEDULED);
+
+          LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", 
+                module_idP,
+                CC_id,
+                frameP,
+                subframeP,
+                UE_id);
+
+        } else { // round_UL > 0 => retransmission
+          /* In LTE-M the UL HARQ process is asynchronous */            
+          T(T_ENB_MAC_UE_UL_SCHEDULE_RETRANSMISSION, 
+            T_INT(module_idP), 
+            T_INT(CC_id), 
+            T_INT(rnti), 
+            T_INT(frameP),
+            T_INT(subframeP), 
+            T_INT(harq_pid), 
+            T_INT(UE_template->mcs_UL[harq_pid]), 
+            T_INT(0), 
+            T_INT(6),
+            T_INT(round_UL));
+
+          AssertFatal (UE_template->physicalConfigDedicated != NULL, "UE_template->physicalConfigDedicated is null\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4 != NULL, "UE_template->physicalConfigDedicated->ext4 is null\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 != NULL, "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11 is null\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present == LTE_EPDCCH_Config_r11__config_r11_PR_setup, 
+                      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.present != setup\n");
+          AssertFatal (UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 != NULL,
+                      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11 = NULL\n");
+          
+          LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11 = UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0];
+          
+          AssertFatal(epdcch_setconfig_r11 != NULL, "epdcch_setconfig_r11 is null\n");
+          AssertFatal(epdcch_setconfig_r11->ext2 != NULL, "epdcch_setconfig_r11->ext2 is null\n");
+          AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
+          AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13 != NULL, "epdcch_setconfig_r11->ext2->mpdcch_config_r13 is null");
+          AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->present == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13_PR_setup, 
+                      "epdcch_setconfig_r11->ext2->mpdcch_config_r13->present is not setup\n");
+          AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 != NULL, "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310 is null");
+          AssertFatal(epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present == LTE_EPDCCH_SetConfig_r11__ext2__numberPRB_Pairs_v1310_PR_setup, 
+                      "epdcch_setconfig_r11->ext2->numberPRB_Pairs_v1310->present is not setup\n");
+
+          LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL 6-0A MPDCCH for BL/CE UE %d/%x, ulsch_frame %d, ulsch_subframe %d,UESS MPDCCH Narrowband %d\n",
+                      harq_pid,
+                      frameP,
+                      subframeP,
+                      UE_id,
+                      rnti,
+                      sched_frame,
+                      sched_subframeP,
+                      (int)epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1);
+
+          UE_template->first_rb_ul[harq_pid] = narrowband_to_first_rb(cc, epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13-1);	     
+          
+          hi_dci0_pdu = &(hi_dci0_req->hi_dci0_pdu_list[hi_dci0_req->number_of_dci+hi_dci0_req->number_of_hi]);
+          
+          memset((void*) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t));
+
+          hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE;
+          hi_dci0_pdu->pdu_size = (uint8_t) (2 + sizeof (nfapi_dl_config_mpdcch_pdu));
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_format = (UE_template->rach_resource_type > 1) ? 5 : 4;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type > 1) ? 2 : 1;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_narrowband = epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_Narrowband_r13 - 1;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_prb_pairs = 6;       // checked above that it has to be this
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_assignment = 0; // Note: this can be dynamic
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mpdcch_transmission_type = epdcch_setconfig_r11->transmissionType_r11;  // distibuted
+
+          AssertFatal(UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 != NULL,
+                      "UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11 is null\n");
+
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.start_symbol = *UE_template->physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.startSymbol_r11;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ecce_index = 0;          // Note: this should be dynamic
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.aggreagation_level = 24; // OK for CEModeA r1-3 (9.1.5-1b) or CEModeB r1-4
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti_type = 4; // other
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.rnti = rnti;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ce_mode = (UE_template->rach_resource_type < 3) ? 1 : 2;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.drms_scrambling_init = epdcch_setconfig_r11->dmrs_ScramblingSequenceInt_r11;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.initial_transmission_sf_io = (frameP * 10) + subframeP;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.transmission_power = 6000;     // 0dB
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.resource_block_start = UE_template->first_rb_ul[harq_pid];
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_resource_blocks = 6;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.mcs = 4;       // adjust according to size of RAR, 208 bits with N1A_PRB=3
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.pusch_repetition_levels = 0;
+
+          AssertFatal(epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13 == LTE_EPDCCH_SetConfig_r11__ext2__mpdcch_config_r13__setup__mpdcch_pdsch_HoppingConfig_r13_off,
+                      "epdcch_setconfig_r11->ext2->mpdcch_config_r13->mpdcch_pdsch_HoppingConfig_r13 is not off\n"); 
+          
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.frequency_hopping_flag  = 1 - epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_pdsch_HoppingConfig_r13;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.redudency_version = rvidx_tab[round_UL&3];
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.new_data_indication = UE_template->oldNDI_UL[harq_pid];
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.harq_process = harq_pid;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tpc = tpc;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.csi_request = cqi_req;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.ul_inex = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dai_presence_flag = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dl_assignment_index = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.srs_request = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.dci_subframe_repetition_number = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tcp_bitmap = 0;
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.total_dci_length_include_padding = 29; // hard-coded for 10 MHz
+          hi_dci0_pdu->mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.number_of_tx_antenna_ports = 1;
+
+          hi_dci0_req->number_of_dci++;
+
+          fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
+                                                cqi_req,
+                                                cc,
+                                                UE_template->physicalConfigDedicated,
+                                                get_tmode(module_idP,CC_id,UE_id),
+                                                eNB->ul_handle,
+                                                rnti,
+                                                UE_template->first_rb_ul[harq_pid], // resource_block_start
+                                                UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks
+                                                UE_template->mcs_UL[harq_pid],
+                                                cshift, // cyclic_shift_2_for_drms
+                                                0, // frequency_hopping_enabled_flag
+                                                0, // frequency_hopping_bits
+                                                UE_template->oldNDI_UL[harq_pid], // new_data_indication
+                                                rvidx_tab[round_UL&3], // redundancy_version
+                                                harq_pid, // harq_process_number
+                                                0, // ul_tx_mode
+                                                0, // current_tx_nb
+                                                0, // n_srs
+                                                UE_template->TBS_UL[harq_pid]
+                                                );
+
+          fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp->ul_config_pdu_list[ul_req_tmp->number_of_pdus],
+                                              UE_template->rach_resource_type>2 ? 2 : 1,
+                                              1, //total_number_of_repetitions
+                                              1, //repetition_number
+                                              (frameP * 10) + subframeP);
+                
+          ul_req_tmp->number_of_pdus++;
+          eNB->ul_handle++;
+        }
+      } // UE_is_to_be_scheduled
     } // ULCCs
   } // loop over UE_id
 }
diff --git a/openair2/LAYER2/MAC/rar_tools.c b/openair2/LAYER2/MAC/rar_tools.c
index 2fa13fc98c2293b9ab5215ef12a5c540bbc9cc47..284c0af19e0a96c52466b821031c8eca895b8f33 100644
--- a/openair2/LAYER2/MAC/rar_tools.c
+++ b/openair2/LAYER2/MAC/rar_tools.c
@@ -110,98 +110,124 @@ fill_rar(const module_id_t module_idP,
 
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
 //------------------------------------------------------------------------------
-
+/*
+ * Fill the RAR buffer (header + PDU) for LTE-M devices
+ */
 unsigned short fill_rar_br(eNB_MAC_INST *eNB,
-			   int CC_id,
-			   RA_t        *ra,
-			   const frame_t      frameP,
-			   const sub_frame_t  subframeP,
-			   uint8_t*    const  dlsch_buffer,
-			   const uint8_t      ce_level
-			   )
+                           int CC_id,
+                           RA_t *ra,
+                           const frame_t frameP,
+                           const sub_frame_t subframeP,
+                           uint8_t* const dlsch_buffer,
+                           const uint8_t ce_level)
 //------------------------------------------------------------------------------
 {
-
-  RA_HEADER_RAPID *rarh = (RA_HEADER_RAPID *)dlsch_buffer;
+  RA_HEADER_RAPID *rarh = (RA_HEADER_RAPID *) dlsch_buffer;
   COMMON_channels_t *cc = &eNB->common_channels[CC_id];
-  uint8_t *rar = (uint8_t *)(dlsch_buffer+1);
-
-  uint32_t rballoc,reps;
-  uint32_t TPC,ULdelay,cqireq,mpdcch_nb_index;
-  int input_buffer_length;
+  uint8_t *rar = (uint8_t *)(dlsch_buffer + 1);
 
+  uint32_t rballoc = 0;
+  uint32_t reps = 0;
+  uint32_t ULdelay = 0;
+  uint32_t cqireq = 0;
+  uint32_t mpdcch_nb_index = 0;
+  uint32_t TPC = 0;
+  int input_buffer_length = 0;
+  int N_NB_index = 0;
 
   AssertFatal(ra != NULL, "RA is null \n");
   
-  // subheader fixed
+  /* Subheader fixed */
   rarh->E = 0;		// First and last RAR
   rarh->T = 1;		// 0 for E/T/R/R/BI subheader, 1 for E/T/RAPID subheader
-  rarh->RAPID = ra->preamble_index;	// Respond to Preamble 0 only for the moment
-  ra->timing_offset /= 16;	//T_A = N_TA/16, where N_TA should be on a 30.72Msps
-  rar[0] = (uint8_t) (ra->timing_offset >> (2 + 4));	// 7 MSBs of timing advance + divide by 4
-  rar[1] = (uint8_t) (ra->timing_offset << (4 - 2)) & 0xf0;	// 4 LSBs of timing advance + divide by 4
-  
-  int N_NB_index;
+  rarh->RAPID = ra->preamble_index;	// Respond to Preamble
+
+  /* RAR PDU */
+  /* TA Command */
+  ra->timing_offset /= 16;	// T_A = N_TA/16, where N_TA should be on a 30.72Msps
+  rar[0] = (uint8_t) (ra->timing_offset >> 4) & 0x7f;	// 7 MSBs of timing advance
+  rar[1] = (uint8_t) (ra->timing_offset & 0x0f) << 4;	// 4 LSBs of timing advance
   
-  // Copy the Msg2 narrowband
+  /* Copy the Msg2 narrowband */
   ra->msg34_narrowband = ra->msg2_narrowband;
   ra->msg3_first_rb    = 0;
   ra->msg3_nb_rb       = 2;
 
-
-  if (ce_level < 2) {		//CE Level 0,1, CEmodeA
+  if (ce_level < 2) {	// CE Level 0, 1 (CEmodeA)
     input_buffer_length = 6;
     
     N_NB_index = get_numnarrowbandbits(cc->mib->message.dl_Bandwidth);
 
-    rar[4] = (uint8_t)(ra->rnti>>8);
-    rar[5] = (uint8_t)(ra->rnti&0xff);
-    //cc->ra[ra_idx].timing_offset = 0;
-    
+    /* UL Grant */
     reps = 0;
     ra->msg3_mcs = 7;
     TPC = 3; // no power increase
     ULdelay = 0;
     cqireq = 0;
     mpdcch_nb_index = 0;
-    rballoc = mac_computeRIV(6,ra->msg3_first_rb,ra->msg3_nb_rb);
+    rballoc = mac_computeRIV(6, ra->msg3_first_rb, ra->msg3_nb_rb);
 
     uint32_t buffer = 0;
     buffer |= ra->msg34_narrowband << (16 + (4 - N_NB_index));
-    buffer |= ((rballoc & 0xFF) << (12 + (4 - N_NB_index)));
+    buffer |= ((rballoc & 0x0F) << (12 + (4 - N_NB_index)));
     buffer |= ((reps & 0x03) << (10 + (4 - N_NB_index)));
     buffer |= ((ra->msg3_mcs & 0x07) << (7 + (4 - N_NB_index)));
     buffer |= ((TPC & 0x07) << (4 + (4 - N_NB_index)));
     buffer |= ((cqireq & 0x01) << (3 + (4 - N_NB_index)));
     buffer |= ((ULdelay & 0x01) << (2 + (4 - N_NB_index)));
     buffer |= (mpdcch_nb_index << (4 - N_NB_index));
-    rar[1] = (buffer>>16) & 0x0F;
-    rar[2] = (buffer>>8) & 0xFF;
-    rar[3] = buffer&0xFF;
-  }
-  else { // CE level 2,3 => CEModeB
 
-    AssertFatal(1==0,"Shouldn't get here ...\n");
-    input_buffer_length =5;
+    rar[1] |= (uint8_t) (buffer >> 16) & 0x0F;
+    rar[2] = (uint8_t) (buffer >> 8) & 0xFF;
+    rar[3] = (uint8_t) buffer & 0xFF;
 
+    /* RA CRNTI */
+    rar[4] = (uint8_t)(ra->rnti >> 8);
+    rar[5] = (uint8_t)(ra->rnti & 0xff);
+  
+  } else { // CE level 2, 3 (CEModeB)
 
-    rar[3] = (uint8_t)(ra->rnti>>8);
-    rar[4] = (uint8_t)(ra->rnti&0xff);
+    AssertFatal(1 == 0, "Shouldn't get here ...\n");
+
+    input_buffer_length = 5;
+
+    rar[3] = (uint8_t)(ra->rnti >> 8);
+    rar[4] = (uint8_t)(ra->rnti & 0xff);
   }
-  LOG_I(MAC,"[RAPROC] Frame %d Subframe %d : Generating RAR BR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for ce_level %d, CRNTI %x,preamble %d/%d,TIMING OFFSET %d\n",
-        frameP,subframeP,
-        *(uint8_t*)rarh,rar[0],rar[1],rar[2],rar[3],rar[4],rar[5],
+
+  LOG_I(MAC, "[RAPROC] Frame %d Subframe %d : Generating RAR BR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for ce_level %d, CRNTI %x, preamble %d/%d, TIMING OFFSET %d\n",
+        frameP,
+        subframeP,
+        *(uint8_t*) rarh,
+        rar[0],
+        rar[1],
+        rar[2],
+        rar[3],
+        rar[4],
+        rar[5],
         ce_level,
         ra->rnti,
-        rarh->RAPID,ra->preamble_index,
+        rarh->RAPID,
+        ra->preamble_index,
         ra->timing_offset);
 
   if (opt_enabled) {
-    trace_pdu(DIRECTION_DOWNLINK , dlsch_buffer, input_buffer_length, eNB->Mod_id,  WS_RA_RNTI , 1,
-	      eNB->frame, eNB->subframe, 0, 0);
-    LOG_D(OPT,
-	  "[RAPROC] RAR Frame %d trace pdu for rnti %x and  rapid %d size %d\n",
-	  frameP, ra->rnti, rarh->RAPID, input_buffer_length);
+    trace_pdu(DIRECTION_DOWNLINK, 
+              dlsch_buffer, 
+              input_buffer_length, 
+              eNB->Mod_id,  
+              WS_RA_RNTI, 
+              1, 
+              eNB->frame, 
+              eNB->subframe, 
+              0, 
+              0);
+
+    LOG_D(OPT, "[RAPROC] RAR Frame %d trace pdu for rnti %x and rapid %d size %d\n",
+	        frameP, 
+          ra->rnti, 
+          rarh->RAPID, 
+          input_buffer_length);
   }
 
   return (ra->rnti);
diff --git a/openair2/RRC/LTE/L2_interface_common.c b/openair2/RRC/LTE/L2_interface_common.c
index b03b36a557431d58f8ca8c036dd47e5ebf09bce4..c8553b59701e2331f5e42ccb7a895e09b1aced48 100644
--- a/openair2/RRC/LTE/L2_interface_common.c
+++ b/openair2/RRC/LTE/L2_interface_common.c
@@ -135,7 +135,7 @@ rrc_data_ind(
     LOG_I(RRC, "[UE %x] Frame %d: received a DCCH %d message on SRB %d with Size %d from eNB %d\n",
           ctxt_pP->module_id, ctxt_pP->frame, DCCH_index,Srb_id,sdu_sizeP,  ctxt_pP->eNB_index);
   } else {
-    LOG_I(RRC, "[eNB %d] Frame %d: received a DCCH %d message on SRB %d with Size %d from UE %x\n",
+    LOG_D(RRC, "[eNB %d] Frame %d: received a DCCH %d message on SRB %d with Size %d from UE %x\n",
           ctxt_pP->module_id,
           ctxt_pP->frame,
           DCCH_index,
diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c
index 09c051a62dc43b1920c9a7d7cfd5501fad0b7d19..53e94ab82809e94068b823c7edfa2e90f5fa6179 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c
@@ -3083,6 +3083,27 @@ uint8_t do_RRCConnectionSetup_BR(
   physicalConfigDedicated2->ext7->csi_RS_ConfigNZPToReleaseListExt_r13 = NULL;
 
 
+  rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.mac_MainConfig = CALLOC(1,sizeof(struct LTE_RadioResourceConfigDedicated__mac_MainConfig));
+  rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.mac_MainConfig->present = LTE_RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue;
+  LTE_MAC_MainConfig_t *mac_MainConfig = &rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.mac_MainConfig->choice.explicitValue;
+  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
+  //long *maxHARQ_Tx = CALLOC(1, sizeof(long));
+  //*maxHARQ_Tx = LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
+  long *periodicBSR_Timer = CALLOC(1, sizeof(long));
+  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64;
+  //mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
+  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
+  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320;
+  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
+  mac_MainConfig->timeAlignmentTimerDedicated = LTE_TimeAlignmentTimer_infinity;
+  mac_MainConfig->drx_Config = NULL;
+  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
+  mac_MainConfig->phr_Config->present = LTE_MAC_MainConfig__phr_Config_PR_setup;
+  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
+  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
+  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB3;  // Value dB1 =1 dB, dB3 = 3 dB
+
+
   rrcConnectionSetup->rrc_TransactionIdentifier = Transaction_id;
   rrcConnectionSetup->criticalExtensions.present = LTE_RRCConnectionSetup__criticalExtensions_PR_c1;
   rrcConnectionSetup->criticalExtensions.choice.c1.present =LTE_RRCConnectionSetup__criticalExtensions__c1_PR_rrcConnectionSetup_r8 ;
@@ -3091,7 +3112,7 @@ uint8_t do_RRCConnectionSetup_BR(
   rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.drb_ToReleaseList = NULL;
   rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.sps_Config = NULL;
   rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.physicalConfigDedicated = physicalConfigDedicated2;
-  rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.mac_MainConfig = NULL;
+  // rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.mac_MainConfig = NULL;
 
 #ifdef XER_PRINT
   xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void*)&dl_ccch_msg);
diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h
index 22a9332a58c5842e81ac89ce1d1e71c6a99b786d..b576a7e9339eeae767b6e2715c06c168dbb496b2 100644
--- a/openair2/RRC/LTE/rrc_defs.h
+++ b/openair2/RRC/LTE/rrc_defs.h
@@ -344,7 +344,8 @@ typedef enum HO_STATE_e {
   HO_REQUEST,
   HO_ACK,
   HO_CONFIGURED,
-  HO_RELEASE
+  HO_RELEASE,
+  HO_CANCEL
 } HO_STATE_t;
 
 typedef enum SL_TRIGGER_e {
diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index c69888b0c1868ee749ba6fc57107c1a89d8525f3..fbc5d8f2564ff45a70a46ab0919f5ab002eeca0c 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -63,6 +63,7 @@
 #include "LTE_PeriodicBSR-Timer-r12.h"
 #include "LTE_RetxBSR-Timer-r12.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
+#include "x2ap_eNB.h"
 
 #include "T.h"
 
@@ -850,9 +851,7 @@ rrc_eNB_free_UE(
       LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ sent for RNTI %x, cause 21, radio connection with ue lost\n",
             enb_mod_idP,
             rnti);
-#if defined(ENABLE_USE_MME)
       rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 21);
-#endif
       // send cause 21: radio connection with ue lost
       /* From 3GPP 36300v10 p129 : 19.2.2.2.2 S1 UE Context Release Request (eNB triggered)
         * If the E-UTRAN internal reason is a radio link failure detected in the eNB, the eNB shall wait a sufficient time before
@@ -868,9 +867,7 @@ rrc_eNB_free_UE(
       LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ sent for RNTI %x, cause 20, user inactivity\n",
             enb_mod_idP,
             rnti);
-#if defined(ENABLE_USE_MME)
       rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 20);
-#endif
       // send cause 20: user inactivity
       return;
     }
@@ -1043,9 +1040,7 @@ rrc_eNB_process_RRCConnectionSetupComplete(
 
   if (EPC_MODE_ENABLED == 1) {
     // Forward message to S1AP layer
-#if defined(ENABLE_USE_MME)
     rrc_eNB_send_S1AP_NAS_FIRST_REQ(ctxt_pP, ue_context_pP, rrcConnectionSetupComplete);
-#endif
   } else {
     // RRC loop back (no S1AP), send SecurityModeCommand to UE
     rrc_eNB_generate_SecurityModeCommand(ctxt_pP, ue_context_pP);
@@ -1342,6 +1337,7 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
   LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
+  int                                    x2_enabled;
   uint8_t next_xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);
   ue_context_pP->ue_context.Status = RRC_CONNECTED;
   ue_context_pP->ue_context.ue_rrc_inactivity_timer = 1; // set rrc inactivity when UE goes into RRC_CONNECTED
@@ -1752,6 +1748,8 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
     dedicatedInfoNASList = NULL;
   }
 
+  x2_enabled = is_x2ap_enabled();
+
   // send LTE_RRCConnectionReconfiguration
   memset(buffer, 0, RRC_BUF_SIZE);
   size = do_RRCConnectionReconfiguration(ctxt_pP,
@@ -1762,14 +1760,14 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
                                          (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
                                          (struct LTE_SPS_Config *)NULL,   // maybe ue_context_pP->ue_context.sps_Config,
                                          (struct LTE_PhysicalConfigDedicated *)ue_context_pP->ue_context.physicalConfigDedicated,
-#ifdef EXMIMO_IOT
-                                         NULL, NULL, NULL,NULL,
-#else
-                                         (LTE_MeasObjectToAddModList_t *)MeasObj_list, // MeasObj_list,
-                                         (LTE_ReportConfigToAddModList_t *)ReportConfig_list, // ReportConfig_list,
-                                         (LTE_QuantityConfig_t *)quantityConfig, //quantityConfig,
+//#ifdef EXMIMO_IOT
+//                                         NULL, NULL, NULL,NULL,
+//#else
+                                         x2_enabled ? (LTE_MeasObjectToAddModList_t *)MeasObj_list : NULL, // MeasObj_list,
+                                         x2_enabled ? (LTE_ReportConfigToAddModList_t *)ReportConfig_list : NULL, // ReportConfig_list,
+                                         x2_enabled ? (LTE_QuantityConfig_t *)quantityConfig : NULL, //quantityConfig,
                                          (LTE_MeasIdToAddModList_t *)NULL,
-#endif
+//#endif
                                          (LTE_MAC_MainConfig_t *)ue_context_pP->ue_context.mac_MainConfig,
                                          (LTE_MeasGapConfig_t *)NULL,
                                          (LTE_MobilityControlInfo_t *)NULL,
@@ -2655,6 +2653,7 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
   LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
+  int                                    x2_enabled;
   uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
 #ifdef CBA
   //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
@@ -3159,6 +3158,8 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons
     dedicatedInfoNASList = NULL;
   }
 
+  x2_enabled = is_x2ap_enabled();
+
   memset(buffer, 0, RRC_BUF_SIZE);
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
@@ -3171,10 +3172,10 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons
                                          //#ifdef EXMIMO_IOT
                                          //                                         NULL, NULL, NULL,NULL,
                                          //#else
-                                         (LTE_MeasObjectToAddModList_t *)MeasObj_list,
-                                         (LTE_ReportConfigToAddModList_t *)ReportConfig_list,
-                                         (LTE_QuantityConfig_t *)quantityConfig,
-                                         (LTE_MeasIdToAddModList_t *)MeasId_list,
+                                         x2_enabled ? (LTE_MeasObjectToAddModList_t *)MeasObj_list : NULL,
+                                         x2_enabled ? (LTE_ReportConfigToAddModList_t *)ReportConfig_list : NULL,
+                                         x2_enabled ? (LTE_QuantityConfig_t *)quantityConfig : NULL,
+                                         x2_enabled ? (LTE_MeasIdToAddModList_t *)MeasId_list : NULL,
                                          //#endif
                                          (LTE_MAC_MainConfig_t *)mac_MainConfig,
                                          (LTE_MeasGapConfig_t *)NULL,
@@ -3203,7 +3204,7 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons
   }
 
   LOG_I(RRC,
-        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
+        "[eNB %d] Frame %d, Hello there! Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
         ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
   LOG_D(RRC,
         "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
@@ -3285,6 +3286,7 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
   LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
+  int                                    x2_enabled;
   uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
 #ifdef CBA
   //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
@@ -3652,6 +3654,8 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
     dedicatedInfoNASList = NULL;
   }
 
+  x2_enabled = is_x2ap_enabled();
+
   memset(buffer, 0, RRC_BUF_SIZE);
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
@@ -3664,10 +3668,10 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
                                          // #ifdef EXMIMO_IOT
                                          //                                          NULL, NULL, NULL,NULL,
                                          // #else
-                                         (LTE_MeasObjectToAddModList_t *)MeasObj_list,
-                                         (LTE_ReportConfigToAddModList_t *)ReportConfig_list,
-                                         (LTE_QuantityConfig_t *)quantityConfig,
-                                         (LTE_MeasIdToAddModList_t *)MeasId_list,
+                                         x2_enabled ? (LTE_MeasObjectToAddModList_t *)MeasObj_list : NULL,
+                                         x2_enabled ? (LTE_ReportConfigToAddModList_t *)ReportConfig_list : NULL,
+                                         x2_enabled ? (LTE_QuantityConfig_t *)quantityConfig : NULL,
+                                         x2_enabled ? (LTE_MeasIdToAddModList_t *)MeasId_list : NULL,
                                          // #endif
                                          (LTE_MAC_MainConfig_t *)mac_MainConfig,
                                          (LTE_MeasGapConfig_t *)NULL,
@@ -3914,6 +3918,10 @@ rrc_eNB_process_MeasurementReport(
   if (!(measResults2->measId == 4))
     return;
 
+  /* if X2AP is disabled, do nothing */
+  if (!is_x2ap_enabled())
+    return;
+
   LOG_D(RRC, "A3 event is triggered...\n");
 
   /* if the UE is not in handover mode, start handover procedure */
@@ -4126,10 +4134,9 @@ void rrc_eNB_process_handoverCommand(
   ue_context->ue_context.handover_info->size = size;
 }
 
-#if defined(ENABLE_USE_MME)
 void rrc_eNB_handover_ue_context_release(
-protocol_ctxt_t *const ctxt_pP,
-struct rrc_eNB_ue_context_s *ue_context_p) {
+        protocol_ctxt_t *const ctxt_pP,
+        struct rrc_eNB_ue_context_s *ue_context_p) {
   int e_rab = 0;
   //MessageDef *msg_release_p = NULL;
   MessageDef *msg_delete_tunnels_p = NULL;
@@ -4162,7 +4169,16 @@ struct rrc_eNB_ue_context_s *ue_context_p) {
     rrc_eNB_S1AP_remove_ue_ids(RC.rrc[ctxt_pP->module_id], rrc_ue_s1ap_ids);
   }
 }
-#endif /* defined(ENABLE_USE_MME) */
+
+/* This function may be incorrect. */
+void rrc_eNB_handover_cancel(
+        protocol_ctxt_t              *const ctxt_pP,
+        struct rrc_eNB_ue_context_s  *ue_context_p) {
+  int s1_cause = 1;                        /* 1 = tx2relocoverall-expiry */
+
+  rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(ctxt_pP->module_id, ue_context_p,
+      S1AP_CAUSE_RADIO_NETWORK, s1_cause);
+}
 
 void
 check_handovers(
@@ -4293,6 +4309,7 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
   /* for no gcc warnings */
   (void)dedicatedInfoNas;
   LTE_C_RNTI_t                       *cba_RNTI                         = NULL;
+  int                                x2_enabled;
   uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
 #ifdef CBA
   //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
@@ -5049,6 +5066,9 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
   }
 
 #endif
+
+  x2_enabled = is_x2ap_enabled();
+
   memset(buffer, 0, RRC_BUF_SIZE);
   char rrc_buf[1000 /* arbitrary, should be big enough, has to be less than size of return buf by a few bits/bytes */];
   int rrc_size;
@@ -5063,10 +5083,10 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
              //#ifdef EXMIMO_IOT
              //                                         NULL, NULL, NULL,NULL,
              //#else
-             (LTE_MeasObjectToAddModList_t *)MeasObj_list,
-             (LTE_ReportConfigToAddModList_t *)ReportConfig_list,
-             (LTE_QuantityConfig_t *)quantityConfig,
-             (LTE_MeasIdToAddModList_t *)MeasId_list,
+             x2_enabled ? (LTE_MeasObjectToAddModList_t *)MeasObj_list : NULL,
+             x2_enabled ? (LTE_ReportConfigToAddModList_t *)ReportConfig_list : NULL,
+             x2_enabled ? (LTE_QuantityConfig_t *)quantityConfig : NULL,
+             x2_enabled ? (LTE_MeasIdToAddModList_t *)MeasId_list : NULL,
              //#endif
              (LTE_MAC_MainConfig_t *)mac_MainConfig,
              (LTE_MeasGapConfig_t *)NULL,
@@ -5155,7 +5175,7 @@ rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protoc
                            NULL,
                            NULL,
                            NULL
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                            , (LTE_PMCH_InfoList_r9_t *) NULL
 #endif
                            , NULL);
@@ -5163,25 +5183,26 @@ rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protoc
                           ue_context_p->ue_context.SRB_configList,
                           (LTE_DRB_ToAddModList_t *) NULL,
                           (LTE_DRB_ToReleaseList_t *) NULL
-#if defined(Rel10) || defined(Rel14)
+#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                           , (LTE_PMCH_InfoList_r9_t *) NULL
                           , 0, 0
 #endif
                          );
-#if defined(ENABLE_USE_MME)
-  rrc_eNB_process_security (
-    ctxt_pP,
-    ue_context_p,
-    &ue_context_p->ue_context.security_capabilities);
-  process_eNB_security_key (
-    ctxt_pP,
-    ue_context_p,
-    ue_context_p->ue_context.kenb);
-  rrc_pdcp_config_security(
-    ctxt_pP,
-    ue_context_p,
-    FALSE);
-#endif
+
+  if (EPC_MODE_ENABLED) {
+    rrc_eNB_process_security (
+      ctxt_pP,
+      ue_context_p,
+      &ue_context_p->ue_context.security_capabilities);
+    process_eNB_security_key (
+      ctxt_pP,
+      ue_context_p,
+      ue_context_p->ue_context.kenb);
+    rrc_pdcp_config_security(
+      ctxt_pP,
+      ue_context_p,
+      FALSE);
+  }
 
   // Add a new user (called during the HO procedure)
   LOG_I(RRC, "rrc_eNB_target_add_ue_handover module_id %d rnti %d\n", ctxt_pP->module_id, ctxt_pP->rnti);
@@ -5229,890 +5250,108 @@ rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protoc
 #endif
 }
 
-#if 0
-// 5.3.5.4 LTE_RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
 //-----------------------------------------------------------------------------
+/*
+* TODO: * add function description
+*       * format the function correctly
+*/
 void
-rrc_eNB_generate_RRCConnectionReconfiguration_handover(
+rrc_eNB_process_RRCConnectionReconfigurationComplete(
   const protocol_ctxt_t *const ctxt_pP,
-  rrc_eNB_ue_context_t           *const ue_context_pP,
-  uint8_t                *const nas_pdu,
-  const uint32_t                nas_length
+  rrc_eNB_ue_context_t        *ue_context_pP,
+  const uint8_t xid
 )
 //-----------------------------------------------------------------------------
 {
-  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
+  int                                 i, drb_id;
+  int                                 oip_ifup = 0;
+  int                                 dest_ip_offset = 0;
+  uint8_t                            *kRRCenc = NULL;
+  uint8_t                            *kRRCint = NULL;
+  uint8_t                            *kUPenc = NULL;
+  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
+  LTE_DRB_ToAddModList_t                 *DRB_configList = ue_context_pP->ue_context.DRB_configList2[xid];
+  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList2[xid];
+  LTE_DRB_ToReleaseList_t                *DRB_Release_configList2 = ue_context_pP->ue_context.DRB_Release_configList2[xid];
+  LTE_DRB_Identity_t                     *drb_id_p      = NULL;
+  T(T_ENB_RRC_CONNECTION_RECONFIGURATION_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-  uint8_t                             buffer[RRC_BUF_SIZE];
-  int                                 i;
-  uint8_t                             rv[2];
-  uint16_t                            Idx;
-  // configure SRB1/SRB2, PhysicalConfigDedicated, LTE_MAC_MainConfig for UE
-  eNB_RRC_INST                       *rrc_inst = RC.rrc[ctxt_pP->module_id];
-  struct LTE_PhysicalConfigDedicated    **physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
-  struct LTE_SRB_ToAddMod                *SRB2_config;
-  struct LTE_SRB_ToAddMod__rlc_Config    *SRB2_rlc_config;
-  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config;
-  struct LTE_LogicalChannelConfig__ul_SpecificParameters *SRB2_ul_SpecificParameters;
-  LTE_LogicalChannelConfig_t             *SRB1_logicalChannelConfig = NULL;
-  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList;    // not used in this context: may be removed
-  LTE_SRB_ToAddModList_t                 *SRB_configList2;
-  struct LTE_DRB_ToAddMod                *DRB_config;
-  struct LTE_RLC_Config                  *DRB_rlc_config;
-  struct LTE_PDCP_Config                 *DRB_pdcp_config;
-  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM;
-  struct LTE_LogicalChannelConfig        *DRB_lchan_config;
-  struct LTE_LogicalChannelConfig__ul_SpecificParameters *DRB_ul_SpecificParameters;
-  LTE_DRB_ToAddModList_t                 *DRB_configList2;
-  LTE_MAC_MainConfig_t                   *mac_MainConfig;
-  LTE_MeasObjectToAddModList_t           *MeasObj_list;
-  LTE_MeasObjectToAddMod_t               *MeasObj;
-  LTE_ReportConfigToAddModList_t         *ReportConfig_list;
-  LTE_ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
-                                         *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
-  LTE_MeasIdToAddModList_t               *MeasId_list;
-  LTE_MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
-  LTE_QuantityConfig_t                   *quantityConfig;
-  LTE_MobilityControlInfo_t              *mobilityInfo;
-  // HandoverCommand_t handoverCommand;
-  //uint8_t                             sourceModId =
-  //  get_adjacent_cell_mod_id(ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId);
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-  long                               *sr_ProhibitTimer_r9;
-#endif
-  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
-  long                               *maxHARQ_Tx, *periodicBSR_Timer;
-  // LTE_RSRP_Range_t *rsrp;
-  struct LTE_MeasConfig__speedStatePars  *Sparams;
-  LTE_CellsToAddMod_t                    *CellToAdd;
-  LTE_CellsToAddModList_t                *CellsToAddModList;
-  // srb 1: for HO
-  struct LTE_SRB_ToAddMod                *SRB1_config;
-  struct LTE_SRB_ToAddMod__rlc_Config    *SRB1_rlc_config;
-  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config;
-  struct LTE_LogicalChannelConfig__ul_SpecificParameters *SRB1_ul_SpecificParameters;
-  // phy config dedicated
-  LTE_PhysicalConfigDedicated_t          *physicalConfigDedicated2;
-  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList;
-  protocol_ctxt_t                     ctxt;
-  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: get the newSourceUEIdentity (C-RNTI): ",
-        ctxt_pP->module_id, ctxt_pP->frame);
 
-  for (i = 0; i < 2; i++) {
-    rv[i] = taus() & 0xff;
-    LOG_D(RRC, " %x.", rv[i]);
+  /* Derive the keys from kenb */
+  if (DRB_configList != NULL) {
+    derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
+                      ue_context_pP->ue_context.kenb, &kUPenc);
   }
 
-  LOG_D(RRC, "[eNB %d] Frame %d : handover reparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
-        ctxt_pP->module_id, ctxt_pP->frame);
-  // 1st: reconfigure SRB
-  SRB_configList2 = CALLOC(1, sizeof(*SRB_configList));
-  SRB1_config = CALLOC(1, sizeof(*SRB1_config));
-  SRB1_config->srb_Identity = 1;
-  SRB1_rlc_config = CALLOC(1, sizeof(*SRB1_rlc_config));
-  SRB1_config->rlc_Config = SRB1_rlc_config;
-  SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
-  SRB1_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000;
-  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t16;
-  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
-  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10;
-  SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config));
-  SRB1_config->logicalChannelConfig = SRB1_lchan_config;
-  SRB1_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
-  SRB1_ul_SpecificParameters = CALLOC(1, sizeof(*SRB1_ul_SpecificParameters));
-  SRB1_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB1_ul_SpecificParameters;
-  SRB1_ul_SpecificParameters->priority = 1;
-  //assign_enum(&SRB1_ul_SpecificParameters->prioritisedBitRate,LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity);
-  SRB1_ul_SpecificParameters->prioritisedBitRate =
-    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-  //assign_enum(&SRB1_ul_SpecificParameters->bucketSizeDuration,LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50);
-  SRB1_ul_SpecificParameters->bucketSizeDuration =
-    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-  logicalchannelgroup = CALLOC(1, sizeof(long));
-  *logicalchannelgroup = 0;
-  SRB1_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
-  ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB1_config);
-  //2nd: now reconfigure phy config dedicated
-  physicalConfigDedicated2 = CALLOC(1, sizeof(*physicalConfigDedicated2));
-  *physicalConfigDedicated = physicalConfigDedicated2;
-  physicalConfigDedicated2->pdsch_ConfigDedicated =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated));
-  physicalConfigDedicated2->pucch_ConfigDedicated =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated));
-  physicalConfigDedicated2->pusch_ConfigDedicated =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated));
-  physicalConfigDedicated2->uplinkPowerControlDedicated =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
-  physicalConfigDedicated2->cqi_ReportConfig = NULL;  //CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
-  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
-  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
-  physicalConfigDedicated2->schedulingRequestConfig =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
-  // PDSCH
-  //assign_enum(&physicalConfigDedicated2->pdsch_ConfigDedicated->p_a,
-  //          PDSCH_ConfigDedicated__p_a_dB0);
-  physicalConfigDedicated2->pdsch_ConfigDedicated->p_a = LTE_PDSCH_ConfigDedicated__p_a_dB0;
-  // PUCCH
-  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.present =
-    LTE_PUCCH_ConfigDedicated__ackNackRepetition_PR_release;
-  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.choice.release = 0;
-  physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode = NULL;    //PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing;
-  // Pusch_config_dedicated
-  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_ACK_Index = 0;  // 2.00
-  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_RI_Index = 0;   // 1.25
-  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_CQI_Index = 8;  // 2.25
-  // UplinkPowerControlDedicated
-  physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUSCH = 0; // 0 dB
-  //assign_enum(&physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled,
-  // UplinkPowerControlDedicated__deltaMCS_Enabled_en1);
-  physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled =
-    LTE_UplinkPowerControlDedicated__deltaMCS_Enabled_en1;
-  physicalConfigDedicated2->uplinkPowerControlDedicated->accumulationEnabled = 1; // should be TRUE in order to have 0dB power offset
-  physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUCCH = 0; // 0 dB
-  physicalConfigDedicated2->uplinkPowerControlDedicated->pSRS_Offset = 0; // 0 dB
-  physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient =
-    CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient));
-  //  assign_enum(physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient,FilterCoefficient_fc4); // fc4 dB
-  *physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient = LTE_FilterCoefficient_fc4;  // fc4 dB
-  // TPC-PDCCH-Config
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present = LTE_TPC_PDCCH_Config_PR_setup;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = LTE_TPC_Index_PR_indexOfFormat3;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2);
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.size = 2;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[0] = 0x12;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.bits_unused = 0;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->present = LTE_TPC_PDCCH_Config_PR_setup;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.present = LTE_TPC_Index_PR_indexOfFormat3;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2);
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.size = 2;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[0] = 0x22;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
-  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.bits_unused = 0;
-  //AntennaInfoDedicated
-  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
-  physicalConfigDedicated2->antennaInfo->present = LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
-  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present =
-    LTE_AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
-  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0;
-  // SchedulingRequestConfig
-  physicalConfigDedicated2->schedulingRequestConfig->present = LTE_SchedulingRequestConfig_PR_setup;
-  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;
+  derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
+                     ue_context_pP->ue_context.kenb, &kRRCenc);
+  derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
+                     ue_context_pP->ue_context.kenb, &kRRCint);
+  // Refresh SRBs/DRBs
+  MSC_LOG_TX_MESSAGE(
+    MSC_RRC_ENB,
+    MSC_PDCP_ENB,
+    NULL,
+    0,
+    MSC_AS_TIME_FMT" CONFIG_REQ UE %x DRB (security unchanged)",
+    MSC_AS_TIME_ARGS(ctxt_pP),
+    ue_context_pP->ue_context.rnti);
+  rrc_pdcp_config_asn1_req(
+    ctxt_pP,
+    SRB_configList, //NULL,  //LG-RK 14/05/2014 SRB_configList,
+    DRB_configList,
+    //    (LTE_DRB_ToReleaseList_t *) NULL,
+    DRB_Release_configList2,
+    /*RC.rrc[ctxt_pP->module_id]->ciphering_algorithm[ue_mod_idP] |
+             (RC.rrc[ctxt_pP->module_id]->integrity_algorithm[ue_mod_idP] << 4),
+     */
+    0xff, // already configured during the securitymodecommand
+    kRRCenc,
+    kRRCint,
+    kUPenc
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+    , (LTE_PMCH_InfoList_r9_t *) NULL
+#endif
+    ,NULL);
+  // Refresh SRBs/DRBs
+  rrc_rlc_config_asn1_req(
+    ctxt_pP,
+    SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
+    DRB_configList,
+    //    (LTE_DRB_ToReleaseList_t *) NULL
+    DRB_Release_configList2
+#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
+    , (LTE_PMCH_InfoList_r9_t *) NULL
+    , 0, 0
+#endif
+  );
 
-  if (rrc_inst->carrier[0].sib1->tdd_Config==NULL) {  // FD
-    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_context_pP->local_uid %
-        10);   // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
-  } else {
-    switch (rrc_inst->carrier[0].sib1->tdd_Config->subframeAssignment) {
-      case 1:
-        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid & 1) + ((
-              ue_context_pP->local_uid & 3) >> 1) * 5;    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 7 for UE2, 8 for UE3 , 2 for UE4 etc..)
-        break;
+  // set the SRB active in Ue context
+  if (SRB_configList != NULL) {
+    for (i = 0; (i < SRB_configList->list.count) && (i < 3); i++) {
+      if (SRB_configList->list.array[i]->srb_Identity == 1 ) {
+        ue_context_pP->ue_context.Srb1.Active=1;
+      } else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
+        ue_context_pP->ue_context.Srb2.Active=1;
+        ue_context_pP->ue_context.Srb2.Srb_info.Srb_id=2;
+        LOG_I(RRC,"[eNB %d] Frame  %d CC %d : SRB2 is now active\n",
+              ctxt_pP->module_id,
+              ctxt_pP->frame,
+              ue_context_pP->ue_context.primaryCC_id);
+      } else {
+        LOG_W(RRC,"[eNB %d] Frame  %d CC %d : invalide SRB identity %ld\n",
+              ctxt_pP->module_id,
+              ctxt_pP->frame,
+              ue_context_pP->ue_context.primaryCC_id,
+              SRB_configList->list.array[i]->srb_Identity);
+      }
+    }
 
-      case 3:
-        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid %
-            3);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
-        break;
+    free(SRB_configList);
+    ue_context_pP->ue_context.SRB_configList2[xid] = NULL;
+  }
 
-      case 4:
-        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid &
-            1);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
-        break;
-
-      default:
-        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7; // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..)
-        break;
-    }
-  }
-
-  //  assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax,
-  //SchedulingRequestConfig__setup__dsr_TransMax_n4);
-  //  assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax = SchedulingRequestConfig__setup__dsr_TransMax_n4;
-  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax =
-    LTE_SchedulingRequestConfig__setup__dsr_TransMax_n4;
-  LOG_D(RRC,
-        "handover_config [FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 UE %x) --->][MAC_eNB][MOD %02d][]\n",
-        ctxt_pP->frame, ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ctxt_pP->module_id);
-  rrc_mac_config_req_eNB(
-    ctxt_pP->module_id,
-    ue_context_pP->ue_context.primaryCC_id,
-    0,0,0,0,0,
-#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    0,
-#endif
-    ue_context_pP->ue_context.rnti,
-    (LTE_BCCH_BCH_Message_t *) NULL,
-    (LTE_RadioResourceConfigCommonSIB_t *) NULL,
-#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    (LTE_RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-    ue_context_pP->ue_context.physicalConfigDedicated,
-#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-    (LTE_SCellToAddMod_r10_t *)NULL,
-    //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-    (LTE_MeasObjectToAddMod_t **) NULL,
-    ue_context_pP->ue_context.mac_MainConfig,
-    1,
-    SRB1_logicalChannelConfig,
-    ue_context_pP->ue_context.measGapConfig,
-    (LTE_TDD_Config_t *) NULL,
-    (LTE_MobilityControlInfo_t *) NULL,
-    (LTE_SchedulingInfoList_t *) NULL,
-    0,
-    NULL,
-    NULL,
-    (LTE_MBSFN_SubframeConfigList_t *) NULL
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-    , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL
-#endif
-#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-    ,
-    (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
-#endif
-  );
-  // Configure target eNB SRB2
-  /// SRB2
-  SRB2_config = CALLOC(1, sizeof(*SRB2_config));
-  SRB_configList2 = CALLOC(1, sizeof(*SRB_configList2));
-  memset(SRB_configList2, 0, sizeof(*SRB_configList2));
-  SRB2_config->srb_Identity = 2;
-  SRB2_rlc_config = CALLOC(1, sizeof(*SRB2_rlc_config));
-  SRB2_config->rlc_Config = SRB2_rlc_config;
-  SRB2_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
-  SRB2_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000;
-  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t32;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
-  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10;
-  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
-  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
-  SRB2_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
-  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
-  SRB2_ul_SpecificParameters->priority = 1;
-  SRB2_ul_SpecificParameters->prioritisedBitRate =
-    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-  SRB2_ul_SpecificParameters->bucketSizeDuration =
-    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-  // LCG for CCCH and DCCH is 0 as defined in 36331
-  logicalchannelgroup = CALLOC(1, sizeof(long));
-  *logicalchannelgroup = 0;
-  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
-  SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
-  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
-  ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB2_config);
-  // Configure target eNB DRB
-  DRB_configList2 = CALLOC(1, sizeof(*DRB_configList2));
-  /// DRB
-  DRB_config = CALLOC(1, sizeof(*DRB_config));
-  //DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1; //allowed values 1..32
-  // NN: this is the 1st DRB for this ue, so set it to 1
-  DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32
-  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
-  *(DRB_config->logicalChannelIdentity) = (long)3;
-  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
-  DRB_config->rlc_Config = DRB_rlc_config;
-  DRB_rlc_config->present = LTE_RLC_Config_PR_um_Bi_Directional;
-  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
-  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
-  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
-  DRB_config->pdcp_Config = DRB_pdcp_config;
-  DRB_pdcp_config->discardTimer = NULL;
-  DRB_pdcp_config->rlc_AM = NULL;
-  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
-  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
-  PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
-  DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed;
-  DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
-  DRB_config->logicalChannelConfig = DRB_lchan_config;
-  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
-  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
-  DRB_ul_SpecificParameters->priority = 2;    // lower priority than srb1, srb2
-  DRB_ul_SpecificParameters->prioritisedBitRate =
-    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
-  DRB_ul_SpecificParameters->bucketSizeDuration =
-    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
-  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
-  logicalchannelgroup_drb = CALLOC(1, sizeof(long));
-  *logicalchannelgroup_drb = 1;
-  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
-  ASN_SEQUENCE_ADD(&DRB_configList2->list, DRB_config);
-  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
-  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
-  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
-  maxHARQ_Tx = CALLOC(1, sizeof(long));
-  *maxHARQ_Tx = LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
-  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
-  periodicBSR_Timer = CALLOC(1, sizeof(long));
-  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64;
-  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
-  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320;
-  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
-  mac_MainConfig->drx_Config = NULL;
-  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
-  mac_MainConfig->phr_Config->present = LTE_MAC_MainConfig__phr_Config_PR_setup;
-  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
-  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
-  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-  sr_ProhibitTimer_r9 = CALLOC(1, sizeof(long));
-  *sr_ProhibitTimer_r9 = 0;   // SR tx on PUCCH, Value in number of SR period(s). Value 0 = no timer for SR, Value 2= 2*SR
-  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct LTE_MAC_MainConfig__ext1));
-  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
-  //sps_RA_ConfigList_rlola = NULL;
-#endif
-  // Measurement ID list
-  MeasId_list = CALLOC(1, sizeof(*MeasId_list));
-  memset((void *)MeasId_list, 0, sizeof(*MeasId_list));
-  MeasId0 = CALLOC(1, sizeof(*MeasId0));
-  MeasId0->measId = 1;
-  MeasId0->measObjectId = 1;
-  MeasId0->reportConfigId = 1;
-  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId0);
-  MeasId1 = CALLOC(1, sizeof(*MeasId1));
-  MeasId1->measId = 2;
-  MeasId1->measObjectId = 1;
-  MeasId1->reportConfigId = 2;
-  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId1);
-  MeasId2 = CALLOC(1, sizeof(*MeasId2));
-  MeasId2->measId = 3;
-  MeasId2->measObjectId = 1;
-  MeasId2->reportConfigId = 3;
-  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId2);
-  MeasId3 = CALLOC(1, sizeof(*MeasId3));
-  MeasId3->measId = 4;
-  MeasId3->measObjectId = 1;
-  MeasId3->reportConfigId = 4;
-  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId3);
-  MeasId4 = CALLOC(1, sizeof(*MeasId4));
-  MeasId4->measId = 5;
-  MeasId4->measObjectId = 1;
-  MeasId4->reportConfigId = 5;
-  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId4);
-  MeasId5 = CALLOC(1, sizeof(*MeasId5));
-  MeasId5->measId = 6;
-  MeasId5->measObjectId = 1;
-  MeasId5->reportConfigId = 6;
-  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId5);
-  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;
-  // Add one EUTRA Measurement Object
-  MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
-  memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));
-  // Configure MeasObject
-  MeasObj = CALLOC(1, sizeof(*MeasObj));
-  memset((void *)MeasObj, 0, sizeof(*MeasObj));
-  MeasObj->measObjectId = 1;
-  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
-  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090;
-  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw25;
-  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
-  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
-  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
-  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
-  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
-  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB
-  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList =
-    (LTE_CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));
-  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;
-
-  // Add adjacent cell lists (6 per eNB)
-  for (i = 0; i < 6; i++) {
-    CellToAdd = (LTE_CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
-    CellToAdd->cellIndex = i + 1;
-    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
-    CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0;
-    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
-  }
-
-  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
-  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
-  // Report Configurations for periodical, A1-A5 events
-  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));
-  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));
-  ReportConfig_A1 = CALLOC(1, sizeof(*ReportConfig_A1));
-  ReportConfig_A2 = CALLOC(1, sizeof(*ReportConfig_A2));
-  ReportConfig_A3 = CALLOC(1, sizeof(*ReportConfig_A3));
-  ReportConfig_A4 = CALLOC(1, sizeof(*ReportConfig_A4));
-  ReportConfig_A5 = CALLOC(1, sizeof(*ReportConfig_A5));
-  ReportConfig_per->reportConfigId = 1;
-  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
-    LTE_ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
-  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
-  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
-  ReportConfig_A1->reportConfigId = 2;
-  ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    LTE_ReportConfigEUTRA__triggerType_PR_event;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
-  a1_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
-  a1_Threshold.choice.threshold_RSRP = 10;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
-  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
-  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);
-  ReportConfig_A2->reportConfigId = 3;
-  ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    LTE_ReportConfigEUTRA__triggerType_PR_event;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.
-  a2_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.
-  a2_Threshold.choice.threshold_RSRP = 10;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
-  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
-  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);
-  ReportConfig_A3->reportConfigId = 4;
-  ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    LTE_ReportConfigEUTRA__triggerType_PR_event;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset =
-    10;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-  eventA3.reportOnLeave = 1;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
-  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
-  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);
-  ReportConfig_A4->reportConfigId = 5;
-  ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    LTE_ReportConfigEUTRA__triggerType_PR_event;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA4.
-  a4_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA4.
-  a4_Threshold.choice.threshold_RSRP = 10;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
-  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
-  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);
-  ReportConfig_A5->reportConfigId = 6;
-  ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
-    LTE_ReportConfigEUTRA__triggerType_PR_event;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
-    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-  eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-  eventA5.a5_Threshold2.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-  eventA5.a5_Threshold1.choice.threshold_RSRP = 10;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
-  eventA5.a5_Threshold2.choice.threshold_RSRP = 10;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
-  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
-  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);
-  Sparams = CALLOC(1, sizeof(*Sparams));
-  Sparams->present = LTE_MeasConfig__speedStatePars_PR_setup;
-  Sparams->choice.setup.timeToTrigger_SF.sf_High = LTE_SpeedStateScaleFactors__sf_Medium_oDot75;
-  Sparams->choice.setup.timeToTrigger_SF.sf_Medium = LTE_SpeedStateScaleFactors__sf_High_oDot5;
-  Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
-  Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
-  Sparams->choice.setup.mobilityStateParameters.t_Evaluation = LTE_MobilityStateParameters__t_Evaluation_s60;
-  Sparams->choice.setup.mobilityStateParameters.t_HystNormal = LTE_MobilityStateParameters__t_HystNormal_s120;
-  quantityConfig = CALLOC(1, sizeof(*quantityConfig));
-  memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
-  quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA));
-  memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA));
-  quantityConfig->quantityConfigCDMA2000 = NULL;
-  quantityConfig->quantityConfigGERAN = NULL;
-  quantityConfig->quantityConfigUTRA = NULL;
-  quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP =
-    CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP));
-  quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
-    CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ));
-  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4;
-  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4;
-  /* mobilityinfo  */
-  mobilityInfo = CALLOC(1, sizeof(*mobilityInfo));
-  memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo));
-  mobilityInfo->targetPhysCellId =
-    (LTE_PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t];
-  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %ld mod_id: %d ue: %x \n",
-        ctxt_pP->module_id,
-        ctxt_pP->frame,
-        mobilityInfo->targetPhysCellId,
-        ctxt_pP->module_id,
-        ue_context_pP->ue_context.rnti);
-  mobilityInfo->additionalSpectrumEmission = CALLOC(1, sizeof(*mobilityInfo->additionalSpectrumEmission));
-  *mobilityInfo->additionalSpectrumEmission = 1;  //Check this value!
-  mobilityInfo->t304 = LTE_MobilityControlInfo__t304_ms50;    // need to configure an appropriate value here
-  // New UE Identity (C-RNTI) to identify an UE uniquely in a cell
-  mobilityInfo->newUE_Identity.size = 2;
-  mobilityInfo->newUE_Identity.bits_unused = 0;
-  mobilityInfo->newUE_Identity.buf = rv;
-  mobilityInfo->newUE_Identity.buf[0] = rv[0];
-  mobilityInfo->newUE_Identity.buf[1] = rv[1];
-  //memset((void *)&mobilityInfo->radioResourceConfigCommon,(void *)&rrc_inst->sib2->radioResourceConfigCommon,sizeof(RadioResourceConfigCommon_t));
-  //memset((void *)&mobilityInfo->radioResourceConfigCommon,0,sizeof(RadioResourceConfigCommon_t));
-  // Configuring radioResourceConfigCommon
-  mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon =
-    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon));
-  memcpy((void *)mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon,
-         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(LTE_RACH_ConfigCommon_t));
-  mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo =
-    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo));
-  memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
-         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
-         sizeof(LTE_PRACH_ConfigInfo_t));
-  mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex =
-    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
-  mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon =
-    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon));
-  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
-         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(LTE_PDSCH_ConfigCommon_t));
-  memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon,
-         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(LTE_PUSCH_ConfigCommon_t));
-  mobilityInfo->radioResourceConfigCommon.phich_Config = NULL;
-  mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon =
-    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon));
-  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon,
-         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(LTE_PUCCH_ConfigCommon_t));
-  mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon =
-    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon));
-  memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
-         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
-         sizeof(LTE_SoundingRS_UL_ConfigCommon_t));
-  mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon =
-    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon));
-  memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
-         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.uplinkPowerControlCommon,
-         sizeof(LTE_UplinkPowerControlCommon_t));
-  mobilityInfo->radioResourceConfigCommon.antennaInfoCommon = NULL;
-  mobilityInfo->radioResourceConfigCommon.p_Max = NULL;   // CALLOC(1,sizeof(*mobilityInfo->radioResourceConfigCommon.p_Max));
-  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.p_Max,(void *)rrc_inst->sib1->p_Max,sizeof(P_Max_t));
-  mobilityInfo->radioResourceConfigCommon.tdd_Config = NULL;  //CALLOC(1,sizeof(LTE_TDD_Config_t));
-  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.tdd_Config,(void *)rrc_inst->sib1->tdd_Config,sizeof(LTE_TDD_Config_t));
-  mobilityInfo->radioResourceConfigCommon.ul_CyclicPrefixLength =
-    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.ul_CyclicPrefixLength;
-  //End of configuration of radioResourceConfigCommon
-  mobilityInfo->carrierFreq = CALLOC(1, sizeof(*mobilityInfo->carrierFreq));  //CALLOC(1,sizeof(CarrierFreqEUTRA_t)); 36090
-  mobilityInfo->carrierFreq->dl_CarrierFreq = 36090;
-  mobilityInfo->carrierFreq->ul_CarrierFreq = NULL;
-  mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(
-      *mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct LTE_CarrierBandwidthEUTRA));  LTE_AllowedMeasBandwidth_mbw25
-  mobilityInfo->carrierBandwidth->dl_Bandwidth = LTE_CarrierBandwidthEUTRA__dl_Bandwidth_n25;
-  mobilityInfo->carrierBandwidth->ul_Bandwidth = NULL;
-  mobilityInfo->rach_ConfigDedicated = NULL;
-  // store the srb and drb list for ho management, mainly in case of failure
-  memcpy(ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList,
-         (void *)SRB_configList2,
-         sizeof(LTE_SRB_ToAddModList_t));
-  memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList,
-         (void *)DRB_configList2,
-         sizeof(LTE_DRB_ToAddModList_t));
-  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
-  memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
-         (void *)mac_MainConfig,
-         sizeof(LTE_MAC_MainConfig_t));
-  memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
-         (void *)ue_context_pP->ue_context.physicalConfigDedicated,
-         sizeof(LTE_PhysicalConfigDedicated_t));
-  /*    memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,
-     (void *)rrc_inst->sps_Config[ue_mod_idP],
-     sizeof(SPS_Config_t));
-   */
-  LOG_I(RRC, "[eNB %d] Frame %d: adding new UE\n",
-        ctxt_pP->module_id, ctxt_pP->frame);
-  //Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
-  Idx = DCCH;
-  // SRB1
-  ue_context_pP->ue_context.Srb1.Active = 1;
-  ue_context_pP->ue_context.Srb1.Srb_info.Srb_id = Idx;
-  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
-  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
-  // SRB2
-  ue_context_pP->ue_context.Srb2.Active = 1;
-  ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = Idx;
-  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
-  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
-  LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %x\n",
-        ctxt_pP->module_id, Idx, ue_context_pP->ue_context.rnti);
-  //      rrc_pdcp_config_req (enb_mod_idP, frameP, 1, CONFIG_ACTION_ADD, idx, UNDEF_SECURITY_MODE);
-  //      rrc_rlc_config_req(enb_mod_idP,frameP,1,CONFIG_ACTION_ADD,Idx,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
-  rrc_pdcp_config_asn1_req(&ctxt,
-                           ue_context_pP->ue_context.SRB_configList,
-                           (LTE_DRB_ToAddModList_t *) NULL, (LTE_DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                           , (LTE_PMCH_InfoList_r9_t *) NULL
-#endif
-                           ,NULL);
-  rrc_rlc_config_asn1_req(&ctxt,
-                          ue_context_pP->ue_context.SRB_configList,
-                          (LTE_DRB_ToAddModList_t *) NULL, (LTE_DRB_ToReleaseList_t *) NULL
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                          , (LTE_PMCH_InfoList_r9_t *) NULL
-                          , 0, 0
-#endif
-                         );
-  /* Initialize NAS list */
-  dedicatedInfoNASList = NULL;
-  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
-  memset(buffer, 0, RRC_BUF_SIZE);
-  int size=do_RRCConnectionReconfiguration(
-             ctxt_pP,
-             buffer,
-             rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id,
-             SRB_configList2,
-             DRB_configList2,
-             NULL,  // DRB2_list,
-             NULL,    //*sps_Config,
-             ue_context_pP->ue_context.physicalConfigDedicated,
-             MeasObj_list,
-             ReportConfig_list,
-             NULL,    //quantityConfig,
-             MeasId_list,
-             mac_MainConfig,
-             NULL,
-             mobilityInfo,
-             Sparams,
-             NULL,
-             NULL,
-             dedicatedInfoNASList,
-             (LTE_SL_CommConfig_r12_t *)NULL,
-             (LTE_SL_DiscConfig_r12_t *)NULL
-#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-             , NULL   // SCellToAddMod_r10_t
-#endif
-           );
-
-  if (size <= 0)
-    LOG_E(RRC,
-          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration for handover (bytes %d, UE rnti %x) failed\n",
-          ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
-  else
-    LOG_I(RRC,
-          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration for handover (bytes %d, UE rnti %x)\n",
-          ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
-
-  // to be updated if needed
-  /*if (RC.rrc[ctxt_pP->module_id]->SRB1_config[ue_mod_idP]->logicalChannelConfig) {
-     if (RC.rrc[ctxt_pP->module_id]->SRB1_config[ue_mod_idP]->logicalChannelConfig->present == LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
-     SRB1_logicalChannelConfig = &RC.rrc[ctxt_pP->module_id]->SRB1_config[ue_mod_idP]->logicalChannelConfig->choice.explicitValue;
-     }
-     else {
-     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
-     }
-     }
-     else {
-     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
-     }
-   */
-  LOG_D(RRC,
-        "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration_handover to UE %x MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
-        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
-  //rrc_rlc_data_req(ctxt_pP->module_id,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
-  //pdcp_data_req (ctxt_pP->module_id, frameP, 1, (ue_mod_idP * NB_RB_MAX) + DCCH,rrc_eNB_mui++, 0, size, (char *) buffer, 1);
-  rrc_mac_config_req_eNB(
-    ctxt_pP->module_id,
-    ue_context_pP->ue_context.primaryCC_id,
-    0,0,0,0,0,
-#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    0,
-#endif
-    ue_context_pP->ue_context.rnti,
-    (LTE_BCCH_BCH_Message_t *) NULL,
-    (LTE_RadioResourceConfigCommonSIB_t *) NULL,
-#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
-    (LTE_RadioResourceConfigCommonSIB_t *) NULL,
-#endif
-    ue_context_pP->ue_context.physicalConfigDedicated,
-#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
-    (LTE_SCellToAddMod_r10_t *)NULL,
-    //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
-#endif
-    (LTE_MeasObjectToAddMod_t **) NULL,
-    ue_context_pP->ue_context.mac_MainConfig,
-    1,
-    SRB1_logicalChannelConfig,
-    ue_context_pP->ue_context.measGapConfig,
-    (LTE_TDD_Config_t *) NULL,
-    (LTE_MobilityControlInfo_t *) mobilityInfo,
-    (LTE_SecurityConfigHO_t *)NULL,
-    (LTE_SchedulingInfoList_t *) NULL, 0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-    , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL
-#endif
-#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
-    ,
-    (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
-#endif
-  );
-  /*
-     handoverCommand.criticalExtensions.present = HandoverCommand__criticalExtensions_PR_c1;
-     handoverCommand.criticalExtensions.choice.c1.present = HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8;
-     handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.buf = buffer;
-     handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.size = size;
-   */
-  //#warning "COMPILATION PROBLEM"
-#ifdef PROBLEM_COMPILATION_RESOLVED
-
-  if (sourceModId != 0xFF) {
-    memcpy(RC.rrc[sourceModId].handover_info[RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s]->buf,
-           (void *)buffer, size);
-    RC.rrc[sourceModId].handover_info[RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s]->size = size;
-    RC.rrc[sourceModId].handover_info[RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s]->ho_complete =
-      0xF1;
-    //RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ho_complete = 0xFF;
-    LOG_D(RRC, "[eNB %d] Frame %d: setting handover complete to 0xF1 for (%d,%d) and to 0xFF for (%d,%d)\n",
-          ctxt_pP->module_id,
-          ctxt_pP->frame,
-          sourceModId,
-          RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s,
-          ctxt_pP->module_id,
-          ue_mod_idP);
-  } else
-    LOG_W(RRC,
-          "[eNB %d] Frame %d: rrc_eNB_generate_RRCConnectionReconfiguration_handover: Could not find source eNB mod_id.\n",
-          ctxt_pP->module_id, ctxt_pP->frame);
-
-#endif
-}
-#endif
-
-
-//-----------------------------------------------------------------------------
-/*
-* TODO: * add function description
-*       * format the function correctly
-*/
-void
-rrc_eNB_process_RRCConnectionReconfigurationComplete(
-  const protocol_ctxt_t *const ctxt_pP,
-  rrc_eNB_ue_context_t        *ue_context_pP,
-  const uint8_t xid
-)
-//-----------------------------------------------------------------------------
-{
-  int                                 i, drb_id;
-  int                                 oip_ifup = 0;
-  int                                 dest_ip_offset = 0;
-  uint8_t                            *kRRCenc = NULL;
-  uint8_t                            *kRRCint = NULL;
-  uint8_t                            *kUPenc = NULL;
-  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
-  LTE_DRB_ToAddModList_t                 *DRB_configList = ue_context_pP->ue_context.DRB_configList2[xid];
-  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList2[xid];
-  LTE_DRB_ToReleaseList_t                *DRB_Release_configList2 = ue_context_pP->ue_context.DRB_Release_configList2[xid];
-  LTE_DRB_Identity_t                     *drb_id_p      = NULL;
-  T(T_ENB_RRC_CONNECTION_RECONFIGURATION_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
-    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-
-  /* Derive the keys from kenb */
-  if (DRB_configList != NULL) {
-    derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
-                      ue_context_pP->ue_context.kenb, &kUPenc);
-  }
-
-  derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
-                     ue_context_pP->ue_context.kenb, &kRRCenc);
-  derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
-                     ue_context_pP->ue_context.kenb, &kRRCint);
-  // Refresh SRBs/DRBs
-  MSC_LOG_TX_MESSAGE(
-    MSC_RRC_ENB,
-    MSC_PDCP_ENB,
-    NULL,
-    0,
-    MSC_AS_TIME_FMT" CONFIG_REQ UE %x DRB (security unchanged)",
-    MSC_AS_TIME_ARGS(ctxt_pP),
-    ue_context_pP->ue_context.rnti);
-  rrc_pdcp_config_asn1_req(
-    ctxt_pP,
-    SRB_configList, //NULL,  //LG-RK 14/05/2014 SRB_configList,
-    DRB_configList,
-    //    (LTE_DRB_ToReleaseList_t *) NULL,
-    DRB_Release_configList2,
-    /*RC.rrc[ctxt_pP->module_id]->ciphering_algorithm[ue_mod_idP] |
-             (RC.rrc[ctxt_pP->module_id]->integrity_algorithm[ue_mod_idP] << 4),
-     */
-    0xff, // already configured during the securitymodecommand
-    kRRCenc,
-    kRRCint,
-    kUPenc
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-    , (LTE_PMCH_InfoList_r9_t *) NULL
-#endif
-    ,NULL);
-  // Refresh SRBs/DRBs
-  rrc_rlc_config_asn1_req(
-    ctxt_pP,
-    SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
-    DRB_configList,
-    //    (LTE_DRB_ToReleaseList_t *) NULL
-    DRB_Release_configList2
-#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-    , (LTE_PMCH_InfoList_r9_t *) NULL
-    , 0, 0
-#endif
-  );
-
-  // set the SRB active in Ue context
-  if (SRB_configList != NULL) {
-    for (i = 0; (i < SRB_configList->list.count) && (i < 3); i++) {
-      if (SRB_configList->list.array[i]->srb_Identity == 1 ) {
-        ue_context_pP->ue_context.Srb1.Active=1;
-      } else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
-        ue_context_pP->ue_context.Srb2.Active=1;
-        ue_context_pP->ue_context.Srb2.Srb_info.Srb_id=2;
-        LOG_I(RRC,"[eNB %d] Frame  %d CC %d : SRB2 is now active\n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame,
-              ue_context_pP->ue_context.primaryCC_id);
-      } else {
-        LOG_W(RRC,"[eNB %d] Frame  %d CC %d : invalide SRB identity %ld\n",
-              ctxt_pP->module_id,
-              ctxt_pP->frame,
-              ue_context_pP->ue_context.primaryCC_id,
-              SRB_configList->list.array[i]->srb_Identity);
-      }
-    }
-
-    free(SRB_configList);
-    ue_context_pP->ue_context.SRB_configList2[xid] = NULL;
-  }
-
-  // Loop through DRBs and establish if necessary
+  // Loop through DRBs and establish if necessary
 
   if (DRB_configList != NULL) {
     for (i = 0; i < DRB_configList->list.count; i++) {  // num max DRB (11-3-8)
@@ -6332,43 +5571,44 @@ void rrc_eNB_generate_RRCConnectionSetup(const protocol_ctxt_t *const ctxt_pP,
   {
     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
       do_RRCConnectionSetup(ctxt_pP,
-                            ue_context_pP,
-                            CC_id,
-                            (uint8_t *) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload,
-                            (uint8_t) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB, //at this point we do not have the UE capability information, so it can only be TM1 or TM2
-                            rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
-                            SRB_configList,
-                            &ue_context_pP->ue_context.physicalConfigDedicated);
-    LOG_DUMPMSG(RRC,DEBUG_RRC,
-                (char *)(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload),
-                RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
-                "[MSG] RRC Connection Setup\n");
-
+			    ue_context_pP,
+			    CC_id,
+			    (uint8_t *) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload,
+			    (uint8_t) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB, //at this point we do not have the UE capability information, so it can only be TM1 or TM2
+			    rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
+			    SRB_configList,
+			    &ue_context_pP->ue_context.physicalConfigDedicated);
+  }
+  LOG_DUMPMSG(RRC,DEBUG_RRC,
+	(char *)(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload),
+	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+	"[MSG] RRC Connection Setup\n");
+    
     // configure SRB1/SRB2, PhysicalConfigDedicated, LTE_MAC_MainConfig for UE
-
-    if (*SRB_configList != NULL) {
-      for (cnt = 0; cnt < (*SRB_configList)->list.count; cnt++) {
-        if ((*SRB_configList)->list.array[cnt]->srb_Identity == 1) {
+    
+  if (*SRB_configList != NULL) {
+    for (cnt = 0; cnt < (*SRB_configList)->list.count; cnt++) {
+      if ((*SRB_configList)->list.array[cnt]->srb_Identity == 1) {
           SRB1_config = (*SRB_configList)->list.array[cnt];
-
-          if (SRB1_config->logicalChannelConfig) {
-            if (SRB1_config->logicalChannelConfig->present ==
-                LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
-              SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
-            } else {
-              SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
-            }
-          } else {
-            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
-          }
-
-          LOG_D(RRC,
-                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
-                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-          rrc_mac_config_req_eNB(
-            ctxt_pP->module_id,
-            ue_context_pP->ue_context.primaryCC_id,
-            0,0,0,0,0,
+	  
+	  if (SRB1_config->logicalChannelConfig) {
+	    if (SRB1_config->logicalChannelConfig->present ==
+		LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+	      SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
+	    } else {
+	      SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
+	    }
+	  } else {
+	    SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
+	  }
+	  
+	  LOG_D(RRC,
+		PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
+		PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+	  rrc_mac_config_req_eNB(
+				 ctxt_pP->module_id,
+				 ue_context_pP->ue_context.primaryCC_id,
+				 0,0,0,0,0,
 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
             0,
 #endif
@@ -6403,8 +5643,7 @@ void rrc_eNB_generate_RRCConnectionSetup(const protocol_ctxt_t *const ctxt_pP,
           break;
         }
       }
-    }
-
+    
     MSC_LOG_TX_MESSAGE(
       MSC_RRC_ENB,
       MSC_RRC_UE,
@@ -7579,13 +6818,9 @@ rrc_eNB_decode_dcch(
         }
 
         if (EPC_MODE_ENABLED) {
-          if (EPC_MODE_ENABLED == 1) {
-#if defined(ENABLE_USE_MME)
-            rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(ctxt_pP,
-                                                  ue_context_p,
-                                                  ul_dcch_msg);
-#endif
-          }
+          rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(ctxt_pP,
+                                                ue_context_p,
+                                                ul_dcch_msg);
         } else {
           ue_context_p->ue_context.nb_of_e_rabs = 1;
 
@@ -7632,11 +6867,9 @@ rrc_eNB_decode_dcch(
           sdu_sizeP);
 
         if (EPC_MODE_ENABLED == 1) {
-#if defined(ENABLE_USE_MME)
           rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
                                        ue_context_p,
                                        ul_dcch_msg);
-#endif
         }
 
         break;
@@ -7784,8 +7017,18 @@ void rrc_subframe_process(protocol_ctxt_t *const ctxt_pP, const int CC_id)
   double estimated_distance = 0;
   protocol_ctxt_t ctxt;
 #endif
+  MessageDef *msg;
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX, VCD_FUNCTION_IN);
-  check_handovers(ctxt_pP); // counter, get the value and aggregate
+
+  if (is_x2ap_enabled()) {
+    /* send a tick to x2ap */
+    msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_SUBFRAME_PROCESS);
+    itti_send_msg_to_task(TASK_X2AP, ctxt_pP->module_id, msg);
+
+    check_handovers(ctxt_pP); // counter, get the value and aggregate
+  }
+
   // check for UL failure or for UE to be released
   RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
     ctxt_pP->rnti = ue_context_p->ue_id_rnti;
@@ -7845,15 +7088,21 @@ void rrc_subframe_process(protocol_ctxt_t *const ctxt_pP, const int CC_id)
       }
     }
 
-#if defined(ENABLE_USE_MME)
     if (ue_context_p->ue_context.handover_info != NULL) {
       if (ue_context_p->ue_context.handover_info->state == HO_RELEASE) {
         ue_to_be_removed = ue_context_p;
         rrc_eNB_handover_ue_context_release(ctxt_pP, ue_context_p);
         break; //break RB_FOREACH (why to break ?)
       }
+      if (ue_context_p->ue_context.handover_info->state == HO_CANCEL) {
+        rrc_eNB_handover_cancel(ctxt_pP, ue_context_p);
+        /* freeing handover_info and setting it to NULL to let
+         * RRC wait for MME to later on release the UE
+         */
+        free(ue_context_p->ue_context.handover_info);
+        ue_context_p->ue_context.handover_info = NULL;
+      }
     }
-#endif
 
     pthread_mutex_lock(&rrc_release_freelist);
 
@@ -8083,7 +7332,7 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
                                     RRC_DCCH_DATA_IND(msg_p).rnti,
                                     msg_p->ittiMsgHeader.lte_time.frame,
                                     msg_p->ittiMsgHeader.lte_time.slot);
-      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received on DCCH %d %s\n",
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received on DCCH %d %s\n",
             PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
             RRC_DCCH_DATA_IND(msg_p).dcch_index,
             msg_name_p);
@@ -8145,7 +7394,9 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
 
       if (ue != NULL
           && ue->ue_context.ue_release_timer_rrc > 0
-          && (ue->ue_context.handover_info == NULL || ue->ue_context.handover_info->state != HO_RELEASE)) {
+          && (ue->ue_context.handover_info == NULL ||
+              (ue->ue_context.handover_info->state != HO_RELEASE &&
+               ue->ue_context.handover_info->state != HO_CANCEL))) {
         ue->ue_context.ue_release_timer_rrc = ue->ue_context.ue_release_timer_thres_rrc;
       }
 
@@ -8193,6 +7444,51 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
       break;
     }
 
+   case X2AP_HANDOVER_CANCEL: {
+      struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
+      char *cause;
+      switch (X2AP_HANDOVER_CANCEL(msg_p).cause) {
+      case X2AP_T_RELOC_PREP_TIMEOUT:
+        cause = "T_RelocPrep timeout";
+        break;
+      case X2AP_TX2_RELOC_OVERALL_TIMEOUT:
+        cause = "Tx2_RelocOverall timeout";
+        break;
+      default:
+        /* cannot come here */
+        exit(1);
+      }
+      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], X2AP_HANDOVER_CANCEL(msg_p).rnti);
+      if (ue_context_p != NULL &&
+          ue_context_p->ue_context.handover_info != NULL) {
+        LOG_I(RRC, "[eNB %d] eNB receives X2 HANDOVER CANCEL for rnti %x, cause %s [%s]\n",
+              instance,
+              X2AP_HANDOVER_CANCEL(msg_p).rnti,
+              cause,
+              msg_name_p);
+        if (X2AP_HANDOVER_CANCEL(msg_p).cause == X2AP_T_RELOC_PREP_TIMEOUT) {
+          /* for prep timeout, simply return to normal state */
+          /* TODO: be sure that it's correct to set Status to RRC_RECONFIGURED */
+          ue_context_p->ue_context.Status = RRC_RECONFIGURED;
+          /* TODO: be sure free is enough here (check memory leaks) */
+          free(ue_context_p->ue_context.handover_info);
+          ue_context_p->ue_context.handover_info = NULL;
+        } else {
+          /* for overall timeout, remove UE entirely */
+          ue_context_p->ue_context.handover_info->state = HO_CANCEL;
+        }
+      } else {
+        char *failure_cause;
+        if (ue_context_p == NULL)
+          failure_cause = "no UE found";
+        else
+          failure_cause = "UE not in handover";
+        LOG_W(RRC, "[eNB %d] cannot process (%s) X2 HANDOVER CANCEL for rnti %x, cause %s, ignoring\n",
+              instance, failure_cause, X2AP_HANDOVER_CANCEL(msg_p).rnti, cause);
+      }
+      break;
+    }
+
     /* Messages from eNB app */
     case RRC_CONFIGURATION_REQ:
       LOG_I(RRC, "[eNB %d] Received %s : %p\n", instance, msg_name_p,&RRC_CONFIGURATION_REQ(msg_p));
diff --git a/openair2/X2AP/x2ap_eNB.c b/openair2/X2AP/x2ap_eNB.c
index c05495a0c414c79bb5ee1bcf20da02065c9682f8..8b11e469b2d03f1e86b74c8a94bf55778ab9a1d6 100644
--- a/openair2/X2AP/x2ap_eNB.c
+++ b/openair2/X2AP/x2ap_eNB.c
@@ -41,6 +41,7 @@
 #include "x2ap_eNB_generate_messages.h"
 #include "x2ap_common.h"
 #include "x2ap_ids.h"
+#include "x2ap_timers.h"
 
 #include "queue.h"
 #include "assertions.h"
@@ -301,6 +302,9 @@ void x2ap_eNB_handle_register_eNB(instance_t instance,
     new_instance->num_cc           = x2ap_register_eNB->num_cc;
 
     x2ap_id_manager_init(&new_instance->id_manager);
+    x2ap_timers_init(&new_instance->timers,
+                     x2ap_register_eNB->t_reloc_prep,
+                     x2ap_register_eNB->tx2_reloc_overall);
 
     for (int i = 0; i< x2ap_register_eNB->num_cc; i++) {
       new_instance->eutra_band[i]              = x2ap_register_eNB->eutra_band[i];
@@ -402,6 +406,10 @@ void x2ap_eNB_handle_handover_req(instance_t instance,
   }
   /* id_source is ue_id, id_target is unknown yet */
   x2ap_set_ids(id_manager, ue_id, x2ap_handover_req->rnti, ue_id, -1);
+  x2ap_id_set_state(id_manager, ue_id, X2ID_STATE_SOURCE_PREPARE);
+  x2ap_set_reloc_prep_timer(id_manager, ue_id,
+                            x2ap_timer_get_tti(&instance_p->timers));
+  x2ap_id_set_target(id_manager, ue_id, target);
 
   x2ap_eNB_generate_x2_handover_request(instance_p, target, x2ap_handover_req, ue_id);
 }
@@ -480,6 +488,10 @@ void *x2ap_task(void *arg) {
         itti_exit_task();
         break;
 
+      case X2AP_SUBFRAME_PROCESS:
+        x2ap_check_timers(ITTI_MESSAGE_GET_INSTANCE(received_msg));
+        break;
+
       case X2AP_REGISTER_ENB_REQ:
         x2ap_eNB_handle_register_eNB(ITTI_MESSAGE_GET_INSTANCE(received_msg),
                                      &X2AP_REGISTER_ENB_REQ(received_msg));
@@ -534,4 +546,38 @@ void *x2ap_task(void *arg) {
   return NULL;
 }
 
+#include "common/config/config_userapi.h"
+
+int is_x2ap_enabled(void)
+{
+  static volatile int config_loaded = 0;
+  static volatile int enabled = 0;
+  static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+  if (pthread_mutex_lock(&mutex)) goto mutex_error;
+
+  if (config_loaded) {
+    if (pthread_mutex_unlock(&mutex)) goto mutex_error;
+    return enabled;
+  }
 
+  char *enable_x2 = NULL;
+  paramdef_t p[] = {
+   { "enable_x2", "yes/no", 0, strptr:&enable_x2, defstrval:"", TYPE_STRING, 0 }
+  };
+
+  /* TODO: do it per module - we check only first eNB */
+  config_get(p, sizeof(p)/sizeof(paramdef_t), "eNBs.[0]");
+  if (enable_x2 != NULL && strcmp(enable_x2, "yes") == 0)
+    enabled = 1;
+
+  config_loaded = 1;
+
+  if (pthread_mutex_unlock(&mutex)) goto mutex_error;
+
+  return enabled;
+
+mutex_error:
+  LOG_E(X2AP, "mutex error\n");
+  exit(1);
+}
diff --git a/openair2/X2AP/x2ap_eNB.h b/openair2/X2AP/x2ap_eNB.h
index 5433a890883c94d750594fd4a99e848ef449c343..afa6f11b8e0a9839c98eecf728551766b022440c 100644
--- a/openair2/X2AP/x2ap_eNB.h
+++ b/openair2/X2AP/x2ap_eNB.h
@@ -46,6 +46,8 @@ int x2ap_eNB_init_sctp (x2ap_eNB_instance_t *instance_p,
 
 void *x2ap_task(void *arg);
 
+int is_x2ap_enabled(void);
+
 #endif /* X2AP_H_ */
 
 /**
diff --git a/openair2/X2AP/x2ap_eNB_decoder.c b/openair2/X2AP/x2ap_eNB_decoder.c
index a5b19fe2ccac109bd10256de1be489cb494ca75f..3604aa03c8a75420b4638dd70967ddba52745e00 100644
--- a/openair2/X2AP/x2ap_eNB_decoder.c
+++ b/openair2/X2AP/x2ap_eNB_decoder.c
@@ -48,11 +48,17 @@ static int x2ap_eNB_decode_initiating_message(X2AP_X2AP_PDU_t *pdu)
       //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
       X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
       break;
+
     case X2AP_ProcedureCode_id_uEContextRelease:
       //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
       X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
       break;
 
+    case X2AP_ProcedureCode_id_handoverCancel:
+      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
+      X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
+      break;
+
     default:
       X2AP_ERROR("Unknown procedure ID (%d) for initiating message\n",
                   (int)pdu->choice.initiatingMessage.procedureCode);
diff --git a/openair2/X2AP/x2ap_eNB_defs.h b/openair2/X2AP/x2ap_eNB_defs.h
index 3356a101b4e632927cc72d9397f850d1a75885ca..cd6a7e1385690884b1565001ce53f7fb8de397a9 100644
--- a/openair2/X2AP/x2ap_eNB_defs.h
+++ b/openair2/X2AP/x2ap_eNB_defs.h
@@ -34,6 +34,7 @@
 #include "sctp_eNB_defs.h"
 
 #include "x2ap_ids.h"
+#include "x2ap_timers.h"
 
 #ifndef X2AP_ENB_DEFS_H_
 #define X2AP_ENB_DEFS_H_
@@ -63,7 +64,6 @@ typedef enum {
   X2AP_ENB_STATE_MAX,
 } x2ap_eNB_state_t;
 
-
 /* Served PLMN identity element */
 struct plmn_identity_s {
   uint16_t mcc;
@@ -184,6 +184,7 @@ typedef struct x2ap_eNB_instance_s {
   int              multi_sd;
 
   x2ap_id_manager  id_manager;
+  x2ap_timers_t    timers;
 } x2ap_eNB_instance_t;
 
 typedef struct {
diff --git a/openair2/X2AP/x2ap_eNB_generate_messages.c b/openair2/X2AP/x2ap_eNB_generate_messages.c
index c13469d5d4bfc209c523c6b063620a4e6d5c8067..53ec8574fd80e4305fc5e6744d5b8b7748d8f459 100644
--- a/openair2/X2AP/x2ap_eNB_generate_messages.c
+++ b/openair2/X2AP/x2ap_eNB_generate_messages.c
@@ -718,3 +718,87 @@ int x2ap_eNB_generate_x2_ue_context_release (x2ap_eNB_instance_t *instance_p, x2
 
   return ret;
 }
+
+int x2ap_eNB_generate_x2_handover_cancel (x2ap_eNB_instance_t *instance_p, x2ap_eNB_data_t *x2ap_eNB_data_p,
+                                          int x2_ue_id,
+                                          x2ap_handover_cancel_cause_t cause)
+{
+  X2AP_X2AP_PDU_t              pdu;
+  X2AP_HandoverCancel_t        *out;
+  X2AP_HandoverCancel_IEs_t    *ie;
+  int                          ue_id;
+  int                          id_source;
+  int                          id_target;
+
+  uint8_t  *buffer;
+  uint32_t  len;
+  int       ret = 0;
+
+  DevAssert(instance_p != NULL);
+  DevAssert(x2ap_eNB_data_p != NULL);
+
+  ue_id = x2_ue_id;
+  id_source = ue_id;
+  id_target = x2ap_id_get_id_target(&instance_p->id_manager, ue_id);
+
+  /* Prepare the X2AP handover cancel message to encode */
+  memset(&pdu, 0, sizeof(pdu));
+  pdu.present = X2AP_X2AP_PDU_PR_initiatingMessage;
+  pdu.choice.initiatingMessage.procedureCode = X2AP_ProcedureCode_id_handoverCancel;
+  pdu.choice.initiatingMessage.criticality = X2AP_Criticality_ignore;
+  pdu.choice.initiatingMessage.value.present = X2AP_InitiatingMessage__value_PR_HandoverCancel;
+  out = &pdu.choice.initiatingMessage.value.choice.HandoverCancel;
+
+  /* mandatory */
+  ie = (X2AP_HandoverCancel_IEs_t *)calloc(1, sizeof(X2AP_HandoverCancel_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID;
+  ie->criticality = X2AP_Criticality_reject;
+  ie->value.present = X2AP_HandoverCancel_IEs__value_PR_UE_X2AP_ID;
+  ie->value.choice.UE_X2AP_ID = id_source;
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  /* optional */
+  if (id_target != -1) {
+    ie = (X2AP_HandoverCancel_IEs_t *)calloc(1, sizeof(X2AP_HandoverCancel_IEs_t));
+    ie->id = X2AP_ProtocolIE_ID_id_New_eNB_UE_X2AP_ID;
+    ie->criticality = X2AP_Criticality_ignore;
+    ie->value.present = X2AP_HandoverCancel_IEs__value_PR_UE_X2AP_ID_1;
+    ie->value.choice.UE_X2AP_ID_1 = id_target;
+    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  }
+
+  /* mandatory */
+  ie = (X2AP_HandoverCancel_IEs_t *)calloc(1, sizeof(X2AP_HandoverCancel_IEs_t));
+  ie->id = X2AP_ProtocolIE_ID_id_Cause;
+  ie->criticality = X2AP_Criticality_ignore;
+  ie->value.present = X2AP_HandoverCancel_IEs__value_PR_Cause;
+  switch (cause) {
+  case X2AP_T_RELOC_PREP_TIMEOUT:
+    ie->value.choice.Cause.present = X2AP_Cause_PR_radioNetwork;
+    ie->value.choice.Cause.choice.radioNetwork =
+      X2AP_CauseRadioNetwork_trelocprep_expiry;
+    break;
+  case X2AP_TX2_RELOC_OVERALL_TIMEOUT:
+    ie->value.choice.Cause.present = X2AP_Cause_PR_radioNetwork;
+    ie->value.choice.Cause.choice.radioNetwork =
+      X2AP_CauseRadioNetwork_tx2relocoverall_expiry;
+    break;
+  default:
+    /* we can't come here */
+    X2AP_ERROR("unhandled cancel cause\n");
+    exit(1);
+  }
+  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+
+  if (x2ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) {
+    X2AP_ERROR("Failed to encode X2 Handover Cancel\n");
+    abort();
+    return -1;
+  }
+
+  MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2HandoverCancel/initiatingMessage assoc_id %u", x2ap_eNB_data_p->assoc_id);
+
+  x2ap_eNB_itti_send_sctp_data_req(instance_p->instance, x2ap_eNB_data_p->assoc_id, buffer, len, 1);
+
+  return ret;
+}
diff --git a/openair2/X2AP/x2ap_eNB_generate_messages.h b/openair2/X2AP/x2ap_eNB_generate_messages.h
index 059d213277599a465876f3ebfb4c6b5fba242ce2..659966fff68810fe327915b0e4e7ec93d9601a45 100644
--- a/openair2/X2AP/x2ap_eNB_generate_messages.h
+++ b/openair2/X2AP/x2ap_eNB_generate_messages.h
@@ -55,5 +55,10 @@ int x2ap_eNB_generate_x2_handover_request_ack (x2ap_eNB_instance_t *instance_p,
 
 int x2ap_eNB_generate_x2_ue_context_release (x2ap_eNB_instance_t *instance_p, x2ap_eNB_data_t *x2ap_eNB_data_p,
                                              x2ap_ue_context_release_t *x2ap_ue_context_release);
+
+int x2ap_eNB_generate_x2_handover_cancel (x2ap_eNB_instance_t *instance_p, x2ap_eNB_data_t *x2ap_eNB_data_p,
+                                          int x2_ue_id,
+                                          x2ap_handover_cancel_cause_t cause);
+
 #endif /*  X2AP_ENB_GENERATE_MESSAGES_H_ */
 
diff --git a/openair2/X2AP/x2ap_eNB_handler.c b/openair2/X2AP/x2ap_eNB_handler.c
index 9da92787416a1a24f5453ad9b07541b2737c3670..96ffac162ebc2e62c8d249a7b2c72b9d40e7d2eb 100644
--- a/openair2/X2AP/x2ap_eNB_handler.c
+++ b/openair2/X2AP/x2ap_eNB_handler.c
@@ -78,10 +78,16 @@ int x2ap_eNB_handle_ue_context_release (instance_t instance,
                                         uint32_t stream,
                                         X2AP_X2AP_PDU_t *pdu);
 
+static
+int x2ap_eNB_handle_handover_cancel (instance_t instance,
+                                     uint32_t assoc_id,
+                                     uint32_t stream,
+                                     X2AP_X2AP_PDU_t *pdu);
+
 /* Handlers matrix. Only eNB related procedure present here */
 x2ap_message_decoded_callback x2ap_messages_callback[][3] = {
   { x2ap_eNB_handle_handover_preparation, x2ap_eNB_handle_handover_response, 0 }, /* handoverPreparation */
-  { 0, 0, 0 }, /* handoverCancel */
+  { x2ap_eNB_handle_handover_cancel, 0, 0 }, /* handoverCancel */
   { 0, 0, 0 }, /* loadIndication */
   { 0, 0, 0 }, /* errorIndication */
   { 0, 0, 0 }, /* snStatusTransfer */
@@ -631,6 +637,7 @@ int x2ap_eNB_handle_handover_preparation (instance_t instance,
   }
   /* rnti is unknown yet, must not be set to -1, 0 is fine */
   x2ap_set_ids(&instance_p->id_manager, ue_id, 0, ie->value.choice.UE_X2AP_ID, ue_id);
+  x2ap_id_set_state(&instance_p->id_manager, ue_id, X2ID_STATE_TARGET);
 
   X2AP_HANDOVER_REQ(msg).x2_id = ue_id;
 
@@ -775,15 +782,19 @@ int x2ap_eNB_handle_handover_response (instance_t instance,
 
   ue_id = id_source;
 
-  if (id_source != x2ap_id_get_id_source(&instance_p->id_manager, ue_id)) {
-    X2AP_ERROR("incorrect X2AP IDs for UE (old ID %d new ID %d)\n", id_source, id_target);
-    exit(1);
+  if (ue_id != x2ap_find_id_from_id_source(&instance_p->id_manager, id_source)) {
+    X2AP_WARN("incorrect/unknown X2AP IDs for UE (old ID %d new ID %d), ignoring handover response\n",
+              id_source, id_target);
+    return 0;
   }
 
   rnti = x2ap_id_get_rnti(&instance_p->id_manager, ue_id);
 
   /* id_target is a new information, store it */
   x2ap_set_ids(&instance_p->id_manager, ue_id, rnti, id_source, id_target);
+  x2ap_id_set_state(&instance_p->id_manager, ue_id, X2ID_STATE_SOURCE_OVERALL);
+  x2ap_set_reloc_overall_timer(&instance_p->id_manager, ue_id,
+                               x2ap_timer_get_tti(&instance_p->timers));
 
   X2AP_HANDOVER_REQ_ACK(msg).rnti = rnti;
 
@@ -859,13 +870,19 @@ int x2ap_eNB_handle_ue_context_release (instance_t instance,
   id_target = ie->value.choice.UE_X2AP_ID_1;
 
   ue_id = id_source;
+  if (ue_id != x2ap_find_id_from_id_source(&instance_p->id_manager, id_source)) {
+    X2AP_WARN("incorrect/unknown X2AP IDs for UE (old ID %d new ID %d), ignoring UE context release\n",
+              id_source, id_target);
+    return 0;
+  }
 
   if (id_target != x2ap_id_get_id_target(&instance_p->id_manager, ue_id)) {
-    X2AP_ERROR("UE context release: bad id_target for UE %x (id_source %d) expected %d got %d\n",
+    X2AP_ERROR("UE context release: bad id_target for UE %x (id_source %d) expected %d got %d, ignoring message\n",
                x2ap_id_get_rnti(&instance_p->id_manager, ue_id),
                id_source,
                x2ap_id_get_id_target(&instance_p->id_manager, ue_id),
                id_target);
+    return 0;
   }
 
   X2AP_UE_CONTEXT_RELEASE(msg).rnti = x2ap_id_get_rnti(&instance_p->id_manager, ue_id);
@@ -876,3 +893,111 @@ int x2ap_eNB_handle_ue_context_release (instance_t instance,
 
   return 0;
 }
+
+static
+int x2ap_eNB_handle_handover_cancel (instance_t instance,
+                                     uint32_t assoc_id,
+                                     uint32_t stream,
+                                     X2AP_X2AP_PDU_t *pdu)
+{
+  X2AP_HandoverCancel_t             *x2HandoverCancel;
+  X2AP_HandoverCancel_IEs_t         *ie;
+
+  x2ap_eNB_instance_t               *instance_p;
+  x2ap_eNB_data_t                   *x2ap_eNB_data;
+  MessageDef                        *msg;
+  int                               ue_id;
+  int                               id_source;
+  int                               id_target;
+  x2ap_handover_cancel_cause_t      cause;
+
+  DevAssert (pdu != NULL);
+  x2HandoverCancel = &pdu->choice.initiatingMessage.value.choice.HandoverCancel;
+
+  if (stream == 0) {
+    X2AP_ERROR ("Received new x2 handover cancel on stream == 0\n");
+    return 0;
+  }
+
+  X2AP_DEBUG ("Received a new X2 handover cancel\n");
+
+  x2ap_eNB_data = x2ap_get_eNB(NULL, assoc_id, 0);
+  DevAssert(x2ap_eNB_data != NULL);
+
+  instance_p = x2ap_eNB_get_instance(instance);
+  DevAssert(instance_p != NULL);
+
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverCancel_IEs_t, ie, x2HandoverCancel,
+                             X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID, true);
+
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  }
+
+  id_source = ie->value.choice.UE_X2AP_ID;
+
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverCancel_IEs_t, ie, x2HandoverCancel,
+                             X2AP_ProtocolIE_ID_id_New_eNB_UE_X2AP_ID, false);
+
+  if (ie == NULL ) {
+    X2AP_INFO("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    id_target = -1;
+  } else
+    id_target = ie->value.choice.UE_X2AP_ID_1;
+
+  X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverCancel_IEs_t, ie, x2HandoverCancel,
+                             X2AP_ProtocolIE_ID_id_Cause, true);
+
+  if (ie == NULL ) {
+    X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  }
+
+  if (ie->value.present != X2AP_HandoverCancel_IEs__value_PR_Cause ||
+      ie->value.choice.Cause.present != X2AP_Cause_PR_radioNetwork ||
+      !(ie->value.choice.Cause.choice.radioNetwork ==
+            X2AP_CauseRadioNetwork_trelocprep_expiry ||
+        ie->value.choice.Cause.choice.radioNetwork ==
+            X2AP_CauseRadioNetwork_tx2relocoverall_expiry)) {
+    X2AP_ERROR("%s %d: Cause not supported (only T_reloc_prep and TX2_reloc_overall handled)\n",__FILE__,__LINE__);
+    return -1;
+  }
+
+  switch (ie->value.choice.Cause.choice.radioNetwork) {
+  case X2AP_CauseRadioNetwork_trelocprep_expiry:
+    cause = X2AP_T_RELOC_PREP_TIMEOUT;
+    break;
+  case X2AP_CauseRadioNetwork_tx2relocoverall_expiry:
+    cause = X2AP_TX2_RELOC_OVERALL_TIMEOUT;
+    break;
+  default: /* can't come here */ exit(1);
+  }
+
+  ue_id = x2ap_find_id_from_id_source(&instance_p->id_manager, id_source);
+  if (ue_id == -1) {
+    X2AP_WARN("Handover cancel: UE not found (id_source = %d), ignoring message\n", id_source);
+    return 0;
+  }
+
+  if (id_target != -1 &&
+      id_target != x2ap_id_get_id_target(&instance_p->id_manager, ue_id)) {
+    X2AP_ERROR("Handover cancel: bad id_target for UE %x (id_source %d) expected %d got %d\n",
+               x2ap_id_get_rnti(&instance_p->id_manager, ue_id),
+               id_source,
+               x2ap_id_get_id_target(&instance_p->id_manager, ue_id),
+               id_target);
+    exit(1);
+  }
+
+  msg = itti_alloc_new_message(TASK_X2AP, X2AP_HANDOVER_CANCEL);
+
+  X2AP_HANDOVER_CANCEL(msg).rnti = x2ap_id_get_rnti(&instance_p->id_manager, ue_id);
+  X2AP_HANDOVER_CANCEL(msg).cause = cause;
+
+  itti_send_msg_to_task(TASK_RRC_ENB, instance_p->instance, msg);
+
+  x2ap_release_id(&instance_p->id_manager, ue_id);
+
+  return 0;
+}
diff --git a/openair2/X2AP/x2ap_ids.c b/openair2/X2AP/x2ap_ids.c
index b5607821fe5d97ef6c026000236c738740134963..02f1bbfc0e11171b3400317e34a2d5843a220885 100644
--- a/openair2/X2AP/x2ap_ids.c
+++ b/openair2/X2AP/x2ap_ids.c
@@ -60,6 +60,16 @@ int x2ap_find_id(x2ap_id_manager *m, int id_source, int id_target)
   return -1;
 }
 
+int x2ap_find_id_from_id_source(x2ap_id_manager *m, int id_source)
+{
+  int i;
+  for (i = 0; i < X2AP_MAX_IDS; i++)
+    if (m->ids[i].rnti != -1 &&
+        m->ids[i].id_source == id_source)
+      return i;
+  return -1;
+}
+
 int x2ap_find_id_from_rnti(x2ap_id_manager *m, int rnti)
 {
   int i;
@@ -76,6 +86,27 @@ void x2ap_set_ids(x2ap_id_manager *m, int ue_id, int rnti, int id_source, int id
   m->ids[ue_id].id_target = id_target;
 }
 
+/* real type of target is x2ap_eNB_data_t * */
+void x2ap_id_set_target(x2ap_id_manager *m, int ue_id, void *target)
+{
+  m->ids[ue_id].target = target;
+}
+
+void x2ap_id_set_state(x2ap_id_manager *m, int ue_id, x2id_state_t state)
+{
+  m->ids[ue_id].state = state;
+}
+
+void x2ap_set_reloc_prep_timer(x2ap_id_manager *m, int ue_id, uint64_t time)
+{
+  m->ids[ue_id].t_reloc_prep_start = time;
+}
+
+void x2ap_set_reloc_overall_timer(x2ap_id_manager *m, int ue_id, uint64_t time)
+{
+  m->ids[ue_id].tx2_reloc_overall_start = time;
+}
+
 int x2ap_id_get_id_source(x2ap_id_manager *m, int ue_id)
 {
   return m->ids[ue_id].id_source;
@@ -90,3 +121,8 @@ int x2ap_id_get_rnti(x2ap_id_manager *m, int ue_id)
 {
   return m->ids[ue_id].rnti;
 }
+
+void *x2ap_id_get_target(x2ap_id_manager *m, int ue_id)
+{
+  return m->ids[ue_id].target;
+}
diff --git a/openair2/X2AP/x2ap_ids.h b/openair2/X2AP/x2ap_ids.h
index 2232308f73dd944cd578e327467edcd017d67e6d..3d2799e8c46d3248a1fab193f35203510a9af9ff 100644
--- a/openair2/X2AP/x2ap_ids.h
+++ b/openair2/X2AP/x2ap_ids.h
@@ -22,12 +22,38 @@
 #ifndef X2AP_IDS_H_
 #define X2AP_IDS_H_
 
+#include <stdint.h>
+
+/* maximum number of simultaneous handovers, do not set too high */
 #define X2AP_MAX_IDS	16
 
+/*
+ * state:
+ * - when starting handover in source, UE is in state X2ID_STATE_SOURCE_PREPARE
+ * - after receiving HO_ack in source, UE is in state X2ID_STATE_SOURCE_OVERALL
+ * - in target, UE is in state X2ID_STATE_TARGET
+ * The state is used to check timers.
+ */
+typedef enum {
+  X2ID_STATE_SOURCE_PREPARE,
+  X2ID_STATE_SOURCE_OVERALL,
+  X2ID_STATE_TARGET
+} x2id_state_t;
+
 typedef struct {
-  int rnti;             /* -1 when free */
-  int id_source;
-  int id_target;
+  int           rnti;             /* -1 when free */
+  int           id_source;
+  int           id_target;
+
+  /* the target eNB. Real type is x2ap_eNB_data_t * */
+  void          *target;
+
+  /* state: needed to check timers */
+  x2id_state_t  state;
+
+  /* timers */
+  uint64_t      t_reloc_prep_start;
+  uint64_t      tx2_reloc_overall_start;
 } x2ap_id;
 
 typedef struct {
@@ -38,10 +64,17 @@ void x2ap_id_manager_init(x2ap_id_manager *m);
 int x2ap_allocate_new_id(x2ap_id_manager *m);
 void x2ap_release_id(x2ap_id_manager *m, int id);
 int x2ap_find_id(x2ap_id_manager *, int id_source, int id_target);
+int x2ap_find_id_from_id_source(x2ap_id_manager *, int id_source);
 int x2ap_find_id_from_rnti(x2ap_id_manager *, int rnti);
 void x2ap_set_ids(x2ap_id_manager *m, int ue_id, int rnti, int id_source, int id_target);
+void x2ap_id_set_state(x2ap_id_manager *m, int ue_id, x2id_state_t state);
+/* real type of target is x2ap_eNB_data_t * */
+void x2ap_id_set_target(x2ap_id_manager *m, int ue_id, void *target);
+void x2ap_set_reloc_prep_timer(x2ap_id_manager *m, int ue_id, uint64_t time);
+void x2ap_set_reloc_overall_timer(x2ap_id_manager *m, int ue_id, uint64_t time);
 int x2ap_id_get_id_source(x2ap_id_manager *m, int ue_id);
 int x2ap_id_get_id_target(x2ap_id_manager *m, int ue_id);
 int x2ap_id_get_rnti(x2ap_id_manager *m, int ue_id);
+void *x2ap_id_get_target(x2ap_id_manager *m, int ue_id);
 
 #endif /* X2AP_IDS_H_ */
diff --git a/openair2/X2AP/x2ap_timers.c b/openair2/X2AP/x2ap_timers.c
new file mode 100644
index 0000000000000000000000000000000000000000..a0a7b61ad7023259436f3e408dfd8da4591a22b3
--- /dev/null
+++ b/openair2/X2AP/x2ap_timers.c
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+#include "x2ap_timers.h"
+#include "assertions.h"
+#include "PHY/defs_common.h"         /* TODO: try to not include this */
+#include "x2ap_messages_types.h"
+#include "x2ap_eNB_defs.h"
+#include "x2ap_ids.h"
+#include "x2ap_eNB_management_procedures.h"
+#include "x2ap_eNB_generate_messages.h"
+
+void x2ap_timers_init(x2ap_timers_t *t, int t_reloc_prep, int tx2_reloc_overall)
+{
+  t->tti               = 0;
+  t->t_reloc_prep      = t_reloc_prep;
+  t->tx2_reloc_overall = tx2_reloc_overall;
+}
+
+void x2ap_check_timers(instance_t instance)
+{
+  x2ap_eNB_instance_t          *instance_p;
+  x2ap_timers_t                *t;
+  x2ap_id_manager              *m;
+  int                          i;
+  x2ap_handover_cancel_cause_t cause;
+  void                         *target;
+  MessageDef                   *msg;
+  int                          x2_ongoing;
+
+  instance_p = x2ap_eNB_get_instance(instance);
+  DevAssert(instance_p != NULL);
+
+  t = &instance_p->timers;
+  m = &instance_p->id_manager;
+
+  /* increment subframe count */
+  t->tti++;
+
+  x2_ongoing = 0;
+
+  for (i = 0; i < X2AP_MAX_IDS; i++) {
+    if (m->ids[i].rnti == -1) continue;
+    x2_ongoing++;
+
+    if (m->ids[i].state == X2ID_STATE_SOURCE_PREPARE &&
+        t->tti > m->ids[i].t_reloc_prep_start + t->t_reloc_prep) {
+      LOG_I(X2AP, "X2 timeout reloc prep\n");
+      /* t_reloc_prep timed out */
+      cause = X2AP_T_RELOC_PREP_TIMEOUT;
+      goto timeout;
+    }
+
+    if (m->ids[i].state == X2ID_STATE_SOURCE_OVERALL &&
+        t->tti > m->ids[i].tx2_reloc_overall_start + t->tx2_reloc_overall) {
+      LOG_I(X2AP, "X2 timeout reloc overall\n");
+      /* tx2_reloc_overall timed out */
+      cause = X2AP_TX2_RELOC_OVERALL_TIMEOUT;
+      goto timeout;
+    }
+
+    /* no timeout -> check next UE */
+    continue;
+
+timeout:
+    /* inform target about timeout */
+    target = x2ap_id_get_target(m, i);
+    x2ap_eNB_generate_x2_handover_cancel(instance_p, target, i, cause);
+
+    /* inform RRC of cancellation */
+    msg = itti_alloc_new_message(TASK_X2AP, X2AP_HANDOVER_CANCEL);
+    X2AP_HANDOVER_CANCEL(msg).rnti  = x2ap_id_get_rnti(m, i);
+    X2AP_HANDOVER_CANCEL(msg).cause = cause;
+    itti_send_msg_to_task(TASK_RRC_ENB, instance_p->instance, msg);
+
+    /* remove UE from X2AP */
+    x2ap_release_id(m, i);
+  }
+
+  if (x2_ongoing && t->tti % 1000 == 0)
+    LOG_I(X2AP, "X2 has %d process ongoing\n", x2_ongoing);
+}
+
+uint64_t x2ap_timer_get_tti(x2ap_timers_t *t)
+{
+  return t->tti;
+}
diff --git a/openair2/X2AP/x2ap_timers.h b/openair2/X2AP/x2ap_timers.h
new file mode 100644
index 0000000000000000000000000000000000000000..d4579422d599cd685e44372da8b47bf15ddec296
--- /dev/null
+++ b/openair2/X2AP/x2ap_timers.h
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+#ifndef X2AP_TIMERS_H_
+#define X2AP_TIMERS_H_
+
+#include <stdint.h>
+#include "platform_types.h"
+
+typedef struct {
+  /* incremented every TTI (every millisecond when in realtime).
+   * Used to check timers.
+   * 64 bits gives us more than 500 million years of (realtime) processing.
+   * It should be enough.
+   */
+  uint64_t tti;
+
+  /* timer values (unit: TTI, ie. millisecond when in realtime) */
+  int      t_reloc_prep;
+  int      tx2_reloc_overall;
+} x2ap_timers_t;
+
+void x2ap_timers_init(x2ap_timers_t *t, int t_reloc_prep, int tx2_reloc_overall);
+void x2ap_check_timers(instance_t instance);
+uint64_t x2ap_timer_get_tti(x2ap_timers_t *t);
+
+#endif /* X2AP_TIMERS_H_ */
diff --git a/targets/COMMON/create_tasks.c b/targets/COMMON/create_tasks.c
index 4fc2551e15ec4eb5ef6d84d29c9bd88d8c7f5f17..d2dd90b2b4c86e596045a1104570eb44e19847e8 100644
--- a/targets/COMMON/create_tasks.c
+++ b/targets/COMMON/create_tasks.c
@@ -53,10 +53,13 @@ int create_tasks(uint32_t enb_nb) {
 
   if (EPC_MODE_ENABLED) {
     if (enb_nb > 0) {
-      if (itti_create_task (TASK_X2AP, x2ap_task, NULL) < 0) {
-        LOG_E(X2AP, "Create task for X2AP failed\n");
-        return -1;
-      }
+      if (is_x2ap_enabled()) {
+        if (itti_create_task (TASK_X2AP, x2ap_task, NULL) < 0) {
+          LOG_E(X2AP, "Create task for X2AP failed\n");
+          return -1;
+        }
+      } else
+        LOG_I(X2AP, "X2AP is disabled.\n");
 
       if (itti_create_task (TASK_SCTP, sctp_eNB_task, NULL) < 0) {
         LOG_E(SCTP, "Create task for SCTP failed\n");
diff --git a/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.calisson.conf b/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.calisson.conf
index 86131b3e8e97e0b98fadfe7d6617a37f67a9e569..df60ee7fa8d6a9de6a627e4c42c9ca7b6dbd624d 100644
--- a/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.calisson.conf
+++ b/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.calisson.conf
@@ -37,6 +37,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES : 
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.memphis.conf b/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.memphis.conf
index e87a37f9fb8cc5a3fd9e523307f0e18fc17a6bd6..f5dce0a178e72d21bb07356666b9e27d4806ead9 100644
--- a/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.memphis.conf
+++ b/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.memphis.conf
@@ -49,6 +49,11 @@ eNBs =
                             }
 			    );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES : 
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.nord.conf b/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.nord.conf
index af4f4236a7b2059f04193edd9d9be5eb56ff6eeb..d75837ff9793cc79d1aa9b0f6923818b954409a1 100644
--- a/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.nord.conf
+++ b/targets/PROJECTS/CENTOS-LTE-EPC-INTEGRATION/CONF/enb.centos.nord.conf
@@ -36,6 +36,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES : 
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth1";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band13.tm1.50PRB.emtc.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band13.tm1.50PRB.emtc.conf
index a69daff48e017b31dddbd1821381c49b45b2a7d8..ca09ea6625e7b34ef73229cfe5506b1d883849b8 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band13.tm1.50PRB.emtc.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band13.tm1.50PRB.emtc.conf
@@ -48,9 +48,9 @@ eNBs =
       prach_zero_correlation                    = 1;
       prach_freq_offset                         = 1;
       pucch_delta_shift                         = 1;
-      pucch_nRB_CQI                             = 1;
+      pucch_nRB_CQI                             = 0;
       pucch_nCS_AN                              = 0;    
-      pucch_n1_AN                               = 32;
+      pucch_n1_AN                               = 0;
       pdsch_referenceSignalPower                = -27;
       pdsch_p_b                                 = 0;
       pusch_n_SB                                = 1;
@@ -262,7 +262,7 @@ eNBs =
           n1PUCCH_AN_InfoList_r13 = 
           (
               {
-                  pucch_info_value = 0;
+                  pucch_info_value = 33;
               }
           );
           
@@ -360,6 +360,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
 
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.100PRB.usrpx310.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.100PRB.usrpx310.conf
index 8c080b7d1059c6cc4bfd03808b24f3fba1779bef..60142d8fe64cfa363c141bb8b71943c1269e4c4e 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.100PRB.usrpx310.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.100PRB.usrpx310.conf
@@ -142,6 +142,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.25PRB.iris030.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.25PRB.iris030.conf
index 77993457ab9b452bfa5ba7a390791cea6010375f..372c853b29cdd16bec3ebdaca7fe7ec2260fd60f 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.25PRB.iris030.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.25PRB.iris030.conf
@@ -178,6 +178,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eno1";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.usrpx310.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.usrpx310.conf
index 83954a00d52c3e2522371336db87fb6b574ff051..993acae34e95b894877aa7f88923d398b2d6a2c4 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.usrpx310.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band38.tm1.usrpx310.conf
@@ -142,6 +142,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band42.tm1.25PRB.iris030.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band42.tm1.25PRB.iris030.conf
index 764d7886e2a62a37b34c7e31dcb59384fa9b41b5..c55c58e1a727104818c5427fed69e4f4098aa32f 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band42.tm1.25PRB.iris030.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band42.tm1.25PRB.iris030.conf
@@ -178,6 +178,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eno1";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf
index 728492ee835aaf2607ea6aefd09eb5a7be2cc880..ac417c7e3a81cd7a7b11548d5d4c5b84d4c8fc82 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf
@@ -145,6 +145,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth6";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.iris030.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.iris030.conf
index ca85c6538f221587faad1657be2b207468047ff6..5882c1b168015206e3a6d606500a27088c2fb3c9 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.iris030.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.iris030.conf
@@ -178,6 +178,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.usrpb210.replay.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.usrpb210.replay.conf
index 823c5fb1c3e7ec1c9e04fd42fe3cee6af3afac72..a683326639c9b7fc92c1431c4b679aa1437e9073 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.usrpb210.replay.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.25PRB.usrpb210.replay.conf
@@ -179,6 +179,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210-d2d.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210-d2d.conf
index 476d4903f1c5b04e16b3caa927c68ed2e057fc76..5e750cb62652f2946d0c83116a897b91a5bd8f75 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210-d2d.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210-d2d.conf
@@ -179,6 +179,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210.conf
index 83834bfeca6d51a6c8866d95d31d3ef680eed9aa..142b9625983197d6aee2e0a55d43935910382a6e 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210.conf
@@ -179,6 +179,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210_ue_expansion.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210_ue_expansion.conf
index 403e5f24f54cb114dfd9e971f5d2a9541c7625e7..497db9a306bab96faad656f7139cc904aff33243 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210_ue_expansion.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.50PRB.usrpb210_ue_expansion.conf
@@ -146,6 +146,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band38.tm1.if4p5.50PRB.lo.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band38.tm1.if4p5.50PRB.lo.conf
index 7eb16a3b7a9f0f0da3fdd706c254211c6cf53d01..ae2ba73782d6161d6576cbae55545986d087aa3b 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band38.tm1.if4p5.50PRB.lo.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band38.tm1.if4p5.50PRB.lo.conf
@@ -148,6 +148,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi-STUB.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi-STUB.conf
index 47047e5626cbf9e170515b920507b665030dfe25..f7be9e28d95f8a94535bd21cf38f3b7677f85744 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi-STUB.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi-STUB.conf
@@ -148,6 +148,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "vboxnet0";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf
index 472d84c7e2319d84d3436081f91839cd44b72160..9d71b10740cc3ba7e036835735c3b058a29a106c 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.50PRB.nfapi.conf
@@ -179,6 +179,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         #ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.conf
index d989ac8b1087ec181e1da88ffca01aee0130ed7f..ec20ac3abff08d69e88d8f35657c865867b85a8b 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.conf
@@ -148,6 +148,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "eth0";
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf
index 79bd48cd0c5dac9287810cdf377c8322aec000ca..5e5b191a0f206a7b9b310c4cc1fb90727871e33d 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf
@@ -147,6 +147,11 @@ eNBs =
                             }
                           );
 
+    ///X2
+    enable_x2 = "no";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+
     NETWORK_INTERFACES :
     {
         ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";